Commit 791f9d3f by Carsten Brandt

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.
parent c6ef7ec9
...@@ -34,7 +34,7 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -34,7 +34,7 @@ class QueryBuilder extends \yii\db\QueryBuilder
Schema::TYPE_TIME => 'time', Schema::TYPE_TIME => 'time',
Schema::TYPE_DATE => 'date', Schema::TYPE_DATE => 'date',
Schema::TYPE_BINARY => 'blob', Schema::TYPE_BINARY => 'blob',
Schema::TYPE_BOOLEAN => 'bit(1)', Schema::TYPE_BOOLEAN => 'smallint',
Schema::TYPE_MONEY => 'decimal(19,4)', Schema::TYPE_MONEY => 'decimal(19,4)',
); );
......
...@@ -198,15 +198,6 @@ class Schema extends \yii\db\Schema ...@@ -198,15 +198,6 @@ class Schema extends \yii\db\Schema
if (isset($values[1])) { if (isset($values[1])) {
$column->scale = (int)$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 ...@@ -253,7 +244,7 @@ class Schema extends \yii\db\Schema
public function getPdoType($data) public function getPdoType($data)
{ {
static $typeMap = array( 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, 'integer' => \PDO::PARAM_INT,
'string' => \PDO::PARAM_STR, 'string' => \PDO::PARAM_STR,
'resource' => \PDO::PARAM_LOB, 'resource' => \PDO::PARAM_LOB,
......
...@@ -71,8 +71,8 @@ CREATE TABLE `tbl_type` ( ...@@ -71,8 +71,8 @@ CREATE TABLE `tbl_type` (
`blob_col` blob, `blob_col` blob,
`numeric_col` decimal(5,2) DEFAULT '33.22', `numeric_col` decimal(5,2) DEFAULT '33.22',
`time` timestamp NOT NULL DEFAULT '2002-01-01 00:00:00', `time` timestamp NOT NULL DEFAULT '2002-01-01 00:00:00',
`bool_col` bit(1) NOT NULL, `bool_col` smallint NOT NULL,
`bool_col2` bit(1) DEFAULT B'1' `bool_col2` smallint DEFAULT 1
); );
INSERT INTO tbl_customer (email, name, address, status) VALUES ('user1@example.com', 'user1', 'address1', 1); INSERT INTO tbl_customer (email, name, address, status) VALUES ('user1@example.com', 'user1', 'address1', 1);
......
...@@ -67,8 +67,8 @@ class CubridQueryBuilderTest extends QueryBuilderTest ...@@ -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 . " 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_DATE . ' NOT NULL', 'date NOT NULL'),
array(Schema::TYPE_BINARY, 'blob'), array(Schema::TYPE_BINARY, 'blob'),
array(Schema::TYPE_BOOLEAN, 'bit(1)'), array(Schema::TYPE_BOOLEAN, 'smallint'),
array(Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', 'bit(1) NOT NULL DEFAULT 1'), array(Schema::TYPE_BOOLEAN . ' NOT NULL DEFAULT 1', 'smallint NOT NULL DEFAULT 1'),
array(Schema::TYPE_MONEY, 'decimal(19,4)'), array(Schema::TYPE_MONEY, 'decimal(19,4)'),
array(Schema::TYPE_MONEY . '(16,2)', 'decimal(16,2)'), array(Schema::TYPE_MONEY . '(16,2)', 'decimal(16,2)'),
array(Schema::TYPE_MONEY . ' CHECK (value > 0.0)', 'decimal(19,4) CHECK (value > 0.0)'), array(Schema::TYPE_MONEY . ' CHECK (value > 0.0)', 'decimal(19,4) CHECK (value > 0.0)'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment