mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
Merge pull request #49 from kinglozzer/generators
Update SQLServerQuery to use generators
This commit is contained in:
commit
7be531dd7f
@ -43,13 +43,21 @@ class SQLServerQuery extends Query
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function seek($row)
|
public function getIterator()
|
||||||
{
|
{
|
||||||
if (!is_resource($this->handle)) {
|
if (is_resource($this->handle)) {
|
||||||
return false;
|
while ($data = sqlsrv_fetch_array($this->handle, SQLSRV_FETCH_ASSOC)) {
|
||||||
}
|
// special case for sqlsrv - date values are DateTime coming out of the sqlsrv drivers,
|
||||||
|
// so we convert to the usual Y-m-d H:i:s value!
|
||||||
|
foreach ($data as $name => $value) {
|
||||||
|
if ($value instanceof DateTime) {
|
||||||
|
$data[$name] = $value->format('Y-m-d H:i:s');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
user_error('MSSQLQuery::seek() not supported in sqlsrv', E_USER_WARNING);
|
yield $data;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function numRecords()
|
public function numRecords()
|
||||||
@ -65,28 +73,4 @@ class SQLServerQuery extends Query
|
|||||||
user_error('MSSQLQuery::numRecords() not supported in this version of sqlsrv', E_USER_WARNING);
|
user_error('MSSQLQuery::numRecords() not supported in this version of sqlsrv', E_USER_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function nextRecord()
|
|
||||||
{
|
|
||||||
if (!is_resource($this->handle)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($data = sqlsrv_fetch_array($this->handle, SQLSRV_FETCH_ASSOC)) {
|
|
||||||
// special case for sqlsrv - date values are DateTime coming out of the sqlsrv drivers,
|
|
||||||
// so we convert to the usual Y-m-d H:i:s value!
|
|
||||||
foreach ($data as $name => $value) {
|
|
||||||
if ($value instanceof DateTime) {
|
|
||||||
$data[$name] = $value->format('Y-m-d H:i:s');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
} else {
|
|
||||||
// Free the handle if there are no more results - sqlsrv crashes if there are too many handles
|
|
||||||
sqlsrv_free_stmt($this->handle);
|
|
||||||
$this->handle = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user