@@ -4298,6 +4298,137 @@ public function testNonStrictSqlModeNotNullWithDefault(): void {
42984298 $ this ->assertSame ( '' , $ result [0 ]->value );
42994299 }
43004300
4301+ public function testNonStrictSqlModeWithNoListedColumns (): void {
4302+ $ this ->assertQuery ( "SET SESSION sql_mode = '' " );
4303+
4304+ // From VALUES() statement:
4305+ $ this ->assertQuery ( 'CREATE TABLE t1 (id INT, name TEXT NOT NULL, size INT DEFAULT 123, color TEXT) ' );
4306+ $ this ->assertQuery ( "INSERT INTO t1 VALUES (1, 'A', 10, 'red') " );
4307+ $ this ->assertQuery ( "INSERT INTO t1 VALUES (2, 'B', NULL, NULL) " );
4308+ $ result = $ this ->assertQuery ( 'SELECT * FROM t1 ' );
4309+ $ this ->assertCount ( 2 , $ result );
4310+ $ this ->assertSame ( '1 ' , $ result [0 ]->id );
4311+ $ this ->assertSame ( 'A ' , $ result [0 ]->name );
4312+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4313+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4314+ $ this ->assertSame ( '2 ' , $ result [1 ]->id );
4315+ $ this ->assertSame ( 'B ' , $ result [1 ]->name );
4316+ $ this ->assertNull ( $ result [1 ]->size );
4317+ $ this ->assertNull ( $ result [1 ]->color );
4318+
4319+ // From SELECT statement:
4320+ $ this ->assertQuery ( 'CREATE TABLE t2 (id INT, name TEXT NOT NULL, size INT DEFAULT 999, color TEXT) ' );
4321+ $ this ->assertQuery ( 'INSERT INTO t2 SELECT * FROM t1 ' );
4322+ $ result = $ this ->assertQuery ( 'SELECT * FROM t2 ' );
4323+ $ this ->assertCount ( 2 , $ result );
4324+ $ this ->assertSame ( '1 ' , $ result [0 ]->id );
4325+ $ this ->assertSame ( 'A ' , $ result [0 ]->name );
4326+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4327+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4328+ $ this ->assertSame ( '2 ' , $ result [1 ]->id );
4329+ $ this ->assertSame ( 'B ' , $ result [1 ]->name );
4330+ $ this ->assertNull ( $ result [1 ]->size );
4331+ $ this ->assertNull ( $ result [1 ]->color );
4332+ }
4333+
4334+ public function testNonStrictSqlModeWithReorderedColumns (): void {
4335+ $ this ->assertQuery ( "SET SESSION sql_mode = '' " );
4336+
4337+ // From VALUES() statement:
4338+ $ this ->assertQuery ( 'CREATE TABLE t1 (id INT, name TEXT NOT NULL, size INT DEFAULT 123, color TEXT) ' );
4339+ $ this ->assertQuery ( "INSERT INTO t1 (name, color, id, size) VALUES ('A', 'red', 1, 10) " );
4340+ $ this ->assertQuery ( "INSERT INTO t1 (name, id) VALUES ('B', 2) " );
4341+ $ result = $ this ->assertQuery ( 'SELECT * FROM t1 ' );
4342+ $ this ->assertCount ( 2 , $ result );
4343+ $ this ->assertSame ( '1 ' , $ result [0 ]->id );
4344+ $ this ->assertSame ( 'A ' , $ result [0 ]->name );
4345+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4346+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4347+ $ this ->assertSame ( '2 ' , $ result [1 ]->id );
4348+ $ this ->assertSame ( 'B ' , $ result [1 ]->name );
4349+ $ this ->assertSame ( '123 ' , $ result [1 ]->size );
4350+ $ this ->assertNull ( $ result [1 ]->color );
4351+
4352+ // From SELECT statement:
4353+ $ this ->assertQuery ( 'CREATE TABLE t2 (id INT, name TEXT NOT NULL, size INT DEFAULT 999, color TEXT) ' );
4354+ $ this ->assertQuery ( 'INSERT INTO t2 (name, color, id, size) SELECT name, color, id, size FROM t1 ' );
4355+ $ result = $ this ->assertQuery ( 'SELECT * FROM t2 ' );
4356+ $ this ->assertCount ( 2 , $ result );
4357+ $ this ->assertSame ( '1 ' , $ result [0 ]->id );
4358+ $ this ->assertSame ( 'A ' , $ result [0 ]->name );
4359+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4360+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4361+ $ this ->assertSame ( '2 ' , $ result [1 ]->id );
4362+ $ this ->assertSame ( 'B ' , $ result [1 ]->name );
4363+ $ this ->assertSame ( '123 ' , $ result [1 ]->size );
4364+ $ this ->assertNull ( $ result [1 ]->color );
4365+ }
4366+
4367+ public function testNonStrictModeWithTemporaryTable (): void {
4368+ $ this ->assertQuery ( "SET SESSION sql_mode = '' " );
4369+
4370+ // Create a non-temporary table with the same name, but different columns.
4371+ // This should not be touched at all as temporary tables are prioritized.
4372+ $ this ->assertQuery ( 'CREATE TABLE t1 (value TEXT) ' );
4373+
4374+ // From VALUES() statement:
4375+ $ this ->assertQuery ( 'CREATE TEMPORARY TABLE t1 (id INT, name TEXT NOT NULL, size INT DEFAULT 123, color TEXT) ' );
4376+ $ this ->assertQuery ( "INSERT INTO t1 VALUES (1, 'A', 10, 'red') " );
4377+ $ this ->assertQuery ( "INSERT INTO t1 (name, color, id, size) VALUES ('B', 'blue', 2, 20) " );
4378+ $ this ->assertQuery ( "INSERT INTO t1 (name, id) VALUES ('C', 3) " );
4379+ $ result = $ this ->assertQuery ( 'SELECT * FROM t1 ' );
4380+ $ this ->assertCount ( 3 , $ result );
4381+ $ this ->assertSame ( '1 ' , $ result [0 ]->id );
4382+ $ this ->assertSame ( 'A ' , $ result [0 ]->name );
4383+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4384+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4385+ $ this ->assertSame ( '2 ' , $ result [1 ]->id );
4386+ $ this ->assertSame ( 'B ' , $ result [1 ]->name );
4387+ $ this ->assertSame ( '20 ' , $ result [1 ]->size );
4388+ $ this ->assertSame ( 'blue ' , $ result [1 ]->color );
4389+ $ this ->assertSame ( '3 ' , $ result [2 ]->id );
4390+ $ this ->assertSame ( 'C ' , $ result [2 ]->name );
4391+ $ this ->assertSame ( '123 ' , $ result [2 ]->size );
4392+ $ this ->assertNull ( $ result [2 ]->color );
4393+
4394+ // From SELECT statement:
4395+ $ this ->assertQuery ( 'CREATE TEMPORARY TABLE t2 (id INT, name TEXT NOT NULL, size INT DEFAULT 999, color TEXT) ' );
4396+ $ this ->assertQuery ( 'INSERT INTO t2 (name, color, id, size) SELECT name, color, id, size FROM t1 ' );
4397+ $ result = $ this ->assertQuery ( 'SELECT * FROM t2 ' );
4398+ $ this ->assertCount ( 3 , $ result );
4399+ $ this ->assertSame ( '1 ' , $ result [0 ]->id );
4400+ $ this ->assertSame ( 'A ' , $ result [0 ]->name );
4401+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4402+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4403+ $ this ->assertSame ( '2 ' , $ result [1 ]->id );
4404+ $ this ->assertSame ( 'B ' , $ result [1 ]->name );
4405+ $ this ->assertSame ( '20 ' , $ result [1 ]->size );
4406+ $ this ->assertSame ( 'blue ' , $ result [1 ]->color );
4407+ $ this ->assertSame ( '3 ' , $ result [2 ]->id );
4408+ $ this ->assertSame ( 'C ' , $ result [2 ]->name );
4409+ $ this ->assertSame ( '123 ' , $ result [2 ]->size );
4410+ $ this ->assertNull ( $ result [2 ]->color );
4411+ }
4412+
4413+ public function testNonStrictModeWithOnDuplicateKeyUpdate (): void {
4414+ $ this ->assertQuery ( "SET SESSION sql_mode = '' " );
4415+
4416+ $ this ->assertQuery ( 'CREATE TABLE t1 (id INT PRIMARY KEY, name TEXT NOT NULL, size INT DEFAULT 123, color TEXT) ' );
4417+ $ this ->assertQuery ( "INSERT INTO t1 VALUES (1, 'A', 10, 'red') " );
4418+ $ result = $ this ->assertQuery ( 'SELECT * FROM t1 ' );
4419+ $ this ->assertCount ( 1 , $ result );
4420+ $ this ->assertSame ( 'A ' , $ result [0 ]->name );
4421+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4422+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4423+
4424+ $ this ->assertQuery ( "INSERT INTO t1 VALUES (1, 'B', 20, 'blue') ON DUPLICATE KEY UPDATE name = 'B' " );
4425+ $ result = $ this ->assertQuery ( 'SELECT * FROM t1 ' );
4426+ $ this ->assertCount ( 1 , $ result );
4427+ $ this ->assertSame ( 'B ' , $ result [0 ]->name );
4428+ $ this ->assertSame ( '10 ' , $ result [0 ]->size );
4429+ $ this ->assertSame ( 'red ' , $ result [0 ]->color );
4430+ }
4431+
43014432 public function testSessionSqlModes (): void {
43024433 // Syntax: "sql_mode" ("@@sql_mode" for SELECT)
43034434 $ this ->assertQuery ( 'SET sql_mode = "ERROR_FOR_DIVISION_BY_ZERO" ' );
0 commit comments