|
|
@@ -313,10 +313,19 @@ class ResultSet implements ResultSetInterface
|
|
|
*/
|
|
|
public function serialize()
|
|
|
{
|
|
|
+ if (!$this->_useBuffering) {
|
|
|
+ $msg = 'You cannot serialize an un-buffered ResultSet. Use Query::bufferResults() to get a buffered ResultSet.';
|
|
|
+ throw new Exception($msg);
|
|
|
+ }
|
|
|
+
|
|
|
while ($this->valid()) {
|
|
|
$this->next();
|
|
|
}
|
|
|
|
|
|
+ if ($this->_results instanceof SplFixedArray) {
|
|
|
+ return serialize($this->_results->toArray());
|
|
|
+ }
|
|
|
+
|
|
|
return serialize($this->_results);
|
|
|
}
|
|
|
|
|
|
@@ -330,9 +339,10 @@ class ResultSet implements ResultSetInterface
|
|
|
*/
|
|
|
public function unserialize($serialized)
|
|
|
{
|
|
|
- $this->_results = unserialize($serialized);
|
|
|
+ $results = (array)(unserialize($serialized) ?: []);
|
|
|
+ $this->_results = SplFixedArray::fromArray($results);
|
|
|
$this->_useBuffering = true;
|
|
|
- $this->_count = count($this->_results);
|
|
|
+ $this->_count = $this->_results->count();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -351,7 +361,13 @@ class ResultSet implements ResultSetInterface
|
|
|
return $this->_count = $this->_statement->rowCount();
|
|
|
}
|
|
|
|
|
|
- return $this->_count = count($this->_results);
|
|
|
+ if ($this->_results instanceof SplFixedArray) {
|
|
|
+ $this->_count = $this->_results->count();
|
|
|
+ } else {
|
|
|
+ $this->_count = count($this->_results);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $this->_count;
|
|
|
}
|
|
|
|
|
|
/**
|