Skip to content

Commit

Permalink
better use int for boolean representation
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cebe committed Sep 6, 2013
1 parent c6ef7ec commit 791f9d3
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
2 changes: 1 addition & 1 deletion framework/yii/db/cubrid/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
);

Expand Down
11 changes: 1 addition & 10 deletions framework/yii/db/cubrid/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,6 @@ protected function loadColumnSchema($info)
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;
}
}
}
}
}
Expand Down Expand Up @@ -253,7 +244,7 @@ protected function findTableNames($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,
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/data/cubrid.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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 ('[email protected]', 'user1', 'address1', 1);
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ public function columnTypes()
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)'),
Expand Down

0 comments on commit 791f9d3

Please sign in to comment.