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 Jan 3, 2018
1 parent e3ab127 commit 3f96a94
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
10 changes: 0 additions & 10 deletions lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1166,14 +1166,4 @@ public function getBlobTypeDeclarationSQL(array $field)
{
return 'BLOB';
}

/**
* {@inheritdoc}
*/
public function quoteStringLiteral($str)
{
$str = str_replace('\\', '\\\\', $str); // Oracle requires backslashes to be escaped aswell.

return parent::quoteStringLiteral($str);
}
}
8 changes: 6 additions & 2 deletions lib/Doctrine/DBAL/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,12 @@ protected function _getPortableTableColumnDefinition($tableColumn)
}

if (null !== $tableColumn['data_default']) {
// 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'])
);
}

$precision = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1410,19 +1410,20 @@ public function testCreateAndListSequences() : void
private function getEscapedLiterals() : array
{
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 @@ -1452,9 +1453,10 @@ public function testEscapedDefaultValueCanBeInserted() : void
$this->createTableForDefaultValues();

$this->_conn->insert('string_escaped_default_value', ['def_foo' => 'foo']);
$row = $this->_conn->fetchAssoc('SELECT * FROM string_escaped_default_value');

foreach ($this->getEscapedLiterals() as $i => $literal) {
self::assertSame($literal[1], $row['field' . $i], 'inserted default value should be the configured default value for: ' . $literal[0]);
$value = $this->_conn->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]);
}
}
}

0 comments on commit 3f96a94

Please sign in to comment.