mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
BUGFIX: numRecords not supported on sqlsrv, need to count manually
This commit is contained in:
parent
2b5f25455f
commit
27b44a3722
@ -1277,21 +1277,18 @@ class MSSQLDatabase extends SS_Database {
|
|||||||
// Perform the search
|
// Perform the search
|
||||||
$result = DB::query($fullQuery);
|
$result = DB::query($fullQuery);
|
||||||
|
|
||||||
// Regenerate DataObjectSet
|
// Regenerate DataObjectSet - watch out, numRecords doesn't work on sqlsrv driver on Windows.
|
||||||
$totalCount = $result->numRecords();
|
|
||||||
$current = -1;
|
$current = -1;
|
||||||
$results = new DataObjectSet();
|
$results = new DataObjectSet();
|
||||||
foreach ($result as $row) {
|
foreach ($result as $row) {
|
||||||
$current++;
|
$current++;
|
||||||
|
|
||||||
// Select a subset for paging
|
// Select a subset for paging
|
||||||
if ($current>=$start+$pageLength) break;
|
if ($current>=$start && $current<$start+$pageLength) {
|
||||||
if ($current<$start) continue;
|
$results->push(DataObject::get_by_id($row['Source'], $row['ID']));
|
||||||
|
}
|
||||||
$results->push(DataObject::get_by_id($row['Source'], $row['ID']));
|
|
||||||
}
|
}
|
||||||
|
$results->setPageLimits($start, $pageLength, $current+1);
|
||||||
$results->setPageLimits($start, $pageLength, $totalCount);
|
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
@ -1644,6 +1641,8 @@ class MSSQLQuery extends SS_Query {
|
|||||||
// WARNING: This will only work if the cursor type is NOT forward only!
|
// WARNING: This will only work if the cursor type is NOT forward only!
|
||||||
if(function_exists('sqlsrv_num_rows')) {
|
if(function_exists('sqlsrv_num_rows')) {
|
||||||
return sqlsrv_num_rows($this->handle);
|
return sqlsrv_num_rows($this->handle);
|
||||||
|
} else {
|
||||||
|
user_error("MSSQLQuery::numRecords() not supported on this version of sqlsrv.", E_USER_WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user