From 791f9d3f4e815244cc67c6cc2e928d57d884c76b Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 6 Sep 2013 13:21:35 +0200 Subject: [PATCH] better use int for boolean representation bit has special syntax for storing and retreiving so we'd need a converter for that. Storing 1 bit will result in one byte left padded on the disc so the result of a query for boolean 0 will be 0x00 and for boolean 1 will be 0x80. --- framework/yii/db/cubrid/QueryBuilder.php | 2 +- framework/yii/db/cubrid/Schema.php | 11 +---------- tests/unit/data/cubrid.sql | 4 ++-- tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php | 4 ++-- 4 files changed, 6 insertions(+), 15 deletions(-) diff --git a/framework/yii/db/cubrid/QueryBuilder.php b/framework/yii/db/cubrid/QueryBuilder.php index 4e5121a..935b3d3 100644 --- a/framework/yii/db/cubrid/QueryBuilder.php +++ b/framework/yii/db/cubrid/QueryBuilder.php @@ -34,7 +34,7 @@ class QueryBuilder extends \yii\db\QueryBuilder Schema::TYPE_TIME => 'time', Schema::TYPE_DATE => 'date', Schema::TYPE_BINARY => 'blob', - Schema::TYPE_BOOLEAN => 'bit(1)', + Schema::TYPE_BOOLEAN => 'smallint', Schema::TYPE_MONEY => 'decimal(19,4)', ); diff --git a/framework/yii/db/cubrid/Schema.php b/framework/yii/db/cubrid/Schema.php index a423296..c07602f 100644 --- a/framework/yii/db/cubrid/Schema.php +++ b/framework/yii/db/cubrid/Schema.php @@ -198,15 +198,6 @@ class Schema extends \yii\db\Schema if (isset($values[1])) { $column->scale = (int)$values[1]; } - if ($type === 'bit' || $type === 'bit varying') { - if ($column->size === 1) { - $column->type = self::TYPE_BOOLEAN; - } elseif ($column->size > 32) { - $column->type = self::TYPE_BIGINT; - } elseif ($column->size === 32) { - $column->type = self::TYPE_INTEGER; - } - } } } } @@ -253,7 +244,7 @@ class Schema extends \yii\db\Schema public function getPdoType($data) { static $typeMap = array( - 'boolean' => \PDO::PARAM_STR, // CUBRID PDO does not support PARAM_BOOL + 'boolean' => \PDO::PARAM_INT, // CUBRID PDO does not support PARAM_BOOL 'integer' => \PDO::PARAM_INT, 'string' => \PDO::PARAM_STR, 'resource' => \PDO::PARAM_LOB, diff --git a/tests/unit/data/cubrid.sql b/tests/unit/data/cubrid.sql index 2cf7716..5525418 100644 --- a/tests/unit/data/cubrid.sql +++ b/tests/unit/data/cubrid.sql @@ -71,8 +71,8 @@ CREATE TABLE `tbl_type` ( `blob_col` blob, `numeric_col` decimal(5,2) DEFAULT '33.22', `time` timestamp NOT NULL DEFAULT '2002-01-01 00:00:00', - `bool_col` bit(1) NOT NULL, - `bool_col2` bit(1) DEFAULT B'1' + `bool_col` smallint NOT NULL, + `bool_col2` smallint DEFAULT 1 ); INSERT INTO tbl_customer (email, name, address, status) VALUES ('user1@example.com', 'user1', 'address1', 1); diff --git a/tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php b/tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php index 36967d7..94a002e 100644 --- a/tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php +++ b/tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php @@ -67,8 +67,8 @@ class CubridQueryBuilderTest extends QueryBuilderTest array(Schema::TYPE_DATE . " CHECK(value BETWEEN '2011-01-01' AND '2013-01-01')", "date CHECK(value BETWEEN '2011-01-01' AND '2013-01-01')"), array(Schema::TYPE_DATE . ' NOT NULL', 'date NOT NULL'), array(Schema::TYPE_BINARY, 'blob'), - array(Schema::TYPE_BOOLEAN, 'bit(1)'), - array(Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', 'bit(1) NOT NULL DEFAULT 1'), + array(Schema::TYPE_BOOLEAN, 'smallint'), + array(Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', 'smallint NOT NULL DEFAULT 1'), array(Schema::TYPE_MONEY, 'decimal(19,4)'), array(Schema::TYPE_MONEY . '(16,2)', 'decimal(16,2)'), array(Schema::TYPE_MONEY . ' CHECK (value > 0.0)', 'decimal(19,4) CHECK (value > 0.0)'),