mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-02-07 12:36:25 +00:00
Fixing Sqlite's handling of datetime/timestamp columns with current_timestamp default set
This commit is contained in:
parent
326583153a
commit
2227e01990
2 changed files with 37 additions and 0 deletions
|
@ -185,6 +185,9 @@ class Sqlite extends DboSource {
|
||||||
'default' => $default,
|
'default' => $default,
|
||||||
'length' => $this->length($column['type'])
|
'length' => $this->length($column['type'])
|
||||||
);
|
);
|
||||||
|
if (in_array($fields[$column['name']]['type'], array('timestamp', 'datetime')) && strtoupper($fields[$column['name']]['default']) === 'CURRENT_TIMESTAMP') {
|
||||||
|
$fields[$column['name']]['default'] = null;
|
||||||
|
}
|
||||||
if ($column['pk'] == 1) {
|
if ($column['pk'] == 1) {
|
||||||
$fields[$column['name']]['key'] = $this->index['PRI'];
|
$fields[$column['name']]['key'] = $this->index['PRI'];
|
||||||
$fields[$column['name']]['null'] = false;
|
$fields[$column['name']]['null'] = false;
|
||||||
|
|
|
@ -422,6 +422,40 @@ class SqliteTest extends CakeTestCase {
|
||||||
$this->Dbo->query('DROP TABLE ' . $tableName);
|
$this->Dbo->query('DROP TABLE ' . $tableName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that describe ignores `default current_timestamp` in timestamp columns.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDescribeHandleCurrentTimestamp() {
|
||||||
|
$name = $this->Dbo->fullTableName('timestamp_default_values');
|
||||||
|
$sql = <<<SQL
|
||||||
|
CREATE TABLE $name (
|
||||||
|
id INT NOT NULL,
|
||||||
|
phone VARCHAR(10),
|
||||||
|
limit_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (id)
|
||||||
|
);
|
||||||
|
SQL;
|
||||||
|
$this->Dbo->execute($sql);
|
||||||
|
$model = new Model(array(
|
||||||
|
'table' => 'timestamp_default_values',
|
||||||
|
'ds' => 'test',
|
||||||
|
'alias' => 'TimestampDefaultValue'
|
||||||
|
));
|
||||||
|
$result = $this->Dbo->describe($model);
|
||||||
|
$this->Dbo->execute('DROP TABLE ' . $name);
|
||||||
|
|
||||||
|
$this->assertNull($result['limit_date']['default']);
|
||||||
|
|
||||||
|
$schema = new CakeSchema(array(
|
||||||
|
'connection' => 'test',
|
||||||
|
'testdescribes' => $result
|
||||||
|
));
|
||||||
|
$result = $this->Dbo->createSchema($schema);
|
||||||
|
$this->assertContains('"limit_date" timestamp NOT NULL', $result);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test virtualFields with functions.
|
* Test virtualFields with functions.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue