Skip to content

Commit e736497

Browse files
author
Oscar Franco
committed
Do not throw on invalid SQL statement and bump version
1 parent 27fea14 commit e736497

7 files changed

Lines changed: 62 additions & 57 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ If you are using quick-sqlite in your app, please get in touch or open a PR with
3434
- Your app will now include C++, you will need to install the NDK on your machine for android. (unless you know how to generate an AAR, feel free to open a PR)
3535
- If you want to run the example project on android, you will have to change the paths on the android/CMakeLists.txt file, they are already there, just uncomment them.
3636
- This library supports SQLite BLOBs which are mapped to JS ArrayBuffers, check out the sample project on how to use it
37+
- Starting with version 2.0.0 the library no longer throws errors when an invalid statement is passed, but rather returns an object with a `status` enum property, where 0 signals a succesful execution and `1` an incorrect execution (this is to keep typeorm from exploding when an incorrect query is executed)
3738

3839
## Use TypeORM
3940

@@ -54,6 +55,8 @@ interface ISQLite {
5455
query: string,
5556
params: any[] | undefined
5657
) => {
58+
status: 0 | 1; // 0 for correct execution
59+
message: string; // if status === 1, here you will find error description
5760
rows: any[];
5861
insertId?: number;
5962
};

android/CMakeLists.txt

Lines changed: 44 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,47 @@ cmake_minimum_required(VERSION 3.4.1)
33
set (CMAKE_VERBOSE_MAKEFILE ON)
44
set (CMAKE_CXX_STANDARD 11)
55

6-
# This flag is set on the example project build.gradle (in the ext variables)
7-
# Needed to change the directories when building JUST the example project
8-
# message ("DEV_CMAKE=${DEV_CMAKE}")
9-
10-
# if(DEV_CMAKE)
11-
# include_directories(
12-
# ../cpp
13-
# ../node_modules/react-native/React
14-
# ../node_modules/react-native/React/Base
15-
# ../node_modules/react-native/ReactCommon/jsi
16-
# )
17-
18-
# add_library(sequel
19-
# SHARED
20-
21-
# ../node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp
22-
# ../cpp/sequel.cpp
23-
# ../cpp/sequel.h
24-
# ../cpp/SequelResult.h
25-
# ../cpp/react-native-quick-sqlite.cpp
26-
# ../cpp/react-native-quick-sqlite.h
27-
# ../cpp/sqlite3.h
28-
# ../cpp/sqlite3.c
29-
# cpp-adapter.cpp
30-
# )
31-
# else()
32-
include_directories(
33-
../cpp
34-
../../react-native/React
35-
../../react-native/React/Base
36-
../../react-native/ReactCommon/jsi
37-
)
38-
39-
add_library(sequel
40-
SHARED
41-
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
42-
../cpp/sequel.cpp
43-
../cpp/sequel.h
44-
../cpp/SequelResult.h
45-
../cpp/react-native-quick-sqlite.cpp
46-
../cpp/react-native-quick-sqlite.h
47-
../cpp/sqlite3.h
48-
../cpp/sqlite3.c
49-
cpp-adapter.cpp
50-
)
51-
# endif()
52-
53-
target_link_libraries(sequel android log)
6+
# Uncomment the following lines to compile the example project
7+
# include_directories(
8+
# ../cpp
9+
# ../node_modules/react-native/React
10+
# ../node_modules/react-native/React/Base
11+
# ../node_modules/react-native/ReactCommon/jsi
12+
# )
13+
14+
# add_library(sequel
15+
# SHARED
16+
17+
# ../node_modules/react-native/ReactCommon/jsi/jsi/jsi.cpp
18+
# ../cpp/sequel.cpp
19+
# ../cpp/sequel.h
20+
# ../cpp/SequelResult.h
21+
# ../cpp/react-native-quick-sqlite.cpp
22+
# ../cpp/react-native-quick-sqlite.h
23+
# ../cpp/sqlite3.h
24+
# ../cpp/sqlite3.c
25+
# cpp-adapter.cpp
26+
# )
27+
28+
include_directories(
29+
../cpp
30+
../../react-native/React
31+
../../react-native/React/Base
32+
../../react-native/ReactCommon/jsi
33+
)
34+
35+
add_library(sequel
36+
SHARED
37+
../../react-native/ReactCommon/jsi/jsi/jsi.cpp
38+
../cpp/sequel.cpp
39+
../cpp/sequel.h
40+
../cpp/SequelResult.h
41+
../cpp/react-native-quick-sqlite.cpp
42+
../cpp/react-native-quick-sqlite.h
43+
../cpp/sqlite3.h
44+
../cpp/sqlite3.c
45+
cpp-adapter.cpp
46+
)
47+
48+
49+
target_link_libraries(sequel android log)

cpp/react-native-quick-sqlite.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void installSequel(jsi::Runtime &rt, const char *docPath)
6262
jsi::detail::throwJSError(rt, "[react-native-quick-sqlite] database location must be a string");
6363
return {};
6464
}
65-
65+
6666
tempDocPath = tempDocPath + "/" + args[1].asString(rt).utf8(rt);
6767
}
6868

@@ -167,8 +167,11 @@ void installSequel(jsi::Runtime &rt, const char *docPath)
167167

168168
if (result.type == SequelResultError)
169169
{
170-
jsi::detail::throwJSError(rt, result.message.c_str());
171-
return {};
170+
// jsi::detail::throwJSError(rt, result.message.c_str());
171+
auto res = jsi::Object(rt);
172+
res.setProperty(rt, "status", jsi::Value(1));
173+
res.setProperty(rt, "message", jsi::String::createFromUtf8(rt, result.message.c_str()));
174+
return move(res);
172175
}
173176

174177
return move(result.value);

cpp/sequel.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
#include <unistd.h>
1616
#include <sys/stat.h>
1717
#include <map>
18+
// #ifdef ANDROID
19+
// #include "logs.h"
20+
// #endif // ANDROID
1821

1922
using namespace std;
2023
using namespace facebook;
@@ -262,14 +265,14 @@ SequelResult sequel_execute(jsi::Runtime &rt, string const dbName, string const
262265
// Compile and move result into statement memory spot
263266
int statementStatus = sqlite3_prepare_v2(db, query.c_str(), -1, &statement, NULL);
264267

268+
265269
if (statementStatus == SQLITE_OK) // statemnet is correct, bind the passed parameters
266270
{
267271
bindStatement(statement, rt, params);
268272
}
269273
else
270274
{
271275
const char *message = sqlite3_errmsg(db);
272-
273276
return {
274277
SequelResultError,
275278
"[react-native-quick-sqlite] SQL execution error: " + string(message),
@@ -377,6 +380,7 @@ SequelResult sequel_execute(jsi::Runtime &rt, string const dbName, string const
377380
}
378381

379382
jsi::Object rows = jsi::Object(rt);
383+
rows.setProperty(rt, "status", jsi::Value(0));
380384
rows.setProperty(rt, "length", jsi::Value((int)results.size()));
381385
rows.setProperty(rt, "_array", move(array));
382386

example/android/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ buildscript {
66
minSdkVersion = 16
77
compileSdkVersion = 29
88
targetSdkVersion = 29
9-
useDevCmakeLists = true
109
}
1110
repositories {
1211
google()

example/ios/Podfile.lock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ PODS:
185185
- React-cxxreact (= 0.63.4)
186186
- React-jsi (= 0.63.4)
187187
- React-jsinspector (0.63.4)
188-
- react-native-quick-sqlite (0.1.4):
188+
- react-native-quick-sqlite (1.0.5):
189189
- React-Core
190190
- React-RCTActionSheet (0.63.4):
191191
- React-Core/RCTActionSheetHeaders (= 0.63.4)
@@ -357,7 +357,7 @@ SPEC CHECKSUMS:
357357
React-jsi: a0418934cf48f25b485631deb27c64dc40fb4c31
358358
React-jsiexecutor: 93bd528844ad21dc07aab1c67cb10abae6df6949
359359
React-jsinspector: 58aef7155bc9a9683f5b60b35eccea8722a4f53a
360-
react-native-quick-sqlite: 4c9ebbb28e83ea60274084117c25b513dcf7b571
360+
react-native-quick-sqlite: b86820d88ce8c0ee4b5491a2ba1ebbf807a311b4
361361
React-RCTActionSheet: 89a0ca9f4a06c1f93c26067af074ccdce0f40336
362362
React-RCTAnimation: 1bde3ecc0c104c55df246eda516e0deb03c4e49b
363363
React-RCTBlob: a97d378b527740cc667e03ebfa183a75231ab0f0
@@ -372,4 +372,4 @@ SPEC CHECKSUMS:
372372

373373
PODFILE CHECKSUM: 468acaff90c15fab0a38d24ffe8509d22154ad61
374374

375-
COCOAPODS: 1.10.1
375+
COCOAPODS: 1.11.2

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-quick-sqlite",
3-
"version": "1.0.5",
3+
"version": "2.0.0",
44
"description": "Fast sqlite implementation for react-native",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

0 commit comments

Comments
 (0)