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]); } } } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 7ebbea2d11f..2d3d9558e01 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -832,7 +832,7 @@ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() */ public function testQuotesDatabaseNameInListSequencesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListSequencesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListSequencesSQL("Foo'Bar\\"), '', true); } /** @@ -840,7 +840,7 @@ public function testQuotesDatabaseNameInListSequencesSQL() */ public function testQuotesTableNameInListTableIndexesSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true); } /** @@ -848,7 +848,7 @@ public function testQuotesTableNameInListTableIndexesSQL() */ public function testQuotesTableNameInListTableForeignKeysSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true); } /** @@ -856,7 +856,7 @@ public function testQuotesTableNameInListTableForeignKeysSQL() */ public function testQuotesTableNameInListTableConstraintsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true); } /** @@ -864,7 +864,7 @@ public function testQuotesTableNameInListTableConstraintsSQL() */ public function testQuotesTableNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true); } /** @@ -872,6 +872,6 @@ public function testQuotesTableNameInListTableColumnsSQL() */ public function testQuotesDatabaseNameInListTableColumnsSQL() { - self::assertContains("'Foo''Bar\\\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); + self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\"), '', true); } }