mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 15:05:37 +00:00
Counting should not interfere with iterator
This commit is contained in:
parent
2e61981c95
commit
2a85e21e35
@ -26,6 +26,8 @@ class SQLite3Query extends Query
|
|||||||
*/
|
*/
|
||||||
protected $handle;
|
protected $handle;
|
||||||
|
|
||||||
|
protected int $count = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hook the result-set given into a Query class, suitable for use by framework.
|
* Hook the result-set given into a Query class, suitable for use by framework.
|
||||||
* @param SQLite3Connector $database The database object that created this query.
|
* @param SQLite3Connector $database The database object that created this query.
|
||||||
@ -35,6 +37,8 @@ class SQLite3Query extends Query
|
|||||||
{
|
{
|
||||||
$this->database = $database;
|
$this->database = $database;
|
||||||
$this->handle = $handle;
|
$this->handle = $handle;
|
||||||
|
// Count early to make sure we don't interfere with the generator and rewind operation
|
||||||
|
$this->count = $this->countRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __destruct()
|
public function __destruct()
|
||||||
@ -44,10 +48,15 @@ class SQLite3Query extends Query
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function numRecords()
|
||||||
|
{
|
||||||
|
return $this->count;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @todo This looks terrible but there is no SQLite3::get_num_rows() implementation
|
* @todo This looks terrible but there is no SQLite3::get_num_rows() implementation
|
||||||
*/
|
*/
|
||||||
public function numRecords()
|
private function countRecords()
|
||||||
{
|
{
|
||||||
// Some queries are not iterable using fetchArray like CREATE statement
|
// Some queries are not iterable using fetchArray like CREATE statement
|
||||||
if (!$this->handle->numColumns()) {
|
if (!$this->handle->numColumns()) {
|
||||||
@ -55,7 +64,7 @@ class SQLite3Query extends Query
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->handle->reset();
|
$this->handle->reset();
|
||||||
$c=0;
|
$c = 0;
|
||||||
while ($this->handle->fetchArray()) {
|
while ($this->handle->fetchArray()) {
|
||||||
$c++;
|
$c++;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user