Skip to content

Commit

Permalink
Using closeCursor in ConnectionTest, sqlite is very sad about open
Browse files Browse the repository at this point in the history
cursors
  • Loading branch information
lorenzo committed Mar 28, 2014
1 parent 456f0f2 commit 17f2e99
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/TestCase/Database/ConnectionTest.php
Expand Up @@ -158,6 +158,7 @@ public function testExecuteWithArguments() {
$statement = $this->connection->execute($sql, ['one' => 2, 'two' => 3], array('one' => 'integer', 'two' => 'integer'));
$this->assertCount(1, $statement);
$result = $statement->fetch('assoc');
$statement->closeCursor();
$this->assertEquals(['total' => 6], $result);
}

Expand All @@ -176,6 +177,7 @@ public function testExecuteWithArgumentsAndTypes() {
$params = [new \DateTime('2012-01-01 10:10:10'), '2000-01-01 10:10:10', 2.1];
$statement = $this->connection->execute($sql, $params, ['date', 'string', 'integer']);
$result = $statement->fetch();
$statement->closeCursor();
$this->assertEquals($result, array_filter($result));
}

Expand All @@ -199,6 +201,7 @@ public function testExecuteWithNoParams() {
$sql = 'SELECT 1';
$statement = $this->connection->execute($sql);
$result = $statement->fetch();
$statement->closeCursor();
$this->assertCount(1, $result);
$this->assertEquals([1], $result);
}
Expand Down Expand Up @@ -275,15 +278,17 @@ public function testStatementReusing() {
$this->_insertTwoRecords();

$total = $this->connection->execute('SELECT COUNT(*) AS total FROM things');
$total = $total->fetch('assoc');
$this->assertEquals(2, $total['total']);
$result = $total->fetch('assoc');
$this->assertEquals(2, $result['total']);
$total->closeCursor();

$result = $this->connection->execute('SELECT title, body FROM things');
$row = $result->fetch('assoc');
$this->assertEquals('a title', $row['title']);
$this->assertEquals('a body', $row['body']);

$row = $result->fetch('assoc');
$result->closeCursor();
$this->assertEquals('another title', $row['title']);
$this->assertEquals('another body', $row['body']);
}
Expand All @@ -300,6 +305,7 @@ public function testUpdateWithoutConditionsNorTypes() {
$this->connection->update('things', ['title' => $title, 'body' => $body]);
$result = $this->connection->execute('SELECT * FROM things WHERE title = ? AND body = ?', [$title, $body]);
$this->assertCount(2, $result);
$result->closeCursor();
}

/**
Expand All @@ -314,6 +320,7 @@ public function testUpdateWithConditionsNoTypes() {
$this->connection->update('things', ['title' => $title, 'body' => $body], ['id' => 2]);
$result = $this->connection->execute('SELECT * FROM things WHERE title = ? AND body = ?', [$title, $body]);
$this->assertCount(1, $result);
$result->closeCursor();
}

/**
Expand All @@ -328,6 +335,7 @@ public function testUpdateWithConditionsCombinedNoTypes() {
$this->connection->update('things', ['title' => $title, 'body' => $body], ['id' => 2, 'body is not null']);
$result = $this->connection->execute('SELECT * FROM things WHERE title = ? AND body = ?', [$title, $body]);
$this->assertCount(1, $result);
$result->closeCursor();
}

/**
Expand All @@ -347,6 +355,7 @@ public function testUpdateWithTypes() {
$this->assertEquals('2012-01-01', $row['body']);
$row = $result->fetch('assoc');
$this->assertEquals('2012-01-01', $row['body']);
$result->closeCursor();
}

/**
Expand All @@ -364,6 +373,7 @@ public function testUpdateWithConditionsAndTypes() {
$this->assertCount(1, $result);
$row = $result->fetch('assoc');
$this->assertEquals('2012-01-01', $row['body']);
$result->closeCursor();
}

/**
Expand Down

0 comments on commit 17f2e99

Please sign in to comment.