Skip to content

Commit

Permalink
Fixed handling special characters in default values on Oracle
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Apr 11, 2019
1 parent 73a2909 commit d6cc725
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
10 changes: 8 additions & 2 deletions lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
use function array_values;
use function assert;
use function preg_match;
use function preg_replace;
use function sprintf;
use function str_replace;
use function strpos;
use function strtolower;
use function strtoupper;
Expand Down Expand Up @@ -144,8 +146,12 @@ protected function _getPortableTableColumnDefinition($tableColumn)
}

if ($tableColumn['data_default'] !== null) {
// Default values returned from database are enclosed in single quotes.
$tableColumn['data_default'] = trim($tableColumn['data_default'], "'");
// Default values returned from database are represented as literal expressions
$tableColumn['data_default'] = str_replace(
"''",
"'",
preg_replace('/^\'(.*)\'$/s', '$1', $tableColumn['data_default'])
);
}

if ($tableColumn['data_precision'] !== null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1507,19 +1507,20 @@ public function testCreateAndListSequences() : void
private function getEscapedLiterals() : iterable
{
return [
['An ASCII NUL (X\'00\')', "foo\\0bar"],
['Single quote, C-style', "foo\\'bar"],
['An ASCII NUL (X\'00\')', "foo\0bar"],
['Single quote, C-style', "foo'bar"],
['Single quote, doubled-style', "foo''bar"],
['Double quote, C-style', 'foo\\"bar'],
['Double quote, C-style', 'foo"bar'],
['Double quote, double-style', 'foo""bar'],
['Backspace', 'foo\\bbar'],
['New-line', 'foo\\nbar'],
['Carriage return', 'foo\\rbar'],
['Tab', 'foo\\tbar'],
['ASCII 26 (Control+Z)', 'foo\\Zbar'],
['Backslash (\)', 'foo\\\\bar'],
['Percent (%)', 'foo\\%bar'],
['Underscore (_)', 'foo\\_bar'],
['Backspace', "foo\x08bar"],
['New-line', "foo\nbar"],
['Carriage return', "foo\rbar"],
['Tab', "foo\tbar"],
['ASCII 26 (Control+Z)', "foo\x1abar"],
['Backslash (\)', 'foo\\bar'],
['Double backslash', 'foo\\\\bar'],
['Percent (%)', 'foo%bar'],
['Underscore (_)', 'foo_bar'],
];
}

Expand Down Expand Up @@ -1549,7 +1550,6 @@ public function testEscapedDefaultValueCanBeInserted() : void
$this->createTableForDefaultValues();

$this->connection->insert('string_escaped_default_value', ['def_foo' => 'foo']);

foreach ($this->getEscapedLiterals() as $i => $literal) {
$value = $this->connection->fetchColumn('SELECT field' . $i . ' FROM string_escaped_default_value');
self::assertSame($literal[1], $value, 'inserted default value should be the configured default value for: ' . $literal[0]);
Expand Down

0 comments on commit d6cc725

Please sign in to comment.