From e996f3dfd579eed51f24eaa6415b367f7cb1b1f7 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 6 Sep 2013 13:53:33 +0200 Subject: [PATCH] Workaround for broken PDO::quote() in CUBRID 9.1.0 http://jira.cubrid.org/browse/APIS-658 --- framework/yii/db/cubrid/Schema.php | 13 ++++++------- tests/unit/framework/db/cubrid/CubridConnectionTest.php | 8 ++++++++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/framework/yii/db/cubrid/Schema.php b/framework/yii/db/cubrid/Schema.php index c07602f..d1fdc10 100644 --- a/framework/yii/db/cubrid/Schema.php +++ b/framework/yii/db/cubrid/Schema.php @@ -96,18 +96,17 @@ class Schema extends \yii\db\Schema */ public function quoteValue($str) { - throw new NotSupportedException('quoteValue is currently broken in cubrid PDO'); - // TODO implement workaround -/* if (!is_string($str)) { + if (!is_string($str)) { return $str; } $this->db->open(); - if (($value = $this->db->pdo->quote($str)) !== false) { - return $value; - } else { // the driver doesn't support quote (e.g. oci) + // workaround for broken PDO::quote() implementation in CUBRID 9.1.0 http://jira.cubrid.org/browse/APIS-658 + if (version_compare($this->db->pdo->getAttribute(\PDO::ATTR_CLIENT_VERSION), '9.1.0', '<=')) { return "'" . addcslashes(str_replace("'", "''", $str), "\000\n\r\\\032") . "'"; - }*/ + } else { + return $this->db->pdo->quote($str); + } } /** diff --git a/tests/unit/framework/db/cubrid/CubridConnectionTest.php b/tests/unit/framework/db/cubrid/CubridConnectionTest.php index 2937d22..bfd2c90 100644 --- a/tests/unit/framework/db/cubrid/CubridConnectionTest.php +++ b/tests/unit/framework/db/cubrid/CubridConnectionTest.php @@ -10,4 +10,12 @@ class CubridConnectionTest extends ConnectionTest $this->driverName = 'cubrid'; parent::setUp(); } + + public function testQuoteValue() + { + $connection = $this->getConnection(false); + $this->assertEquals(123, $connection->quoteValue(123)); + $this->assertEquals("'string'", $connection->quoteValue('string')); + $this->assertEquals("'It''s interesting'", $connection->quoteValue("It's interesting")); + } }