mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-18 18:46:17 +00:00
Merge pull request #8852 from MarkusBauer/v2.x/SqliteFixCurrentTimestampDefault
Fixing 'default current_timestamp' in Sqlite
This commit is contained in:
commit
11661be50f
2 changed files with 37 additions and 0 deletions
|
@ -185,6 +185,9 @@ class Sqlite extends DboSource {
|
|||
'default' => $default,
|
||||
'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) {
|
||||
$fields[$column['name']]['key'] = $this->index['PRI'];
|
||||
$fields[$column['name']]['null'] = false;
|
||||
|
|
|
@ -422,6 +422,40 @@ class SqliteTest extends CakeTestCase {
|
|||
$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.
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue