diff --git a/rdb/Connection.php b/rdb/Connection.php index dcfdf63..5d7519c 100644 --- a/rdb/Connection.php +++ b/rdb/Connection.php @@ -271,7 +271,6 @@ public function run(Query $query, $options = array(), &$profile = '') } else { return $this->createCursorFromResponse($response, $token, $response['n'], $toNativeOptions); } - } public function continueQuery($token) diff --git a/rdb/Cursor.php b/rdb/Cursor.php index 0445f96..e8000bd 100644 --- a/rdb/Cursor.php +++ b/rdb/Cursor.php @@ -17,6 +17,7 @@ class Cursor implements Iterator private $currentData; private $currentSize; private $currentIndex; + private $totalIndex = 0; private $isComplete; private $wasIterated; @@ -51,16 +52,19 @@ public function next() } $this->wasIterated = true; $this->currentIndex++; + $this->totalIndex++; } public function valid() { $this->requestMoreIfNecessary(); return !$this->isComplete || ($this->currentIndex < $this->currentSize); } + public function key() { - return null; + return $this->totalIndex; } + public function current() { $this->requestMoreIfNecessary(); @@ -87,13 +91,14 @@ public function close() $this->isComplete = true; } $this->currentIndex = 0; + $this->totalIndex = 0; $this->currentSize = 0; $this->currentData = array(); } public function bufferedCount() { - $this->currentSize - $this->currentIndex; + return $this->currentSize - $this->currentIndex; } public function getNotes() diff --git a/rdb/Datum/ObjectDatum.php b/rdb/Datum/ObjectDatum.php index 7e241ad..0d4b8c7 100644 --- a/rdb/Datum/ObjectDatum.php +++ b/rdb/Datum/ObjectDatum.php @@ -8,6 +8,16 @@ class ObjectDatum extends Datum { + protected $decimalPoint; + + public function __construct($value = null) + { + parent::__construct($value); + + $localeconv = localeconv(); + $this->decimalPoint = isset($localeconv['decimal_point']) ? $localeconv['decimal_point'] : '.'; + } + public function encodeServerRequest() { $jsonValue = $this->getValue(); @@ -70,10 +80,10 @@ public function toNative($opts) // This is really stupid. It looks like we can either use `date`, which ignores microseconds, // or we can use `createFromFormat` which cannot handle negative epoch times. if ($time < 0) { - $format = (strpos($time, '.') !== false) ? 'Y-m-d\TH:i:s.u' : 'Y-m-d\TH:i:s'; + $format = (strpos($time, $this->decimalPoint) !== false) ? 'Y-m-d\TH:i:s.u' : 'Y-m-d\TH:i:s'; $datetime = new \DateTime(date($format, $time) . $native['timezone'], new \DateTimeZone('UTC')); } else { - $format = (strpos($time, '.') !== false) ? '!U.u T' : '!U T'; + $format = (strpos($time, $this->decimalPoint) !== false) ? sprintf('!U%su T', $this->decimalPoint) : '!U T'; $datetime = \DateTime::createFromFormat($format, $time . " " . $native['timezone'], new \DateTimeZone('UTC')); } diff --git a/rdb/DatumConverter.php b/rdb/DatumConverter.php index 055e3a9..eb67ada 100644 --- a/rdb/DatumConverter.php +++ b/rdb/DatumConverter.php @@ -158,7 +158,6 @@ public function canEncodeAsJson($v) } return false; - } public function wrapImplicitVar(Query $q)