Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
50 lines (43 loc) · 1.52 KB

File metadata and controls

50 lines (43 loc) · 1.52 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var sqlite3 = require('..');
var assert = require('assert');
describe('rerunning statements', function() {
var db;
before(function(done) { db = new sqlite3.Database(':memory:', done); });
var count = 10;
var inserted = 0;
var retrieved = 0;
it('should create the table', function(done) {
db.run("CREATE TABLE foo (id int)", done);
});
it('should insert repeatedly, reusing the same statement', function(done) {
var stmt = db.prepare("INSERT INTO foo VALUES(?)");
for (var i = 5; i < count; i++) {
stmt.run(i, function(err) {
if (err) throw err;
inserted++;
});
}
stmt.finalize(done);
});
it('should retrieve repeatedly, resuing the same statement', function(done) {
var collected = [];
var stmt = db.prepare("SELECT id FROM foo WHERE id = ?");
for (var i = 0; i < count; i++) {
stmt.get(i, function(err, row) {
if (err) throw err;
if (row) collected.push(row);
});
}
stmt.finalize(function(err) {
if (err) throw err;
retrieved += collected.length;
assert.deepEqual(collected, [ { id: 5 }, { id: 6 }, { id: 7 }, { id: 8 }, { id: 9 } ]);
done();
});
});
it('should have inserted and retrieved the right amount', function() {
assert.equal(inserted, 5);
assert.equal(retrieved, 5);
});
after(function(done) { db.close(done); });
});
Morty Proxy This is a proxified and sanitized view of the page, visit original site.