-
Notifications
You must be signed in to change notification settings - Fork 664
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid caching dirty data to fix #2027
- Loading branch information
1 parent
0dd3a6f
commit a4c1a42
Showing
2 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const alasql = require('../dist/alasql.js'); | ||
|
||
if (typeof exports === 'object') { | ||
var assert = require('assert'); | ||
} | ||
|
||
describe('Test 2007 - SQL cache', function () { | ||
before(function () { | ||
alasql('create database test'); | ||
alasql('use test'); | ||
}); | ||
|
||
after(function () { | ||
alasql('drop database test'); | ||
}); | ||
|
||
it('A) Execute query and assert cache for `data` afterwards', () => { | ||
alasql('CREATE TABLE osoby (id INT, meno STRING)'); | ||
alasql('INSERT INTO osoby VALUES (1, "John"), (2, "Jane"), (3, "Jake")'); | ||
var res = alasql('SELECT * FROM osoby'); | ||
|
||
assert.deepEqual(alasql.databases["test"].sqlCache["-169125189"].query.data, []); | ||
assert.equal(res.length, 3); | ||
|
||
// Delete all rows | ||
alasql('DELETE FROM osoby'); | ||
|
||
// Assert that the cache is still empty for "data" | ||
// Without the fix, the cache would still contain the data from the previous query even though all rows were deleted | ||
assert.deepEqual(alasql.databases["test"].sqlCache["-169125189"].query.data, []); | ||
|
||
// Insert more rows | ||
alasql('INSERT INTO osoby VALUES (4, "Jack"), (5, "Paul")'); | ||
|
||
// Execute same query from cache again, the cache is hit now | ||
var res2 = alasql('SELECT * FROM osoby'); | ||
|
||
// Cache should still be empty for "data" | ||
assert.deepEqual(alasql.databases["test"].sqlCache["-169125189"].query.data, []); | ||
assert.equal(res2.length, 2); | ||
}); | ||
}); |