From 598d01287b0e052f2813fadae8e63a3e4bf03269 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Tue, 15 Oct 2013 03:36:45 +0200 Subject: [PATCH] added cubrid specific pdo type casting cubrid pdo does not support PARAM_BOOL so we cast the value to integer and store 0 and 1 instead fixes #964 --- framework/yii/db/cubrid/Schema.php | 20 ++++++++++++++++++++ .../framework/db/cubrid/CubridActiveRecordTest.php | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/framework/yii/db/cubrid/Schema.php b/framework/yii/db/cubrid/Schema.php index ba7fcae..5a57b64 100644 --- a/framework/yii/db/cubrid/Schema.php +++ b/framework/yii/db/cubrid/Schema.php @@ -237,4 +237,24 @@ class Schema extends \yii\db\Schema } return $tableNames; } + + /** + * Determines the PDO type for the given PHP data value. + * @param mixed $data the data whose PDO type is to be determined + * @return integer the PDO type + * @see http://www.php.net/manual/en/pdo.constants.php + */ + public function getPdoType($data) + { + static $typeMap = array( + // php type => PDO type + 'boolean' => \PDO::PARAM_INT, // PARAM_BOOL is not supported by CUBRID PDO + 'integer' => \PDO::PARAM_INT, + 'string' => \PDO::PARAM_STR, + 'resource' => \PDO::PARAM_LOB, + 'NULL' => \PDO::PARAM_NULL, + ); + $type = gettype($data); + return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR; + } } diff --git a/tests/unit/framework/db/cubrid/CubridActiveRecordTest.php b/tests/unit/framework/db/cubrid/CubridActiveRecordTest.php index 2d2db15..49f9bc0 100644 --- a/tests/unit/framework/db/cubrid/CubridActiveRecordTest.php +++ b/tests/unit/framework/db/cubrid/CubridActiveRecordTest.php @@ -32,5 +32,11 @@ class CubridActiveRecordTest extends ActiveRecordTest $customer->refresh(); $this->assertEquals(0, $customer->status); + + $customers = Customer::find()->where(array('status' => true))->all(); + $this->assertEquals(2, count($customers)); + + $customers = Customer::find()->where(array('status' => false))->all(); + $this->assertEquals(1, count($customers)); } }