Commit 00adfbd0 authored by Kim Hemsø Rasmussen's avatar Kim Hemsø Rasmussen

Hopefully final fixes. Added phpdoc @inheritdoc where it were missing. Added...

Hopefully final fixes. Added phpdoc @inheritdoc where it were missing. Added MysqlConnection::getWrappedResourceHandle(). MysqliStatement::fetchAll() now decide fetch style if none is set, instead of letting fetch() do it on every call.
parent 208dd75f
......@@ -26,26 +26,41 @@ use Doctrine\DBAL\Driver as DriverInterface;
*/
class Driver implements DriverInterface
{
/**
* {@inheritdoc}
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{
return new MysqliConnection($params, $username, $password, $driverOptions);
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'mysqli';
}
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{
return new \Doctrine\DBAL\Schema\MySqlSchemaManager($conn);
}
/**
* {@inheritdoc}
*/
public function getDatabasePlatform()
{
return new \Doctrine\DBAL\Platforms\MySqlPlatform();
}
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn)
{
$params = $conn->getParams();
......
......@@ -19,12 +19,12 @@
namespace Doctrine\DBAL\Driver\Mysqli;
use Doctrine\DBAL\Driver\Connection as ConnectionInterface;
use Doctrine\DBAL\Driver\Connection as Connection;
/**
* @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/
class MysqliConnection implements ConnectionInterface
class MysqliConnection implements Connection
{
/**
* @var \mysqli
......@@ -43,11 +43,29 @@ class MysqliConnection implements ConnectionInterface
}
}
/**
* Retrieve mysqli native resource handle.
*
* Could be used if part of your application is not using DBAL
*
* @return mysqli
*/
public function getWrappedResourceHandle()
{
return $this->_conn;
}
/**
* {@inheritdoc}
*/
public function prepare($prepareString)
{
return new MysqliStatement($this->_conn, $prepareString);
}
/**
* {@inheritdoc}
*/
public function query()
{
$args = func_get_args();
......@@ -57,43 +75,67 @@ class MysqliConnection implements ConnectionInterface
return $stmt;
}
/**
* {@inheritdoc}
*/
public function quote($input, $type=\PDO::PARAM_STR)
{
return "'". $this->_conn->escape_string($input) ."'";
}
/**
* {@inheritdoc}
*/
public function exec($statement)
{
$this->_conn->query($statement);
return $this->_conn->affected_rows;
}
/**
* {@inheritdoc}
*/
public function lastInsertId($name = null)
{
return $this->_conn->insert_id;
}
/**
* {@inheritdoc}
*/
public function beginTransaction()
{
$this->_conn->query('START TRANSACTION');
return true;
}
/**
* {@inheritdoc}
*/
public function commit()
{
return $this->_conn->commit();
}
/**
* {@inheritdoc}non-PHPdoc)
*/
public function rollBack()
{
return $this->_conn->rollback();
}
/**
* {@inheritdoc}
*/
public function errorCode()
{
return $this->_conn->errno;
}
/**
* {@inheritdoc}
*/
public function errorInfo()
{
return $this->_conn->error;
......
......@@ -27,7 +27,7 @@ use PDO;
*/
class MysqliStatement implements \IteratorAggregate, Statement
{
private static $_paramTypeMap = array(
protected static $_paramTypeMap = array(
PDO::PARAM_STR => 's',
PDO::PARAM_BOOL => 'i',
PDO::PARAM_NULL => 's',
......@@ -35,32 +35,32 @@ class MysqliStatement implements \IteratorAggregate, Statement
PDO::PARAM_LOB => 's' // TODO Support LOB bigger then max package size.
);
private $_conn;
private $_stmt;
protected $_conn;
protected $_stmt;
/**
* @var null|false|array
*/
private $_columnNames;
protected $_columnNames;
/**
* @var null|array
*/
private $_rowBindedValues;
protected $_rowBindedValues;
/**
* @var array
*/
private $_bindedValues;
protected $_bindedValues;
/**
* Contains ref values for bindValue()
*
* @var array
*/
private $_values = array();
protected $_values = array();
private $_defaultFetchStyle = PDO::FETCH_BOTH;
protected $_defaultFetchStyle = PDO::FETCH_BOTH;
public function __construct(\mysqli $conn, $prepareString)
{
......@@ -73,7 +73,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
$paramCount = $this->_stmt->param_count;
if (0 < $paramCount) {
// Index 0 is types
// Need to init the string else php think we are trying to access it as a array. Better solution for this ?
// Need to init the string else php think we are trying to access it as a array.
$bindedValues = array(0 => str_repeat('s', $paramCount));
$null = null;
for ($i = 1; $i < $paramCount; $i++) {
......@@ -205,7 +205,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
if (true === $ret) {
$values = array();
foreach ($this->_rowBindedValues as $v) {
// Mysqli converts them to a scalar type it can fit in. Tests dont expect that.
// Mysqli converts them to a scalar type it can fit in.
$values[] = null === $v ? null : (string)$v;
}
return $values;
......@@ -251,6 +251,8 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/
public function fetchAll($fetchStyle = null)
{
$fetchStyle = $fetchStyle ?: $this->_defaultFetchStyle;
$a = array();
while (($row = $this->fetch($fetchStyle)) !== null) {
$a[] = $row;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment