230,7 → 230,7 |
public function create ($dsn, $username = null, $password = null, |
array $options = null, $dbspec = null, $force = false) |
{ |
$connection = new PDO($dsn, |
$connection = new \PDO($dsn, |
$username !== null ? $username : $this->_username, |
$password !== null ? $password : $this->_password, |
$options !== null ? $options : $this->_options); |
244,6 → 244,81 |
} |
|
/** |
* Maps column meta-information to a column definition. |
* |
* Should be overwritten and called by inheriting classes. |
* |
* @todo |
* @param array $value |
* @param string $column_name |
* @return string |
*/ |
protected function _columnDef (array $data, $column_name) |
{ |
$def = (isset($data['unsigned']) && $data['unsigned'] ? 'UNSIGNED ' : '') |
. $data['type'] |
. (isset($data['not_null']) && $data['not_null'] ? ' NOT NULL' : ' NULL') |
. (isset($data['default']) && $data['default'] ? " DEFAULT {$data['default']}" : '') |
. (isset($data['auto_inc']) && $data['auto_inc'] ? ' AUTO_INCREMENT' : '') |
. (isset($data['unique']) && $data['unique'] ? ' UNIQUE KEY' : '') |
. (isset($data['primary']) && $data['primary'] ? ' PRIMARY KEY' : '') |
. (isset($data['comment']) && $data['comment'] ? " COMMENT '{$data['comment']}'" : ''); |
|
return $this->escapeName($column_name) . ' ' . $def; |
} |
|
/** |
* Creates a database table according to the specified parameters |
* |
* @todo |
* @param string $name |
* @param array $columns |
* @param array $options = null |
* @return bool |
* @see PDOStatement::execute() |
*/ |
public function createTable ($name, array $columns, array $options = null) |
{ |
$class = \get_class($this); |
$query = 'CREATE TABLE ' |
. $this->escapeName($name) |
. '(' |
. array_map(array($this, '_columnDef'), $columns, array_keys($columns)) . ')'; |
|
$stmt = $this->prepare($query); |
|
/* DEBUG */ |
if (defined('DEBUG') && DEBUG > 1) |
{ |
debug(array( |
'query' => $query, |
)); |
} |
|
$success =& $this->_lastSuccess; |
$success = $stmt->execute(); |
|
$errorInfo =& $this->_lastError; |
$errorInfo = $stmt->errorInfo(); |
|
$this->_resetLastInsertId(); |
|
$result =& $this->_lastResult; |
$result = $stmt->fetchAll(); |
|
if (defined('DEBUG') && DEBUG > 1) |
{ |
debug(array( |
'_lastSuccess' => $success, |
'_lastError' => $errorInfo, |
'_lastResult' => $result |
)); |
} |
|
return $success; |
} |
|
/** |
* Initiates a transaction |
* |
* @return bool |