moved getPDOType() back to Command to avoid dependency on Schema

fixes #854
This commit is contained in:
Carsten Brandt
2013-09-18 16:29:16 +02:00
parent cc09ef56b9
commit ef13a11f66
9 changed files with 70 additions and 96 deletions

View File

@@ -181,7 +181,7 @@ class Command extends \yii\base\Component
{
$this->prepare();
if ($dataType === null) {
$this->pdoStatement->bindParam($name, $value, $this->db->schema->getPdoType($value));
$this->pdoStatement->bindParam($name, $value, $this->getPdoType($value));
} elseif ($length === null) {
$this->pdoStatement->bindParam($name, $value, $dataType);
} elseif ($driverOptions === null) {
@@ -208,7 +208,7 @@ class Command extends \yii\base\Component
{
$this->prepare();
if ($dataType === null) {
$this->pdoStatement->bindValue($name, $value, $this->db->schema->getPdoType($value));
$this->pdoStatement->bindValue($name, $value, $this->getPdoType($value));
} else {
$this->pdoStatement->bindValue($name, $value, $dataType);
}
@@ -236,7 +236,7 @@ class Command extends \yii\base\Component
$type = $value[1];
$value = $value[0];
} else {
$type = $this->db->schema->getPdoType($value);
$type = $this->getPdoType($value);
}
$this->pdoStatement->bindValue($name, $value, $type);
$this->_params[$name] = $value;
@@ -245,6 +245,25 @@ class Command extends \yii\base\Component
return $this;
}
/**
* 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
*/
private function getPdoType($data)
{
static $typeMap = array( // php type => PDO type
'boolean' => \PDO::PARAM_BOOL,
'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;
}
/**
* Executes the SQL statement.
* This method should only be used for executing non-query SQL statement, such as `INSERT`, `DELETE`, `UPDATE` SQLs.

View File

@@ -377,23 +377,4 @@ abstract class Schema extends Object
return 'string';
}
}
/**
* Determines the PDO type for the give 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_BOOL,
'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;
}
}

View File

@@ -237,23 +237,4 @@ class Schema extends \yii\db\Schema
}
return $tableNames;
}
/**
* Determines the PDO type for the give 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(
'boolean' => \PDO::PARAM_INT, // CUBRID PDO does not support PARAM_BOOL
'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;
}
}