Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	package.json
  • Loading branch information
louislam committed Mar 27, 2023
2 parents 39a31c2 + 8598a9d commit 702211c
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
matrix:
os:
- macos-latest
- ubuntu-latest
- ubuntu-20.04
- windows-latest
host:
- x64
Expand Down Expand Up @@ -57,7 +57,7 @@ jobs:
run: npm install -g yarn

- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v1.1
uses: microsoft/setup-msbuild@v1.3
if: contains(matrix.os, 'windows')
with:
msbuild-architecture: ${{ matrix.target }}
Expand Down
6 changes: 4 additions & 2 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
"libraries": [
"-l<(sqlite_libname)"
],
"conditions": [ [ "OS=='linux'", {"libraries+":["-Wl,-rpath=<@(sqlite)/lib"]} ] ],
"conditions": [ [ "OS!='win'", {"libraries+":["-L<@(sqlite)/lib"]} ] ],
"conditions": [
[ "OS=='linux'", {"libraries+":["-Wl,-rpath=<@(sqlite)/lib"]} ],
[ "OS!='win'", {"libraries+":["-L<@(sqlite)/lib"]} ]
],
'msvs_settings': {
'VCLinkerTool': {
'AdditionalLibraryDirectories': [
Expand Down
2 changes: 1 addition & 1 deletion deps/common-sqlite.gypi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
'variables': {
'sqlite_version%':'3390400',
'sqlite_version%':'3410100',
"toolset%":'',
},
'target_defaults': {
Expand Down
Binary file removed deps/sqlite-autoconf-3390400.tar.gz
Binary file not shown.
Binary file added deps/sqlite-autoconf-3410100.tar.gz
Binary file not shown.
24 changes: 12 additions & 12 deletions lib/sqlite3.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,16 @@ export class Statement extends events.EventEmitter {
run(params: any, callback?: (this: RunResult, err: Error | null) => void): this;
run(...params: any[]): this;

get(callback?: (err: Error | null, row?: any) => void): this;
get(params: any, callback?: (this: RunResult, err: Error | null, row?: any) => void): this;
get<T>(callback?: (err: Error | null, row?: T) => void): this;
get<T>(params: any, callback?: (this: RunResult, err: Error | null, row?: T) => void): this;
get(...params: any[]): this;

all(callback?: (err: Error | null, rows: any[]) => void): this;
all(params: any, callback?: (this: RunResult, err: Error | null, rows: any[]) => void): this;
all<T>(callback?: (err: Error | null, rows: T[]) => void): this;
all<T>(params: any, callback?: (this: RunResult, err: Error | null, rows: T[]) => void): this;
all(...params: any[]): this;

each(callback?: (err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each(params: any, callback?: (this: RunResult, err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(callback?: (err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(params: any, callback?: (this: RunResult, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each(...params: any[]): this;
}

Expand All @@ -103,16 +103,16 @@ export class Database extends events.EventEmitter {
run(sql: string, params: any, callback?: (this: RunResult, err: Error | null) => void): this;
run(sql: string, ...params: any[]): this;

get(sql: string, callback?: (this: Statement, err: Error | null, row: any) => void): this;
get(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: any) => void): this;
get<T>(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void): this;
get<T>(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void): this;
get(sql: string, ...params: any[]): this;

all(sql: string, callback?: (this: Statement, err: Error | null, rows: any[]) => void): this;
all(sql: string, params: any, callback?: (this: Statement, err: Error | null, rows: any[]) => void): this;
all<T>(sql: string, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this;
all<T>(sql: string, params: any, callback?: (this: Statement, err: Error | null, rows: T[]) => void): this;
all(sql: string, ...params: any[]): this;

each(sql: string, callback?: (this: Statement, err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: any) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(sql: string, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each<T>(sql: string, params: any, callback?: (this: Statement, err: Error | null, row: T) => void, complete?: (err: Error | null, count: number) => void): this;
each(sql: string, ...params: any[]): this;

exec(sql: string, callback?: (this: Statement, err: Error | null) => void): this;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@louislam/sqlite3",
"description": "Asynchronous, non-blocking SQLite3 bindings",
"version": "15.1.2",
"homepage": "https://github.com/louislam/node-sqlite3",
"version": "15.1.6",
"homepage": "https://github.com/TryGhost/node-sqlite3",
"author": {
"name": "Mapbox",
"url": "https://mapbox.com/"
Expand Down Expand Up @@ -57,15 +57,15 @@
"node-pre-gyp-github": "1.4.4"
},
"peerDependencies": {
"node-gyp": "7.x"
"node-gyp": "8.x"
},
"peerDependenciesMeta": {
"node-gyp": {
"optional": true
}
},
"optionalDependencies": {
"node-gyp": "^7.1.2"
"node-gyp": "8.x"
},
"scripts": {
"build": "node-pre-gyp build",
Expand Down
18 changes: 9 additions & 9 deletions src/database.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void Database::Process() {
queue.pop();
std::unique_ptr<Baton> baton(call->baton);
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
TRY_CATCH_CALL(this->Value(), cb, 1, argv);
called = true;
}
Expand Down Expand Up @@ -97,7 +97,7 @@ void Database::Schedule(Work_Callback callback, Baton* baton, bool exclusive) {
// We don't call the actual callback, so we have to make sure that
// the baton gets destroyed.
delete baton;
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { exception };
TRY_CATCH_CALL(Value(), cb, 1, argv);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ void Database::Work_AfterOpen(napi_env e, napi_status status, void* data) {

Napi::Function cb = baton->callback.Value();

if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
TRY_CATCH_CALL(db->Value(), cb, 1, argv);
}
else if (!db->open) {
Expand Down Expand Up @@ -294,7 +294,7 @@ void Database::Work_AfterClose(napi_env e, napi_status status, void* data) {
Napi::Function cb = baton->callback.Value();

// Fire callbacks.
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
TRY_CATCH_CALL(db->Value(), cb, 1, argv);
}
else if (db->open) {
Expand Down Expand Up @@ -630,7 +630,7 @@ void Database::Work_AfterExec(napi_env e, napi_status status, void* data) {
if (baton->status != SQLITE_OK) {
EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception);

if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { exception };
TRY_CATCH_CALL(db->Value(), cb, 1, argv);
}
Expand All @@ -639,7 +639,7 @@ void Database::Work_AfterExec(napi_env e, napi_status status, void* data) {
EMIT_EVENT(db->Value(), 2, info);
}
}
else if (!cb.IsUndefined() && cb.IsFunction()) {
else if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { env.Null() };
TRY_CATCH_CALL(db->Value(), cb, 1, argv);
}
Expand Down Expand Up @@ -671,7 +671,7 @@ void Database::Work_Wait(Baton* b) {
assert(baton->db->pending == 0);

Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { env.Null() };
TRY_CATCH_CALL(baton->db->Value(), cb, 1, argv);
}
Expand Down Expand Up @@ -742,7 +742,7 @@ void Database::Work_AfterLoadExtension(napi_env e, napi_status status, void* dat
if (baton->status != SQLITE_OK) {
EXCEPTION(Napi::String::New(env, baton->message.c_str()), baton->status, exception);

if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { exception };
TRY_CATCH_CALL(db->Value(), cb, 1, argv);
}
Expand All @@ -751,7 +751,7 @@ void Database::Work_AfterLoadExtension(napi_env e, napi_status status, void* dat
EMIT_EVENT(db->Value(), 2, info);
}
}
else if (!cb.IsUndefined() && cb.IsFunction()) {
else if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { env.Null() };
TRY_CATCH_CALL(db->Value(), cb, 1, argv);
}
Expand Down
2 changes: 2 additions & 0 deletions src/gcc-preinclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
__asm__(".symver exp,exp@GLIBC_2.2.5");
__asm__(".symver log,log@GLIBC_2.2.5");
__asm__(".symver log2,log2@GLIBC_2.2.5");
__asm__(".symver pow,pow@GLIBC_2.2.5");
__asm__(".symver fcntl64,fcntl@GLIBC_2.2.5");
#endif
Expand All @@ -20,6 +21,7 @@ __asm__(".symver fcntl64,fcntl@GLIBC_2.2.5");
__asm__(".symver memcpy,memcpy@GLIBC_2.17");
__asm__(".symver exp,exp@GLIBC_2.17");
__asm__(".symver log,log@GLIBC_2.17");
__asm__(".symver log2,log2@GLIBC_2.17");
__asm__(".symver pow,pow@GLIBC_2.17");
__asm__(".symver fcntl64,fcntl@GLIBC_2.17");
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ inline bool OtherIsInt(Napi::Number source) {
}
}

#define IS_FUNCTION(cb) \
!cb.IsUndefined() && cb.IsFunction()

#define REQUIRE_ARGUMENTS(n) \
if (info.Length() < (n)) { \
Napi::TypeError::New(env, "Expected " #n "arguments").ThrowAsJavaScriptException(); \
Expand Down
18 changes: 9 additions & 9 deletions src/statement.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ template <class T> void Statement::Error(T* baton) {

Napi::Function cb = baton->callback.Value();

if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { exception };
TRY_CATCH_CALL(stmt->Value(), cb, 1, argv);
}
Expand Down Expand Up @@ -208,7 +208,7 @@ template <class T> Values::Field*
return new Values::Float(pos, source.ToNumber().DoubleValue());
}
else if (source.IsObject()) {
Napi::String napiVal = source.ToString();
Napi::String napiVal = Napi::String::New(source.Env(), "[object Object]");
// Check whether toString returned a value that is not undefined.
if(napiVal.Type() == 0) {
return NULL;
Expand Down Expand Up @@ -375,7 +375,7 @@ void Statement::Work_AfterBind(napi_env e, napi_status status, void* data) {
else {
// Fire callbacks.
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { env.Null() };
TRY_CATCH_CALL(stmt->Value(), cb, 1, argv);
}
Expand Down Expand Up @@ -442,7 +442,7 @@ void Statement::Work_AfterGet(napi_env e, napi_status status, void* data) {
else {
// Fire callbacks.
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
if (stmt->status == SQLITE_ROW) {
// Create the result array from the data we acquired.
Napi::Value argv[] = { env.Null(), RowToJS(env, &baton->row) };
Expand Down Expand Up @@ -516,7 +516,7 @@ void Statement::Work_AfterRun(napi_env e, napi_status status, void* data) {
else {
// Fire callbacks.
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
(stmt->Value()).Set(Napi::String::New(env, "lastID"), Napi::Number::New(env, baton->inserted_id));
(stmt->Value()).Set( Napi::String::New(env, "changes"), Napi::Number::New(env, baton->changes));

Expand Down Expand Up @@ -586,7 +586,7 @@ void Statement::Work_AfterAll(napi_env e, napi_status status, void* data) {
else {
// Fire callbacks.
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
if (baton->rows.size()) {
// Create the result array from the data we acquired.
Napi::Array result(Napi::Array::New(env, baton->rows.size()));
Expand Down Expand Up @@ -716,7 +716,7 @@ void Statement::AsyncEach(uv_async_t* handle) {
}

Napi::Function cb = async->item_cb.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[2];
argv[0] = env.Null();

Expand Down Expand Up @@ -791,7 +791,7 @@ void Statement::Work_AfterReset(napi_env e, napi_status status, void* data) {

// Fire callbacks.
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
Napi::Value argv[] = { env.Null() };
TRY_CATCH_CALL(stmt->Value(), cb, 1, argv);
}
Expand Down Expand Up @@ -893,7 +893,7 @@ void Statement::Finalize_(Baton* b) {

// Fire callback in case there was one.
Napi::Function cb = baton->callback.Value();
if (!cb.IsUndefined() && cb.IsFunction()) {
if (IS_FUNCTION(cb)) {
TRY_CATCH_CALL(baton->stmt->Value(), cb, 0, NULL);
}
}
Expand Down
16 changes: 16 additions & 0 deletions test/other_objects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,20 @@ describe('data types', function() {
});
});

it('should ignore faulty toString in array', function(done) {
const faulty = [[{toString: null}], 1];
db.all('SELECT * FROM txt_table WHERE txt = ? LIMIT ?', faulty, function (err) {
assert.equal(err, null);
done();
});
});

it('should ignore faulty toString set to function', function(done) {
const faulty = [[{toString: function () {console.log('oh no');}}], 1];
db.all('SELECT * FROM txt_table WHERE txt = ? LIMIT ?', faulty, function (err) {
assert.equal(err, undefined);
done();
});
});

});
4 changes: 2 additions & 2 deletions tools/BinaryBuilder.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ FROM node:$NODE_VERSION-$VARIANT

ARG VARIANT

RUN if [[ "$VARIANT" =~ alpine* ]] ; then apk add build-base python3 --update-cache ; fi
RUN if case $VARIANT in "alpine"*) true;; *) false;; esac; then apk add build-base python3 --update-cache ; fi

WORKDIR /usr/src/build

Expand All @@ -22,7 +22,7 @@ ENV CXXFLAGS="${CXXFLAGS:-} -include ../src/gcc-preinclude.h"
RUN npx node-pre-gyp configure
RUN npx node-pre-gyp build

RUN if [[ ! "$VARIANT" =~ alpine* ]] ; then ldd lib/binding/*/node_sqlite3.node; nm lib/binding/*/node_sqlite3.node | grep "GLIBC_" | c++filt || true ; fi
RUN if case $VARIANT in "alpine"*) false;; *) true;; esac; then ldd lib/binding/*/node_sqlite3.node; nm lib/binding/*/node_sqlite3.node | grep \"GLIBC_\" | c++filt || true ; fi

RUN npm run test
RUN npx node-pre-gyp package
Expand Down

0 comments on commit 702211c

Please sign in to comment.