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; ...@@ -26,26 +26,41 @@ use Doctrine\DBAL\Driver as DriverInterface;
*/ */
class Driver implements DriverInterface class Driver implements DriverInterface
{ {
/**
* {@inheritdoc}
*/
public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) public function connect(array $params, $username = null, $password = null, array $driverOptions = array())
{ {
return new MysqliConnection($params, $username, $password, $driverOptions); return new MysqliConnection($params, $username, $password, $driverOptions);
} }
/**
* {@inheritdoc}
*/
public function getName() public function getName()
{ {
return 'mysqli'; return 'mysqli';
} }
/**
* {@inheritdoc}
*/
public function getSchemaManager(\Doctrine\DBAL\Connection $conn) public function getSchemaManager(\Doctrine\DBAL\Connection $conn)
{ {
return new \Doctrine\DBAL\Schema\MySqlSchemaManager($conn); return new \Doctrine\DBAL\Schema\MySqlSchemaManager($conn);
} }
/**
* {@inheritdoc}
*/
public function getDatabasePlatform() public function getDatabasePlatform()
{ {
return new \Doctrine\DBAL\Platforms\MySqlPlatform(); return new \Doctrine\DBAL\Platforms\MySqlPlatform();
} }
/**
* {@inheritdoc}
*/
public function getDatabase(\Doctrine\DBAL\Connection $conn) public function getDatabase(\Doctrine\DBAL\Connection $conn)
{ {
$params = $conn->getParams(); $params = $conn->getParams();
......
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
namespace Doctrine\DBAL\Driver\Mysqli; 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> * @author Kim Hemsø Rasmussen <kimhemsoe@gmail.com>
*/ */
class MysqliConnection implements ConnectionInterface class MysqliConnection implements Connection
{ {
/** /**
* @var \mysqli * @var \mysqli
...@@ -43,11 +43,29 @@ class MysqliConnection implements ConnectionInterface ...@@ -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) public function prepare($prepareString)
{ {
return new MysqliStatement($this->_conn, $prepareString); return new MysqliStatement($this->_conn, $prepareString);
} }
/**
* {@inheritdoc}
*/
public function query() public function query()
{ {
$args = func_get_args(); $args = func_get_args();
...@@ -57,43 +75,67 @@ class MysqliConnection implements ConnectionInterface ...@@ -57,43 +75,67 @@ class MysqliConnection implements ConnectionInterface
return $stmt; return $stmt;
} }
/**
* {@inheritdoc}
*/
public function quote($input, $type=\PDO::PARAM_STR) public function quote($input, $type=\PDO::PARAM_STR)
{ {
return "'". $this->_conn->escape_string($input) ."'"; return "'". $this->_conn->escape_string($input) ."'";
} }
/**
* {@inheritdoc}
*/
public function exec($statement) public function exec($statement)
{ {
$this->_conn->query($statement); $this->_conn->query($statement);
return $this->_conn->affected_rows; return $this->_conn->affected_rows;
} }
/**
* {@inheritdoc}
*/
public function lastInsertId($name = null) public function lastInsertId($name = null)
{ {
return $this->_conn->insert_id; return $this->_conn->insert_id;
} }
/**
* {@inheritdoc}
*/
public function beginTransaction() public function beginTransaction()
{ {
$this->_conn->query('START TRANSACTION'); $this->_conn->query('START TRANSACTION');
return true; return true;
} }
/**
* {@inheritdoc}
*/
public function commit() public function commit()
{ {
return $this->_conn->commit(); return $this->_conn->commit();
} }
/**
* {@inheritdoc}non-PHPdoc)
*/
public function rollBack() public function rollBack()
{ {
return $this->_conn->rollback(); return $this->_conn->rollback();
} }
/**
* {@inheritdoc}
*/
public function errorCode() public function errorCode()
{ {
return $this->_conn->errno; return $this->_conn->errno;
} }
/**
* {@inheritdoc}
*/
public function errorInfo() public function errorInfo()
{ {
return $this->_conn->error; return $this->_conn->error;
......
...@@ -27,7 +27,7 @@ use PDO; ...@@ -27,7 +27,7 @@ use PDO;
*/ */
class MysqliStatement implements \IteratorAggregate, Statement class MysqliStatement implements \IteratorAggregate, Statement
{ {
private static $_paramTypeMap = array( protected static $_paramTypeMap = array(
PDO::PARAM_STR => 's', PDO::PARAM_STR => 's',
PDO::PARAM_BOOL => 'i', PDO::PARAM_BOOL => 'i',
PDO::PARAM_NULL => 's', PDO::PARAM_NULL => 's',
...@@ -35,32 +35,32 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -35,32 +35,32 @@ class MysqliStatement implements \IteratorAggregate, Statement
PDO::PARAM_LOB => 's' // TODO Support LOB bigger then max package size. PDO::PARAM_LOB => 's' // TODO Support LOB bigger then max package size.
); );
private $_conn; protected $_conn;
private $_stmt; protected $_stmt;
/** /**
* @var null|false|array * @var null|false|array
*/ */
private $_columnNames; protected $_columnNames;
/** /**
* @var null|array * @var null|array
*/ */
private $_rowBindedValues; protected $_rowBindedValues;
/** /**
* @var array * @var array
*/ */
private $_bindedValues; protected $_bindedValues;
/** /**
* Contains ref values for bindValue() * Contains ref values for bindValue()
* *
* @var array * @var array
*/ */
private $_values = array(); protected $_values = array();
private $_defaultFetchStyle = PDO::FETCH_BOTH; protected $_defaultFetchStyle = PDO::FETCH_BOTH;
public function __construct(\mysqli $conn, $prepareString) public function __construct(\mysqli $conn, $prepareString)
{ {
...@@ -73,7 +73,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -73,7 +73,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
$paramCount = $this->_stmt->param_count; $paramCount = $this->_stmt->param_count;
if (0 < $paramCount) { if (0 < $paramCount) {
// Index 0 is types // 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)); $bindedValues = array(0 => str_repeat('s', $paramCount));
$null = null; $null = null;
for ($i = 1; $i < $paramCount; $i++) { for ($i = 1; $i < $paramCount; $i++) {
...@@ -205,7 +205,7 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -205,7 +205,7 @@ class MysqliStatement implements \IteratorAggregate, Statement
if (true === $ret) { if (true === $ret) {
$values = array(); $values = array();
foreach ($this->_rowBindedValues as $v) { 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; $values[] = null === $v ? null : (string)$v;
} }
return $values; return $values;
...@@ -251,6 +251,8 @@ class MysqliStatement implements \IteratorAggregate, Statement ...@@ -251,6 +251,8 @@ class MysqliStatement implements \IteratorAggregate, Statement
*/ */
public function fetchAll($fetchStyle = null) public function fetchAll($fetchStyle = null)
{ {
$fetchStyle = $fetchStyle ?: $this->_defaultFetchStyle;
$a = array(); $a = array();
while (($row = $this->fetch($fetchStyle)) !== null) { while (($row = $this->fetch($fetchStyle)) !== null) {
$a[] = $row; $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