-
-
Notifications
You must be signed in to change notification settings - Fork 815
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #518 from briangreenery/master
Add support for sqlite3_interrupt
- Loading branch information
Showing
3 changed files
with
93 additions
and
0 deletions.
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
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,69 @@ | ||
var sqlite3 = require('..'); | ||
var assert = require('assert'); | ||
|
||
describe('interrupt', function() { | ||
it('should interrupt queries', function(done) { | ||
var query = | ||
'with t (n) as (values (1),(2),(3),(4),(5),(6),(7),(8)) ' + | ||
'select last.n ' + | ||
'from t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t,t as last'; | ||
|
||
var interrupted = false; | ||
var saved = null; | ||
|
||
var db = new sqlite3.Database(':memory:', function() { | ||
db.each(query, function(err) { | ||
if (!interrupted) { | ||
interrupted = true; | ||
db.interrupt(); | ||
} else if (err) { | ||
saved = err; | ||
} | ||
}); | ||
|
||
db.close(function() { | ||
if (saved) { | ||
assert.equal(saved.message, 'SQLITE_INTERRUPT: interrupted'); | ||
assert.equal(saved.errno, sqlite3.INTERRUPT); | ||
assert.equal(saved.code, 'SQLITE_INTERRUPT'); | ||
done(); | ||
} else { | ||
done(new Error('Completed query without error, but expected error')); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
it('should throw if interrupt is called before open', function(done) { | ||
var db = new sqlite3.Database(':memory:'); | ||
|
||
assert.throws(function() { | ||
db.interrupt(); | ||
}, (/Database is not open/)); | ||
|
||
db.close(); | ||
done(); | ||
}); | ||
|
||
it('should throw if interrupt is called after close', function(done) { | ||
var db = new sqlite3.Database(':memory:'); | ||
|
||
db.close(function() { | ||
assert.throws(function() { | ||
db.interrupt(); | ||
}, (/Database is not open/)); | ||
|
||
done(); | ||
}); | ||
}); | ||
|
||
it('should throw if interrupt is called during close', function(done) { | ||
var db = new sqlite3.Database(':memory:', function() { | ||
db.close(); | ||
assert.throws(function() { | ||
db.interrupt(); | ||
}, (/Database is closing/)); | ||
done(); | ||
}); | ||
}); | ||
}); |