Skip to content

Commit e1f91b4

Browse files
committed
Merge pull request #26 from hranicka/hotfix/sqlitejournal-bug
tests: SQLiteJournal 'Too many variables' bug test added [Ref #25]
2 parents 4649143 + 080568d commit e1f91b4

File tree

4 files changed

+50
-5
lines changed

4 files changed

+50
-5
lines changed

src/Caching/Storages/SQLiteJournal.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,17 @@ public function clean(array $conditions)
116116
return [];
117117
}
118118

119-
$stmt = $this->pdo->prepare(implode(' UNION ', $unions));
119+
$unionSql = implode(' UNION ', $unions);
120+
$stmt = $this->pdo->prepare($unionSql);
120121
$stmt->execute($args);
121122
$keys = $stmt->fetchAll(\PDO::FETCH_COLUMN, 0);
122123
if (empty($keys)) {
123124
return [];
124125
}
125126

126-
$in = '(?' . str_repeat(', ?', count($keys) - 1) . ')';
127127
$this->pdo->exec('BEGIN');
128-
$this->pdo->prepare("DELETE FROM tags WHERE key IN $in")->execute($keys);
129-
$this->pdo->prepare("DELETE FROM priorities WHERE key IN $in")->execute($keys);
128+
$this->pdo->prepare("DELETE FROM tags WHERE key IN ($unionSql)")->execute($args);
129+
$this->pdo->prepare("DELETE FROM priorities WHERE key IN ($unionSql)")->execute($args);
130130
$this->pdo->exec('COMMIT');
131131

132132
return $keys;

tests/Caching/SQLiteJournal.phpt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class SQLiteJournalTest extends IJournalTestCase
2121

2222
public function createJournal()
2323
{
24-
return new SQLiteJournal;
24+
static $id = 0;
25+
return new SQLiteJournal(TEMP_DIR . '/sqlitejournal_' . ++$id . '.sqlite');
2526
}
2627

2728
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Caching\Storages\SQLiteStorage tags dependency test.
5+
*/
6+
7+
use Nette\Caching\Cache;
8+
use Nette\Caching\Storages\SQLiteJournal;
9+
use Tester\Assert;
10+
11+
12+
require __DIR__ . '/../../bootstrap.php';
13+
14+
15+
if (!extension_loaded('pdo_sqlite')) {
16+
Tester\Environment::skip('Requires PHP extension pdo_sqlite.');
17+
}
18+
19+
20+
$journal = new SQLiteJournal;
21+
22+
// Writing cache...
23+
$keys = [];
24+
for ($i = 0; $i < 2000; $i++) {
25+
$keys[] = 'key' . $i;
26+
}
27+
28+
foreach ($keys as $key) {
29+
$journal->write($key, [
30+
Cache::TAGS => ['one', 'two'],
31+
]);
32+
}
33+
34+
$journal->write('keyThree', [
35+
Cache::TAGS => ['three'],
36+
]);
37+
38+
// Cleaning by tags...
39+
$keys = $journal->clean([
40+
Cache::TAGS => ['one', 'xx'],
41+
]);
42+
43+
Assert::same($keys, $keys);

tests/php-win.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[PHP]
22
extension_dir = "./ext"
33
extension=php_mbstring.dll
4+
extension=php_pdo_sqlite.dll
45
;extension=php_memcache.dll
56

67
[Zend]

0 commit comments

Comments
 (0)