Skip to content

Commit

Permalink
#10 Adds close and reset
Browse files Browse the repository at this point in the history
  • Loading branch information
sbuberl committed Apr 20, 2019
1 parent 4552d6d commit b214ed6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
53 changes: 53 additions & 0 deletions tests/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b214ed6

Please sign in to comment.