Browse Source

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
tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
598d01287b
  1. 20
      framework/yii/db/cubrid/Schema.php
  2. 6
      tests/unit/framework/db/cubrid/CubridActiveRecordTest.php

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

@ -237,4 +237,24 @@ class Schema extends \yii\db\Schema
} }
return $tableNames; 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;
}
} }

6
tests/unit/framework/db/cubrid/CubridActiveRecordTest.php

@ -32,5 +32,11 @@ class CubridActiveRecordTest extends ActiveRecordTest
$customer->refresh(); $customer->refresh();
$this->assertEquals(0, $customer->status); $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));
} }
} }

Loading…
Cancel
Save