Browse Source

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.
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
791f9d3f4e
  1. 2
      framework/yii/db/cubrid/QueryBuilder.php
  2. 11
      framework/yii/db/cubrid/Schema.php
  3. 4
      tests/unit/data/cubrid.sql
  4. 4
      tests/unit/framework/db/cubrid/CubridQueryBuilderTest.php

2
framework/yii/db/cubrid/QueryBuilder.php

@ -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)',
); );

11
framework/yii/db/cubrid/Schema.php

@ -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
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,

4
tests/unit/data/cubrid.sql

@ -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);

4
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 . " 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)'),

Loading…
Cancel
Save