Unverified Commit a8c34ea4 by Kewde Committed by GitHub

Merge pull request #1078 from gms1/add-open-flags

fix #1032: add constants for file open
parents 5bb0dc0e 802afaf2
...@@ -22,6 +22,9 @@ NAN_MODULE_INIT(RegisterModule) { ...@@ -22,6 +22,9 @@ NAN_MODULE_INIT(RegisterModule) {
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_READWRITE, OPEN_READWRITE); DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_READWRITE, OPEN_READWRITE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_CREATE, OPEN_CREATE); DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_CREATE, OPEN_CREATE);
DEFINE_CONSTANT_INTEGER(target, SQLITE_OPEN_FULLMUTEX, OPEN_FULLMUTEX); 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); DEFINE_CONSTANT_STRING(target, SQLITE_VERSION, VERSION);
#ifdef SQLITE_SOURCE_ID #ifdef SQLITE_SOURCE_ID
DEFINE_CONSTANT_STRING(target, SQLITE_SOURCE_ID, SOURCE_ID); DEFINE_CONSTANT_STRING(target, SQLITE_SOURCE_ID, SOURCE_ID);
......
...@@ -6,7 +6,10 @@ describe('constants', function() { ...@@ -6,7 +6,10 @@ describe('constants', function() {
assert.ok(sqlite3.OPEN_READONLY === 1); assert.ok(sqlite3.OPEN_READONLY === 1);
assert.ok(sqlite3.OPEN_READWRITE === 2); assert.ok(sqlite3.OPEN_READWRITE === 2);
assert.ok(sqlite3.OPEN_CREATE === 4); assert.ok(sqlite3.OPEN_CREATE === 4);
assert.ok(sqlite3.OPEN_URI === 0x00000040);
assert.ok(sqlite3.OPEN_FULLMUTEX === 0x00010000); 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() { it('should have the right error flags', function() {
......
...@@ -30,6 +30,64 @@ describe('open/close', function() { ...@@ -30,6 +30,64 @@ describe('open/close', function() {
helper.deleteFile('test/tmp/test_create.db'); 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) { 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 // NOTE: test assumes that the user is not allowed to create new files
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment