From 559558a530fc7d5832f099d934c105a67854260f Mon Sep 17 00:00:00 2001 From: Guillermo Pages Date: Mon, 13 Sep 2021 18:23:43 +0200 Subject: [PATCH] fix: Missing class OdbcResultSet --- src/Db/OdbcResultSet.php | 122 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/Db/OdbcResultSet.php diff --git a/src/Db/OdbcResultSet.php b/src/Db/OdbcResultSet.php new file mode 100644 index 0000000..5530321 --- /dev/null +++ b/src/Db/OdbcResultSet.php @@ -0,0 +1,122 @@ +results = $resultset; + $this->num_fields = is_array(current($resultset)) ? count(current($resultset)) : count($resultset); + $this->num_rows = count($this->results); + $this->length = $this->num_rows; + $this->cursor_index = 0; + } + + public function get_num_rows() + { + return $this->num_rows; + } + + public function count() { + return $this->get_num_rows(); + } + + public function is_error() + { + return ($this->error ? true : false); + } + + public function get_error() + { + return $this->error; + } + + public function get_row() + { + return $this->current(); + } + + public function to_array() + { + return $this->results; + } + + // ArrayAccess + /** + * @param int $offset + * @return bool + */ + public function offsetExists($offset) + { + return !$this->error && $this->cursor_index < $this->length && $this->cursor_index >= 0; + } + + /** + * @param int $offset + * @return bool|array + */ + public function offsetGet($offset) + { + return $this->offsetExists($offset) ? $this->results[$offset] : false; + } + + public function offsetSet($offset, $value) + { + if($this->offsetExists($offset)) { + $this->results[$offset] = $value; + } + } + + public function offsetUnset($offset) + { + throw new \RuntimeException("This makes no sense at all."); + } + + // Iterator + /** + * @return bool|array + */ + public function current() + { + return $this->offsetGet($this->cursor_index); + } + + /** + * @return int + */ + public function key() + { + return $this->cursor_index; + } + + /** + * @return array|bool + */ + public function next() + { + $current = $this->current(); + ++$this->cursor_index; + return $current; + } + + public function rewind() + { + $this->cursor_index = 0; + } + + /** + * @return bool + */ + public function valid() + { + return $this->offsetExists($this->cursor_index); + } +}