Automatic escaping of default values

It is now possible to use `\` in non-escaped default values for a column,
and it will be automatically escaped for platforms that need it.

Previously this lead to a confusion when diffing actual and expected
schema leading to perpetual out of sync schema.

Before:

```php
/**
 * @ORM\Column(options={"default" = "Foo\\Bar"}))
 */
private $name;

```

After:

```php
/**
 * @ORM\Column(options={"default" = "Foo\Bar"}))
 */
private $name;

```

And the result in database will be a default value exactly as written in
the annotation, that is `Foo\Bar`.
parent 00381a6b
......@@ -2306,7 +2306,7 @@ abstract class AbstractPlatform
return " DEFAULT '" . $this->convertBooleans($default) . "'";
}
return " DEFAULT '" . $default . "'";
return " DEFAULT " . $this->quoteStringLiteral($default);
}
/**
......
......@@ -907,4 +907,15 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
self::assertContains('bar', $sql);
self::assertNotContains('DATABASE()', $sql);
}
public function testGetDefaultValueDeclarationSQLEscaped()
{
// string must be escaped
$field = array(
'type' => 'string',
'default' => 'Foo\\Bar'
);
self::assertEquals(" DEFAULT 'Foo\\\\Bar'", $this->_platform->getDefaultValueDeclarationSQL($field));
}
}
......@@ -976,4 +976,15 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
true
);
}
public function testGetDefaultValueDeclarationSQLEscaped()
{
// string must be escaped
$field = array(
'type' => 'string',
'default' => 'Foo\\Bar'
);
self::assertEquals(" DEFAULT 'Foo\\\\Bar'", $this->_platform->getDefaultValueDeclarationSQL($field));
}
}
......@@ -874,4 +874,15 @@ EOD;
{
self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true);
}
public function testGetDefaultValueDeclarationSQLEscaped()
{
// string must be escaped
$field = array(
'type' => 'string',
'default' => 'Foo\\Bar'
);
self::assertEquals(" DEFAULT 'Foo\\\\Bar'", $this->_platform->getDefaultValueDeclarationSQL($field));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment