Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/node_sqlite3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ NAN_MODULE_INIT(RegisterModule) {
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_READWRITE, OPEN_READWRITE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_CREATE, OPEN_CREATE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_FULLMUTEX, OPEN_FULLMUTEX);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_URI, OPEN_URI);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_SHAREDCACHE, OPEN_SHAREDCACHE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_PRIVATECACHE, OPEN_PRIVATECACHE);
DEFINE_CONSTANT_STRING(target, SQLITE_VERSION, VERSION);
#ifdef SQLITE_SOURCE_ID
DEFINE_CONSTANT_STRING(target, SQLITE_SOURCE_ID, SOURCE_ID);
Expand Down
3 changes: 3 additions & 0 deletions test/constants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ describe('constants', function() {
assert.ok(sqlite3.OPEN_READONLY === 1);
assert.ok(sqlite3.OPEN_READWRITE === 2);
assert.ok(sqlite3.OPEN_CREATE === 4);
assert.ok(sqlite3.OPEN_URI === 0x00000040);
assert.ok(sqlite3.OPEN_FULLMUTEX === 0x00010000);
assert.ok(sqlite3.OPEN_SHAREDCACHE === 0x00020000);
assert.ok(sqlite3.OPEN_PRIVATECACHE === 0x00040000);
});

it('should have the right error flags', function() {
Expand Down
58 changes: 58 additions & 0 deletions test/open_close.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,64 @@ describe('open/close', function() {
helper.deleteFile('test/tmp/test_create.db');
});
});

describe('open and close non-existant shared database', function() {
before(function() {
helper.deleteFile('test/tmp/test_create_shared.db');
});

var db;
it('should open the database', function(done) {
db = new sqlite3.Database('file:./test/tmp/test_create_shared.db', sqlite3.OPEN_URI | sqlite3.OPEN_SHAREDCACHE | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, done);
});

it('should close the database', function(done) {
db.close(done);
});

it('should have created the file', function() {
assert.fileExists('test/tmp/test_create_shared.db');
});

after(function() {
helper.deleteFile('test/tmp/test_create_shared.db');
});
});


(sqlite3.VERSION_NUMBER < 3008000 ? describe.skip : describe)('open and close shared memory database', function() {

var db1;
var db2;

it('should open the first database', function(done) {
db1 = new sqlite3.Database('file:./test/tmp/test_memory.db?mode=memory', sqlite3.OPEN_URI | sqlite3.OPEN_SHAREDCACHE | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, done);
});

it('should open the second database', function(done) {
db2 = new sqlite3.Database('file:./test/tmp/test_memory.db?mode=memory', sqlite3.OPEN_URI | sqlite3.OPEN_SHAREDCACHE | sqlite3.OPEN_READWRITE | sqlite3.OPEN_CREATE, done);
});

it('first database should set the user_version', function(done) {
db1.exec('PRAGMA user_version=42', done);
});

it('second database should get the user_version', function(done) {
db2.get('PRAGMA user_version', function(err, row) {
if (err) throw err;
assert.equal(row.user_version, 42);
done();
});
});

it('should close the first database', function(done) {
db1.close(done);
});

it('should close the second database', function(done) {
db2.close(done);
});
});

it('should not be unable to open an inaccessible database', function(done) {
// NOTE: test assumes that the user is not allowed to create new files
Expand Down