@@ -4543,6 +4543,113 @@ public function testNonStrictModeWithReplaceStatement(): void {
4543
4543
$ this ->assertSame ( 'blue ' , $ result [0 ]->color );
4544
4544
}
4545
4545
4546
+ public function testNonStrictModeTypeCasting (): void {
4547
+ $ this ->assertQuery (
4548
+ "CREATE TABLE t (
4549
+ col_int INT,
4550
+ col_float FLOAT,
4551
+ col_double DOUBLE,
4552
+ col_decimal DECIMAL,
4553
+ col_char CHAR(255),
4554
+ col_varchar VARCHAR(255),
4555
+ col_text TEXT,
4556
+ col_bool BOOL,
4557
+ col_bit BIT,
4558
+ col_binary BINARY(255),
4559
+ col_varbinary VARBINARY(255),
4560
+ col_blob BLOB,
4561
+ col_date DATE,
4562
+ col_time TIME,
4563
+ col_datetime DATETIME,
4564
+ col_timestamp TIMESTAMP,
4565
+ col_year YEAR,
4566
+ col_enum ENUM('a', 'b', 'c'),
4567
+ col_set SET('a', 'b', 'c'),
4568
+ col_json JSON
4569
+ ) "
4570
+ );
4571
+
4572
+ // Set non-strict mode.
4573
+ $ this ->assertQuery ( "SET SESSION sql_mode = '' " );
4574
+
4575
+ // INSERT.
4576
+ $ this ->assertQuery (
4577
+ "INSERT INTO t VALUES ('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '') "
4578
+ );
4579
+
4580
+ $ result = $ this ->assertQuery ( 'SELECT * FROM t ' );
4581
+ $ this ->assertCount ( 1 , $ result );
4582
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_int );
4583
+ $ this ->assertSame ( PHP_VERSION_ID < 80100 ? '0.0 ' : '0 ' , $ result [0 ]->col_float );
4584
+ $ this ->assertSame ( PHP_VERSION_ID < 80100 ? '0.0 ' : '0 ' , $ result [0 ]->col_double );
4585
+ $ this ->assertSame ( PHP_VERSION_ID < 80100 ? '0.0 ' : '0 ' , $ result [0 ]->col_decimal );
4586
+ $ this ->assertSame ( '' , $ result [0 ]->col_char );
4587
+ $ this ->assertSame ( '' , $ result [0 ]->col_varchar );
4588
+ $ this ->assertSame ( '' , $ result [0 ]->col_text );
4589
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_bool );
4590
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_bit );
4591
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_binary ); // TODO: Should save ''.
4592
+ $ this ->assertSame ( '' , $ result [0 ]->col_varbinary );
4593
+ $ this ->assertSame ( '' , $ result [0 ]->col_blob );
4594
+ $ this ->assertSame ( '0000-00-00 ' , $ result [0 ]->col_date );
4595
+ $ this ->assertSame ( '00:00:00 ' , $ result [0 ]->col_time );
4596
+ $ this ->assertSame ( '0000-00-00 00:00:00 ' , $ result [0 ]->col_datetime );
4597
+ $ this ->assertSame ( '0000-00-00 00:00:00 ' , $ result [0 ]->col_timestamp );
4598
+ $ this ->assertSame ( '0000 ' , $ result [0 ]->col_year );
4599
+ $ this ->assertSame ( '' , $ result [0 ]->col_enum );
4600
+ $ this ->assertSame ( '' , $ result [0 ]->col_set );
4601
+ $ this ->assertSame ( '' , $ result [0 ]->col_json ); // TODO: This should not be allowed.
4602
+
4603
+ // UPDATE.
4604
+ $ this ->assertQuery (
4605
+ "UPDATE t SET
4606
+ col_int = '',
4607
+ col_float = '',
4608
+ col_double = '',
4609
+ col_decimal = '',
4610
+ col_char = '',
4611
+ col_varchar = '',
4612
+ col_text = '',
4613
+ col_bool = '',
4614
+ col_bit = '',
4615
+ col_binary = '',
4616
+ col_varbinary = '',
4617
+ col_blob = '',
4618
+ col_date = '',
4619
+ col_time = '',
4620
+ col_datetime = '',
4621
+ col_timestamp = '',
4622
+ col_year = '',
4623
+ col_enum = '',
4624
+ col_set = '',
4625
+ col_json = ''
4626
+ "
4627
+ );
4628
+
4629
+ $ result = $ this ->assertQuery ( 'SELECT * FROM t ' );
4630
+ $ this ->assertCount ( 1 , $ result );
4631
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_int );
4632
+ $ this ->assertSame ( PHP_VERSION_ID < 80100 ? '0.0 ' : '0 ' , $ result [0 ]->col_float );
4633
+ $ this ->assertSame ( PHP_VERSION_ID < 80100 ? '0.0 ' : '0 ' , $ result [0 ]->col_double );
4634
+ $ this ->assertSame ( PHP_VERSION_ID < 80100 ? '0.0 ' : '0 ' , $ result [0 ]->col_decimal );
4635
+ $ this ->assertSame ( '' , $ result [0 ]->col_char );
4636
+ $ this ->assertSame ( '' , $ result [0 ]->col_varchar );
4637
+ $ this ->assertSame ( '' , $ result [0 ]->col_text );
4638
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_bool );
4639
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_bit );
4640
+ $ this ->assertSame ( '0 ' , $ result [0 ]->col_binary ); // TODO: Should save ''.
4641
+ $ this ->assertSame ( '' , $ result [0 ]->col_varbinary );
4642
+ $ this ->assertSame ( '' , $ result [0 ]->col_blob );
4643
+ $ this ->assertSame ( '0000-00-00 ' , $ result [0 ]->col_date );
4644
+ $ this ->assertSame ( '00:00:00 ' , $ result [0 ]->col_time );
4645
+ $ this ->assertSame ( '0000-00-00 00:00:00 ' , $ result [0 ]->col_datetime );
4646
+ $ this ->assertSame ( '0000-00-00 00:00:00 ' , $ result [0 ]->col_timestamp );
4647
+ $ this ->assertSame ( '0000 ' , $ result [0 ]->col_year );
4648
+ $ this ->assertSame ( '' , $ result [0 ]->col_enum );
4649
+ $ this ->assertSame ( '' , $ result [0 ]->col_set );
4650
+ $ this ->assertSame ( '' , $ result [0 ]->col_json ); // TODO: This should not be allowed.
4651
+ }
4652
+
4546
4653
public function testSessionSqlModes (): void {
4547
4654
// Syntax: "sql_mode" ("@@sql_mode" for SELECT)
4548
4655
$ this ->assertQuery ( 'SET sql_mode = "ERROR_FOR_DIVISION_BY_ZERO" ' );
0 commit comments