Skip to content

Commit e18caaf

Browse files
committed
test: FLOAT on MySQL cannot be used as WHERE = key
See https://dev.mysql.com/doc/refman/8.0/en/floating-point-types.html
1 parent b008b0d commit e18caaf

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

tests/_support/Database/Migrations/20160428212500_Create_test_tables.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,22 @@ public function up(): void
4747

4848
// Database Type test table
4949
// missing types:
50-
// TINYINT,MEDIUMINT,BIT,YEAR,BINARY,VARBINARY,TINYTEXT,LONGTEXT,
51-
// JSON,Spatial data types
50+
// TINYINT,MEDIUMINT,BIT,YEAR,BINARY,VARBINARY,TINYTEXT,LONGTEXT,
51+
// JSON,Spatial data types
5252
// `id` must be INTEGER else SQLite3 error on not null for autoincrement field.
5353
$data_type_fields = [
54-
'id' => ['type' => 'INTEGER', 'constraint' => 20, 'auto_increment' => true],
55-
'type_varchar' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
56-
'type_char' => ['type' => 'CHAR', 'constraint' => 10, 'null' => true],
57-
'type_text' => ['type' => 'TEXT', 'null' => true],
58-
'type_smallint' => ['type' => 'SMALLINT', 'null' => true],
59-
'type_integer' => ['type' => 'INTEGER', 'null' => true],
54+
'id' => ['type' => 'INTEGER', 'constraint' => 20, 'auto_increment' => true],
55+
'type_varchar' => ['type' => 'VARCHAR', 'constraint' => 40, 'null' => true],
56+
'type_char' => ['type' => 'CHAR', 'constraint' => 10, 'null' => true],
57+
// TEXT should not be used on SQLSRV. It is deprecated.
58+
'type_text' => ['type' => 'TEXT', 'null' => true],
59+
'type_smallint' => ['type' => 'SMALLINT', 'null' => true],
60+
'type_integer' => ['type' => 'INTEGER', 'null' => true],
61+
// FLOAT should not be used on MySQL.
62+
// CREATE TABLE t (f FLOAT, d DOUBLE);
63+
// INSERT INTO t VALUES(99.9, 99.9);
64+
// SELECT * FROM t WHERE f=99.9; // Empty set
65+
// SELECT * FROM t WHERE d=99.9; // 1 row
6066
'type_float' => ['type' => 'FLOAT', 'null' => true],
6167
'type_numeric' => ['type' => 'NUMERIC', 'constraint' => '18,2', 'null' => true],
6268
'type_date' => ['type' => 'DATE', 'null' => true],

tests/system/Database/Live/UpdateTest.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static function provideUpdateBatch(): iterable
163163
'type_smallint' => 9999,
164164
'type_integer' => 9_999_999,
165165
'type_bigint' => 9_999_999,
166-
'type_float' => 999999.9,
166+
'type_float' => 99.9,
167167
'type_numeric' => 999999.99,
168168
'type_date' => '2024-01-01',
169169
'type_datetime' => '2024-01-01 09:00:00',
@@ -174,7 +174,7 @@ public static function provideUpdateBatch(): iterable
174174
'type_smallint' => 9999,
175175
'type_integer' => 9_999_999,
176176
'type_bigint' => 9_999_999,
177-
'type_float' => 999999.9,
177+
'type_float' => 99.9,
178178
'type_numeric' => 999999.99,
179179
'type_date' => '2024-01-01',
180180
'type_datetime' => '2024-01-01 09:00:00',
@@ -187,7 +187,6 @@ public static function provideUpdateBatch(): iterable
187187
'type_smallint' => 9999,
188188
'type_integer' => 9_999_999,
189189
'type_bigint' => 9_999_999,
190-
'type_float' => 999999.9,
191190
'type_numeric' => 999999.99,
192191
'type_date' => '2024-01-01',
193192
'type_datetime' => '2024-01-01 09:00:00',
@@ -198,7 +197,6 @@ public static function provideUpdateBatch(): iterable
198197
'type_smallint' => 9999,
199198
'type_integer' => 9_999_999,
200199
'type_bigint' => 9_999_999,
201-
'type_float' => 999999.9,
202200
'type_numeric' => 999999.99,
203201
'type_date' => '2024-01-01',
204202
'type_datetime' => '2024-01-01 09:00:00',

0 commit comments

Comments
 (0)