Skip to content
Permalink
Browse files

Fix default value handling in SQLServer.

  • Loading branch information...
markstory committed May 26, 2016
1 parent 34defff commit bb0ee7dfbeaf4ef5620c6316ad662d15f0e38d6e
Showing with 34 additions and 1 deletion.
  1. +24 −1 src/Database/Schema/SqlserverSchema.php
  2. +10 −0 tests/TestCase/Database/Schema/SqlserverSchemaTest.php
@@ -161,11 +161,34 @@ public function convertColumnDescription(Table $table, $row)
$field += [
'null' => $row['null'] === '1' ? true : false,
'default' => $row['default'],
'default' => $this->_defaultValue($row['default']),
];
$table->addColumn($row['name'], $field);
}
/**
* Manipulate the default value.
*
* Sqlite includes quotes and bared NULLs in default values.
* We need to remove those.
*
* @param string|null $default The default value.
* @return string|null
*/
protected function _defaultValue($default)
{
if ($default === 'NULL') {
return null;
}
// Remove quotes
if (preg_match("/^'(.*)'$/", $default, $matches)) {
return str_replace("''", "'", $matches[1]);
}
return $default;
}
/**
* {@inheritDoc}
*/
@@ -70,6 +70,7 @@ protected function _createTables($connection)
created DATETIME,
field1 VARCHAR(10) DEFAULT NULL,
field2 VARCHAR(10) DEFAULT 'NULL',
field3 VARCHAR(10) DEFAULT 'O''hare',
CONSTRAINT [content_idx] UNIQUE ([title], [body]),
CONSTRAINT [author_idx] FOREIGN KEY ([author_id]) REFERENCES [schema_authors] ([id]) ON DELETE CASCADE ON UPDATE CASCADE
)
@@ -365,6 +366,15 @@ public function testDescribeTable()
'fixed' => null,
'comment' => null,
],
'field3' => [
'type' => 'string',
'null' => true,
'default' => 'O\'hare',
'length' => 10,
'precision' => null,
'fixed' => null,
'comment' => null,
],
];
$this->assertEquals(['id'], $result->primaryKey());
foreach ($expected as $field => $definition) {

0 comments on commit bb0ee7d

Please sign in to comment.
You can’t perform that action at this time.