Compare commits

...

11 Commits

Author SHA1 Message Date
Fedor Indutnyy
e1f73c0738 Try building without prebuilt OpenSSL 2022-03-29 09:16:20 -07:00
Fedor Indutnyy
4f66ee7b85 Update sqlcipher to 4.5.1 2022-03-04 09:38:50 -08:00
Fedor Indutnyy
92ed9e3635 Test munlock fix in sqlcipher 2021-11-08 21:53:00 +01:00
Fedor Indutnyy
9de3488f68 Update sqlcipher to 4.5.0 2021-11-01 14:23:28 -07:00
Jan Alexander Steffens
917a6f5cf8 Encapsulate the internal SQLite
Add linker flags to
 - prevent the dynamic linker from using an external SQLite for this
   library (`-Bsymbolic`) and
 - prevent the dynamic linker from using the internal SQLite for other
   libraries (`--exclude-libs ALL`).
2021-10-27 11:07:40 -07:00
Fedor Indutnyy
32828e03be Log corruption error information 2021-10-21 12:38:38 -07:00
Fedor Indutny
2fa02d2484 deps: fix build errors with xcode
clang shipped with XCode tries to include `VERSION` file from the
deps/sqlite3.tar.gz. Rename the file to `VERSION.txt` to address that.
2021-04-27 11:48:18 -07:00
Fedor Indutny
a78376d86b gyp: further windows fix 2021-04-05 14:09:45 -07:00
Fedor Indutny
86b685e046 gyp: fix windows 2021-04-05 14:05:35 -07:00
Fedor Indutny
a78e94135c package: no prebuilds for us 2021-04-05 13:45:57 -07:00
Fedor Indutny
5acdaf9d03 sqlcipher support 2021-04-02 16:47:41 -07:00
10 changed files with 83 additions and 48 deletions

1
.gitattributes vendored
View File

@ -1 +1,2 @@
*.lzz linguist-language=C++ *.lzz linguist-language=C++
deps/sqlite3.tar.gz filter=lfs diff=lfs merge=lfs -text

View File

@ -13,6 +13,14 @@
'xcode_settings': { 'xcode_settings': {
'OTHER_CPLUSPLUSFLAGS': ['-std=c++14', '-stdlib=libc++'], 'OTHER_CPLUSPLUSFLAGS': ['-std=c++14', '-stdlib=libc++'],
}, },
'conditions': [
['OS=="linux"', {
'ldflags': [
'-Wl,-Bsymbolic',
'-Wl,--exclude-libs,ALL',
],
}],
],
}, },
{ {
'target_name': 'test_extension', 'target_name': 'test_extension',

5
deps/common.gypi vendored
View File

@ -12,11 +12,6 @@
'ExceptionHandling': 1, 'ExceptionHandling': 1,
}, },
}, },
'conditions': [
['OS == "win"', {
'defines': ['WIN32'],
}],
],
'configurations': { 'configurations': {
'Debug': { 'Debug': {
'defines!': [ 'defines!': [

11
deps/defines.gypi vendored
View File

@ -2,7 +2,6 @@
{ {
'defines': [ 'defines': [
'SQLITE_DQS=0',
'SQLITE_LIKE_DOESNT_MATCH_BLOBS', 'SQLITE_LIKE_DOESNT_MATCH_BLOBS',
'SQLITE_THREADSAFE=2', 'SQLITE_THREADSAFE=2',
'SQLITE_USE_URI=0', 'SQLITE_USE_URI=0',
@ -19,14 +18,14 @@
'SQLITE_ENABLE_COLUMN_METADATA', 'SQLITE_ENABLE_COLUMN_METADATA',
'SQLITE_ENABLE_UPDATE_DELETE_LIMIT', 'SQLITE_ENABLE_UPDATE_DELETE_LIMIT',
'SQLITE_ENABLE_STAT4', 'SQLITE_ENABLE_STAT4',
'SQLITE_ENABLE_FTS3_PARENTHESIS',
'SQLITE_ENABLE_FTS3',
'SQLITE_ENABLE_FTS4',
'SQLITE_ENABLE_FTS5', 'SQLITE_ENABLE_FTS5',
'SQLITE_ENABLE_JSON1', 'SQLITE_ENABLE_JSON1',
'SQLITE_ENABLE_RTREE', 'SQLITE_ENABLE_RTREE',
'SQLITE_ENABLE_GEOPOLY',
'SQLITE_INTROSPECTION_PRAGMAS', 'SQLITE_INTROSPECTION_PRAGMAS',
'SQLITE_SOUNDEX',
# SQLCipher-specific options
'SQLITE_HAS_CODEC',
'SQLITE_TEMP_STORE=2',
'SQLITE_SECURE_DELETE',
], ],
} }

56
deps/sqlite3.gyp vendored
View File

@ -12,54 +12,42 @@
'target_name': 'locate_sqlite3', 'target_name': 'locate_sqlite3',
'type': 'none', 'type': 'none',
'hard_dependency': 1, 'hard_dependency': 1,
'conditions': [ 'actions': [{
['sqlite3 == ""', { 'action_name': 'extract_sqlite3',
'actions': [{ 'inputs': ['sqlite3.tar.gz'],
'action_name': 'extract_sqlite3', 'outputs': [
'inputs': ['sqlite3.tar.gz'], '<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c',
'outputs': [ '<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.h',
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c', '<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3ext.h',
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.h', ],
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3ext.h', 'action': ['node', 'extract.js', '<(SHARED_INTERMEDIATE_DIR)/sqlite3'],
], }],
'action': ['node', 'extract.js', '<(SHARED_INTERMEDIATE_DIR)/sqlite3'],
}],
}, {
'actions': [{
'action_name': 'symlink_sqlite3',
'inputs': [],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c',
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.h',
],
'action': ['node', 'symlink.js', '<(SHARED_INTERMEDIATE_DIR)/sqlite3', '<(sqlite3)'],
}],
}],
],
}, },
{ {
'target_name': 'sqlite3', 'target_name': 'sqlite3',
'type': 'static_library', 'type': 'static_library',
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/',
],
'direct_dependent_settings': {
'include_dirs': [
'<(SHARED_INTERMEDIATE_DIR)/sqlite3/',
],
},
'dependencies': ['locate_sqlite3'], 'dependencies': ['locate_sqlite3'],
'sources': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c'], 'sources': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/sqlite3.c'],
'include_dirs': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/'],
'direct_dependent_settings': {
'include_dirs': ['<(SHARED_INTERMEDIATE_DIR)/sqlite3/'],
},
'cflags': ['-std=c99', '-w'], 'cflags': ['-std=c99', '-w'],
'xcode_settings': { 'xcode_settings': {
'OTHER_CFLAGS': ['-std=c99'], 'OTHER_CFLAGS': ['-std=c99'],
'WARNING_CFLAGS': ['-w'], 'WARNING_CFLAGS': ['-w'],
}, },
'includes': ['defines.gypi'],
'conditions': [ 'conditions': [
['sqlite3 == ""', { ['OS == "win"', {
'includes': ['defines.gypi'],
}, {
'defines': [ 'defines': [
# This is currently required by better-sqlite3. 'WIN32'
'SQLITE_ENABLE_COLUMN_METADATA',
], ],
}] }],
], ],
'configurations': { 'configurations': {
'Debug': { 'Debug': {

BIN
deps/sqlite3.tar.gz vendored

Binary file not shown.

View File

@ -6,6 +6,7 @@ const util = require('./util');
const { const {
Database: CPPDatabase, Database: CPPDatabase,
setErrorConstructor, setErrorConstructor,
setCorruptionLogger,
} = require('bindings')('better_sqlite3.node'); } = require('bindings')('better_sqlite3.node');
function Database(filenameGiven, options) { function Database(filenameGiven, options) {
@ -61,6 +62,7 @@ Database.prototype.close = wrappers.close;
Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers; Database.prototype.defaultSafeIntegers = wrappers.defaultSafeIntegers;
Database.prototype.unsafeMode = wrappers.unsafeMode; Database.prototype.unsafeMode = wrappers.unsafeMode;
Database.prototype[util.inspect] = require('./methods/inspect'); Database.prototype[util.inspect] = require('./methods/inspect');
Database.setCorruptionLogger = setCorruptionLogger;
module.exports = Database; module.exports = Database;
setErrorConstructor(require('./sqlite-error')); setErrorConstructor(require('./sqlite-error'));

View File

@ -11,7 +11,6 @@
}, },
"dependencies": { "dependencies": {
"bindings": "^1.5.0", "bindings": "^1.5.0",
"prebuild-install": "^6.0.1",
"tar": "^6.1.0" "tar": "^6.1.0"
}, },
"devDependencies": { "devDependencies": {
@ -20,12 +19,11 @@
"fs-extra": "^9.1.0", "fs-extra": "^9.1.0",
"mocha": "^8.3.2", "mocha": "^8.3.2",
"nodemark": "^0.3.0", "nodemark": "^0.3.0",
"prebuild": "^10.0.1",
"sqlite": "^4.0.19", "sqlite": "^4.0.19",
"sqlite3": "^5.0.2" "sqlite3": "^5.0.2"
}, },
"scripts": { "scripts": {
"install": "prebuild-install || npm run build-release", "install": "npm run build-release",
"build-release": "node-gyp rebuild --release", "build-release": "node-gyp rebuild --release",
"build-debug": "node-gyp rebuild --debug", "build-debug": "node-gyp rebuild --debug",
"rebuild-release": "npm run lzz && npm run build-release", "rebuild-release": "npm run lzz && npm run build-release",

View File

@ -18,6 +18,7 @@ NODE_MODULE_INIT(/* exports, context */) {
exports->Set(context, InternalizedFromLatin1(isolate, "StatementIterator"), StatementIterator::Init(isolate, data)).FromJust(); exports->Set(context, InternalizedFromLatin1(isolate, "StatementIterator"), StatementIterator::Init(isolate, data)).FromJust();
exports->Set(context, InternalizedFromLatin1(isolate, "Backup"), Backup::Init(isolate, data)).FromJust(); exports->Set(context, InternalizedFromLatin1(isolate, "Backup"), Backup::Init(isolate, data)).FromJust();
exports->Set(context, InternalizedFromLatin1(isolate, "setErrorConstructor"), v8::FunctionTemplate::New(isolate, Addon::JS_setErrorConstructor, data)->GetFunction(context).ToLocalChecked()).FromJust(); exports->Set(context, InternalizedFromLatin1(isolate, "setErrorConstructor"), v8::FunctionTemplate::New(isolate, Addon::JS_setErrorConstructor, data)->GetFunction(context).ToLocalChecked()).FromJust();
exports->Set(context, InternalizedFromLatin1(isolate, "setCorruptionLogger"), v8::FunctionTemplate::New(isolate, Addon::JS_setCorruptionLogger, data)->GetFunction(context).ToLocalChecked()).FromJust();
// Store addon instance data. // Store addon instance data.
addon->Statement.Reset(isolate, v8::Local<v8::Function>::Cast(exports->Get(context, InternalizedFromLatin1(isolate, "Statement")).ToLocalChecked())); addon->Statement.Reset(isolate, v8::Local<v8::Function>::Cast(exports->Get(context, InternalizedFromLatin1(isolate, "Statement")).ToLocalChecked()));
@ -1669,6 +1670,48 @@ void Addon::JS_setErrorConstructor (v8::FunctionCallbackInfo <v8 :: Value> const
if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" ) ; v8 :: Local < v8 :: Function > SqliteError = v8 :: Local < v8 :: Function > :: Cast ( info [ 0 ] ) ; if ( info . Length ( ) <= ( 0 ) || ! info [ 0 ] -> IsFunction ( ) ) return ThrowTypeError ( "Expected " "first" " argument to be " "a function" ) ; v8 :: Local < v8 :: Function > SqliteError = v8 :: Local < v8 :: Function > :: Cast ( info [ 0 ] ) ;
static_cast < Addon * > ( v8 :: Local < v8 :: External > :: Cast ( info . Data ( ) ) -> Value ( ) ) ->SqliteError.Reset( info . GetIsolate ( ) , SqliteError); static_cast < Addon * > ( v8 :: Local < v8 :: External > :: Cast ( info . Data ( ) ) -> Value ( ) ) ->SqliteError.Reset( info . GetIsolate ( ) , SqliteError);
} }
class LogWrapper {
public:
LogWrapper(
v8::Isolate* isolate,
v8::Local<v8::Function> fn
): isolate_(isolate) {
fn_.Reset(isolate, fn);
}
void Call(const char* msg) {
v8::HandleScope scope(isolate_);
v8::Local<v8::Function> fn =
v8::Local<v8::Function>::New(isolate_, fn_);
v8::Local<v8::Value> arg = StringFromUtf8(isolate_, msg, -1);
fn->Call(isolate_->GetCurrentContext(), v8::Undefined(isolate_), 1, &arg);
}
static void Fn(void *pArg, int iErrCode, const char *zMsg) {
LogWrapper* wrapper = reinterpret_cast<LogWrapper*>(pArg);
if (iErrCode == SQLITE_CORRUPT || iErrCode == SQLITE_NOTADB) {
wrapper->Call(zMsg);
}
}
private:
v8::Isolate* isolate_;
v8::Persistent<v8::Function> fn_;
};
void Addon::JS_setCorruptionLogger (v8::FunctionCallbackInfo <v8 :: Value> const & info) {
if (info.Length() <= 0)
return ThrowTypeError("Expected one argument");
v8::Local<v8::Function> fn = v8::Local<v8::Function>::Cast(info[0]);
int status = sqlite3_config(
SQLITE_CONFIG_LOG,
LogWrapper::Fn,
new LogWrapper(v8::Isolate::GetCurrent(), fn));
assert(status == SQLITE_OK);
}
#line 48 "./src/better_sqlite3.lzz" #line 48 "./src/better_sqlite3.lzz"
void Addon::Cleanup (void * ptr) void Addon::Cleanup (void * ptr)
#line 48 "./src/better_sqlite3.lzz" #line 48 "./src/better_sqlite3.lzz"

View File

@ -665,6 +665,7 @@ struct Addon
std::set <Database*, Database::CompareDatabase> dbs; std::set <Database*, Database::CompareDatabase> dbs;
#line 43 "./src/better_sqlite3.lzz" #line 43 "./src/better_sqlite3.lzz"
static void JS_setErrorConstructor (v8::FunctionCallbackInfo <v8 :: Value> const & info); static void JS_setErrorConstructor (v8::FunctionCallbackInfo <v8 :: Value> const & info);
static void JS_setCorruptionLogger (v8::FunctionCallbackInfo <v8 :: Value> const & info);
#line 48 "./src/better_sqlite3.lzz" #line 48 "./src/better_sqlite3.lzz"
static void Cleanup (void * ptr); static void Cleanup (void * ptr);
#line 55 "./src/better_sqlite3.lzz" #line 55 "./src/better_sqlite3.lzz"