Commit ab9f8160 authored by Steve Müller's avatar Steve Müller

fix sqlsrv driver functional test suite

parent 7bcfaba6
...@@ -70,6 +70,20 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -70,6 +70,20 @@ class SQLSrvStatement implements IteratorAggregate, Statement
PDO::FETCH_NUM => SQLSRV_FETCH_NUMERIC, PDO::FETCH_NUM => SQLSRV_FETCH_NUMERIC,
); );
/**
* The name of the default class to instantiate when fetch mode is \PDO::FETCH_CLASS.
*
* @var string
*/
private $defaultFetchClass = '\stdClass';
/**
* The constructor arguments for the default class to instantiate when fetch mode is \PDO::FETCH_CLASS.
*
* @var string
*/
private $defaultFetchClassCtorArgs = array();
/** /**
* The fetch style. * The fetch style.
* *
...@@ -201,6 +215,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -201,6 +215,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{ {
$this->defaultFetchMode = $fetchMode; $this->defaultFetchMode = $fetchMode;
$this->defaultFetchClass = $arg2 ?: $this->defaultFetchClass;
$this->defaultFetchClassCtorArgs = $arg3 ? (array) $arg3 : $this->defaultFetchClassCtorArgs;
return true; return true;
} }
...@@ -225,8 +241,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -225,8 +241,8 @@ class SQLSrvStatement implements IteratorAggregate, Statement
if (isset(self::$fetchMap[$fetchMode])) { if (isset(self::$fetchMap[$fetchMode])) {
return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]); return sqlsrv_fetch_array($this->stmt, self::$fetchMap[$fetchMode]);
} elseif ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) { } elseif ($fetchMode == PDO::FETCH_OBJ || $fetchMode == PDO::FETCH_CLASS) {
$className = null; $className = $this->defaultFetchClass;
$ctorArgs = null; $ctorArgs = $this->defaultFetchClassCtorArgs;
if (count($args) >= 2) { if (count($args) >= 2) {
$className = $args[1]; $className = $args[1];
$ctorArgs = (isset($args[2])) ? $args[2] : array(); $ctorArgs = (isset($args[2])) ? $args[2] : array();
...@@ -242,18 +258,24 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -242,18 +258,24 @@ class SQLSrvStatement implements IteratorAggregate, Statement
*/ */
public function fetchAll($fetchMode = null) public function fetchAll($fetchMode = null)
{ {
$className = null;
$ctorArgs = null;
if (func_num_args() >= 2) {
$args = func_get_args();
$className = $args[1];
$ctorArgs = (isset($args[2])) ? $args[2] : array();
}
$rows = array(); $rows = array();
while ($row = $this->fetch($fetchMode, $className, $ctorArgs)) {
switch ($fetchMode) {
case PDO::FETCH_CLASS:
while ($row = call_user_func_array(array($this, 'fetch'), func_get_args())) {
$rows[] = $row;
}
break;
case PDO::FETCH_COLUMN:
while ($row = $this->fetchColumn()) {
$rows[] = $row; $rows[] = $row;
} }
break;
default:
while ($row = $this->fetch($fetchMode)) {
$rows[] = $row;
}
}
return $rows; return $rows;
} }
...@@ -265,9 +287,13 @@ class SQLSrvStatement implements IteratorAggregate, Statement ...@@ -265,9 +287,13 @@ class SQLSrvStatement implements IteratorAggregate, Statement
{ {
$row = $this->fetch(PDO::FETCH_NUM); $row = $this->fetch(PDO::FETCH_NUM);
if ($row && isset($row[$columnIndex])) {
return $row[$columnIndex]; return $row[$columnIndex];
} }
return false;
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -212,7 +212,8 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -212,7 +212,8 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/ */
public function testFetchAllWithMissingTypes() public function testFetchAllWithMissingTypes()
{ {
if ($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver) { if ($this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\Mysqli\Driver ||
$this->_conn->getDriver() instanceof \Doctrine\DBAL\Driver\SQLSrv\Driver) {
$this->markTestSkipped('mysqli actually supports this'); $this->markTestSkipped('mysqli actually supports this');
} }
......
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