You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix INSERT ... SELECT ... edge case in non-strict mode (#285)
In MySQL non-STRICT mode, when inserting from a `SELECT` query:
When a column is declared as `NOT NULL`, inserting a `NULL` value saves
an IMPLICIT DEFAULT value instead. This behavior only applies to the
`INSERT ... SELECT` syntax (not `VALUES` or `SET`).
In other words:
```sql
CREATE TABLE t (value INT NOT NULL);
-- Strict mode:
INSERT INTO t VALUES (NULL); -- error
INSERT INTO t SET value = NULL; -- error
INSERT INTO t SELECT NULL; -- error
INSERT INTO t VALUES ((SELECT NULL)); -- error
-- Non-strict mode:
INSERT INTO t VALUES (NULL); -- error
INSERT INTO t SET value = NULL; -- error
INSERT INTO t SELECT NULL; -- OK, saves 0 (the implicit default for integer)
INSERT INTO t VALUES ((SELECT NULL)); -- error
```
This fixes some failures in the activation of the top 100 plugins.
$this->assertQuery( 'CREATE TABLE t (value INT NOT NULL)' );
10544
+
10545
+
// Strict mode:
10546
+
$this->assertQueryError( 'INSERT INTO t VALUES (NULL)', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
10547
+
$this->assertQueryError( 'INSERT INTO t SET value = NULL', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
10548
+
$this->assertQueryError( 'INSERT INTO t SELECT NULL', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
10549
+
$this->assertQueryError( 'INSERT INTO t VALUES ((SELECT NULL))', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
$this->assertQueryError( 'INSERT INTO t VALUES (NULL)', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
10554
+
$this->assertQueryError( 'INSERT INTO t SET value = NULL', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
10555
+
$this->assertQuery( 'INSERT INTO t SELECT NULL' );
10556
+
$this->assertSame( '0', $this->assertQuery( 'SELECT * FROM t' )[0]->value );
10557
+
$this->assertQueryError( 'INSERT INTO t VALUES ((SELECT NULL))', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
$this->assertQuery( 'CREATE TABLE t (value INT NOT NULL)' );
10562
+
$this->assertQuery( 'INSERT INTO t VALUES (1)' );
10563
+
10564
+
// Strict mode:
10565
+
$this->assertQueryError( 'UPDATE t SET value = NULL', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
10566
+
$this->assertQueryError( 'UPDATE t SET value = (SELECT NULL)', 'SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: t.value' );
0 commit comments