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
{{ message }}
Repository navigation
Commit d2262de
Browse filesBrowse the repository at this point in the historyBrowse files
MySQL stores a numeric zero default of a temporal column, such as
DEFAULT 0 on a TIMESTAMP column, as its zero value, e.g.
'0000-00-00 00:00:00'. The driver stored it verbatim, so SHOW CREATE
TABLE emitted DEFAULT '0', which MySQL rejects in strict SQL mode.
Normalize these defaults when recording column definitions, and repair
defaults stored by older driver versions when the database is
configured.
"SELECT column_name, column_default FROM information_schema.columns WHERE table_name = '_tmp_table' AND column_name IN ('col_timestamp', 'col_date', 'col_time_fsp') ORDER BY ordinal_position"
6382
+
);
6383
+
$this->assertEquals(
6384
+
array(
6385
+
(object) array(
6386
+
'COLUMN_NAME' => 'col_timestamp',
6387
+
'COLUMN_DEFAULT' => '0000-00-00 00:00:00',
6388
+
),
6389
+
(object) array(
6390
+
'COLUMN_NAME' => 'col_date',
6391
+
'COLUMN_DEFAULT' => '0000-00-00',
6392
+
),
6393
+
(object) array(
6394
+
'COLUMN_NAME' => 'col_time_fsp',
6395
+
'COLUMN_DEFAULT' => '00:00:00.00',
6396
+
),
6397
+
),
6398
+
$this->last_result
6399
+
);
6400
+
}
6401
+
6402
+
public function testInsertUsesTemporalZeroDefaults(): void {
6403
+
$this->assertQuery(
6404
+
'CREATE TABLE _tmp_table (
6405
+
id INT NOT NULL,
6406
+
created_at TIMESTAMP NOT NULL DEFAULT 0,
6407
+
updated_on DATE NOT NULL DEFAULT 0
6408
+
)'
6409
+
);
6410
+
$this->assertQuery( 'INSERT INTO _tmp_table (id) VALUES (1)' );
6411
+
$this->assertQuery( 'SELECT created_at, updated_on FROM _tmp_table' );
6412
+
$this->assertEquals(
6413
+
array(
6414
+
(object) array(
6415
+
'created_at' => '0000-00-00 00:00:00',
6416
+
'updated_on' => '0000-00-00',
6417
+
),
6418
+
),
6419
+
$this->last_result
6420
+
);
6421
+
}
6422
+
6423
+
public function testAlterTableWithTemporalZeroDefaults(): void {
6424
+
$this->assertQuery( 'CREATE TABLE _tmp_table (id INT NOT NULL, modified_at DATETIME NOT NULL)' );
public function testConfigurationNormalizesStoredTemporalZeroDefaults(): void {
6445
+
$this->assertQuery( 'CREATE TABLE _tmp_table (id INT NOT NULL DEFAULT 0, created_at TIMESTAMP NOT NULL DEFAULT 0, label VARCHAR(20) NOT NULL DEFAULT 0)' );
6446
+
6447
+
// Simulate a database configured by an older driver version that
6448
+
// stored numeric zero temporal defaults verbatim.
6449
+
$this->sqlite->exec( "UPDATE _wp_sqlite_mysql_information_schema_columns SET column_default = '0' WHERE table_name = '_tmp_table'" );
6450
+
$this->sqlite->exec( "UPDATE _wp_sqlite_global_variables SET value = '0.0.0' WHERE name = '_wp_sqlite_driver_version'" );
0 commit comments