From 3f96a94e2c6ab2b21a2cbafa5462ff16f5710051 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 3 Jan 2018 13:15:59 -0800 Subject: [PATCH] Fixed handling special characters in default values on Oracle --- .../DBAL/Platforms/OraclePlatform.php | 10 ------- .../DBAL/Schema/OracleSchemaManager.php | 8 ++++-- .../SchemaManagerFunctionalTestCase.php | 28 ++++++++++--------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 7e05af1b1e5..30799fd4e33 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -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); - } } diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 3b043788863..b3715f61a84 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -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; diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index f4b54dd85cd..54715a93e55 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -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'], ]; } @@ -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]); } } }