mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Allow CURRENT_TIMESTAMP for datetime columns - MySQL5.6+.
This commit is contained in:
parent
4a316b158e
commit
d8a55ad065
2 changed files with 36 additions and 1 deletions
|
@ -352,7 +352,7 @@ class Mysql extends DboSource {
|
||||||
if (in_array($fields[$column->Field]['type'], $this->fieldParameters['unsigned']['types'], true)) {
|
if (in_array($fields[$column->Field]['type'], $this->fieldParameters['unsigned']['types'], true)) {
|
||||||
$fields[$column->Field]['unsigned'] = $this->_unsigned($column->Type);
|
$fields[$column->Field]['unsigned'] = $this->_unsigned($column->Type);
|
||||||
}
|
}
|
||||||
if ($fields[$column->Field]['type'] === 'timestamp' && strtoupper($column->Default) === 'CURRENT_TIMESTAMP') {
|
if (in_array($fields[$column->Field]['type'], array('timestamp', 'datetime')) && strtoupper($column->Default) === 'CURRENT_TIMESTAMP') {
|
||||||
$fields[$column->Field]['default'] = null;
|
$fields[$column->Field]['default'] = null;
|
||||||
}
|
}
|
||||||
if (!empty($column->Key) && isset($this->index[$column->Key])) {
|
if (!empty($column->Key) && isset($this->index[$column->Key])) {
|
||||||
|
|
|
@ -927,6 +927,41 @@ SQL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Test that describe() ignores `default current_timestamp` in datetime columns.
|
||||||
|
* This is for MySQL >= 5.6.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDescribeHandleCurrentTimestampDatetime() {
|
||||||
|
$name = $this->Dbo->fullTableName('timestamp_default_values');
|
||||||
|
$sql = <<<SQL
|
||||||
|
CREATE TABLE $name (
|
||||||
|
id INT(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
phone VARCHAR(10),
|
||||||
|
limit_date DATETIME 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` datetime NOT NULL,', $result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
* test that a describe() gets additional fieldParameters
|
* test that a describe() gets additional fieldParameters
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|
Loading…
Reference in a new issue