diff --git a/src/node_sqlite3.cc b/src/node_sqlite3.cc index 64326f784..9c3007005 100644 --- a/src/node_sqlite3.cc +++ b/src/node_sqlite3.cc @@ -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); diff --git a/test/constants.test.js b/test/constants.test.js index fc9ebf4d7..7e1affdda 100644 --- a/test/constants.test.js +++ b/test/constants.test.js @@ -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() { diff --git a/test/open_close.test.js b/test/open_close.test.js index 649e21789..49d2af791 100644 --- a/test/open_close.test.js +++ b/test/open_close.test.js @@ -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