From b214ed66400db73fe3561f6e099a31b5ee3f7dd6 Mon Sep 17 00:00:00 2001 From: sbuberl Date: Sat, 20 Apr 2019 17:37:46 -0400 Subject: [PATCH] #10 Adds close and reset --- src/Statement.php | 23 ++++++++++++++++++ tests/StatementTest.php | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) diff --git a/src/Statement.php b/src/Statement.php index 193820a..b0c306f 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -34,6 +34,29 @@ private function set_error($error) return false; } + public function close() + { + $this->query = null; + $this->params = null; + $this->result = null; + $this->metadata = null; + $this->types = null; + $this->boundParams = null; + $this->boundResults = null; + $this->stored = null; + $this->error = null; + return true; + } + + public function reset() + { + if($this->stored === false) { + $this->result = null; + } + $this->error = null; + return true; + } + public function data_seek($offset) { if($this->query === null) { diff --git a/tests/StatementTest.php b/tests/StatementTest.php index 7a8f453..05cebac 100644 --- a/tests/StatementTest.php +++ b/tests/StatementTest.php @@ -419,6 +419,59 @@ public function testDataSeek() $this->assertEquals($expected, $result->fetchRow()); } + public function testClose() + { + $table = CachedTable::create($this->fsql->current_schema(), 'customers', self::$columns); + $cursor = $table->getWriteCursor(); + foreach (self::$entries as $entry) { + $cursor->appendRow($entry); + } + $table->commit(); + + $statement = new Statement($this->fsql); + $statement->prepare("SELECT firstName, lastName, city FROM customers"); + $statement->execute(); + $statement->store_result(); + $passed = $statement->close(); + $expected = ['stephen', 'king', 'derry']; + $result = $statement->get_result(); + $this->assertTrue($passed === true); + } + + public function testResetStored() + { + $table = CachedTable::create($this->fsql->current_schema(), 'customers', self::$columns); + $cursor = $table->getWriteCursor(); + foreach (self::$entries as $entry) { + $cursor->appendRow($entry); + } + $table->commit(); + + $statement = new Statement($this->fsql); + $statement->prepare("SELECT firstName, lastName, city FROM customers"); + $statement->execute(); + $statement->store_result(); + $passed = $statement->reset(); + $this->assertTrue($passed === true); + } + + public function testResetNotStored() + { + $table = CachedTable::create($this->fsql->current_schema(), 'customers', self::$columns); + $cursor = $table->getWriteCursor(); + foreach (self::$entries as $entry) { + $cursor->appendRow($entry); + } + $table->commit(); + + $statement = new Statement($this->fsql); + $statement->prepare("SELECT firstName, lastName, city FROM customers"); + $statement->execute(); + $passed = $statement->reset(); + $this->assertTrue($passed === true); + } + + public function testNumRowsNoPrepare() { $statement = new Statement($this->fsql);