@op-engineering/op-sqlite 2.0.16 → 2.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -5
- package/android/build.gradle +4 -0
- package/cpp/PreparedStatementHostObject.cpp +3 -3
- package/cpp/bindings.cpp +48 -44
- package/cpp/bridge.cpp +101 -129
- package/cpp/bridge.h +53 -49
- package/cpp/sqlbatchexecutor.cpp +6 -6
- package/cpp/sqlite3.c +5642 -2573
- package/cpp/sqlite3.h +127 -31
- package/cpp/utils.cpp +5 -5
- package/op-sqlite.podspec +8 -1
- package/package.json +1 -1
package/cpp/bridge.cpp
CHANGED
|
@@ -3,52 +3,56 @@
|
|
|
3
3
|
#include "SmartHostObject.h"
|
|
4
4
|
#include "logs.h"
|
|
5
5
|
#include "utils.h"
|
|
6
|
-
#include <ctime>
|
|
7
6
|
#include <unordered_map>
|
|
8
7
|
#include <variant>
|
|
9
8
|
|
|
10
9
|
namespace opsqlite {
|
|
11
10
|
|
|
11
|
+
/// Maps to hold the different objects
|
|
12
12
|
std::unordered_map<std::string, sqlite3 *> dbMap =
|
|
13
13
|
std::unordered_map<std::string, sqlite3 *>();
|
|
14
|
-
std::unordered_map<std::string,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
14
|
+
std::unordered_map<std::string, UpdateCallback> updateCallbackMap =
|
|
15
|
+
std::unordered_map<std::string, UpdateCallback>();
|
|
16
|
+
|
|
17
|
+
std::unordered_map<std::string, CommitCallback> commitCallbackMap =
|
|
18
|
+
std::unordered_map<std::string, CommitCallback>();
|
|
19
|
+
|
|
20
|
+
std::unordered_map<std::string, RollbackCallback> rollbackCallbackMap =
|
|
21
|
+
std::unordered_map<std::string, RollbackCallback>();
|
|
22
|
+
|
|
23
|
+
inline void check_db_open(std::string const &db_name) {
|
|
24
|
+
if (dbMap.count(db_name) == 0) {
|
|
25
|
+
throw std::runtime_error("[OP-SQLite] DB is not open");
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/// Start of api
|
|
30
|
+
|
|
31
|
+
/// Returns the completely formed db path, but it also creates any sub-folders
|
|
32
|
+
/// along the way
|
|
33
|
+
std::string get_db_path(std::string const &db_name,
|
|
34
|
+
std::string const &location) {
|
|
35
|
+
|
|
36
|
+
if (location == ":memory:") {
|
|
37
|
+
return location;
|
|
35
38
|
}
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
|
|
40
|
+
mkdir(location);
|
|
41
|
+
return location + "/" + db_name;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
|
-
BridgeResult
|
|
41
|
-
|
|
44
|
+
BridgeResult opsqlite_open(std::string const &dbName,
|
|
45
|
+
std::string const &lastPath) {
|
|
42
46
|
std::string dbPath = get_db_path(dbName, lastPath);
|
|
43
47
|
|
|
44
48
|
int sqlOpenFlags =
|
|
45
49
|
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE | SQLITE_OPEN_FULLMUTEX;
|
|
46
50
|
|
|
47
51
|
sqlite3 *db;
|
|
48
|
-
int exit = 0;
|
|
49
|
-
exit = sqlite3_open_v2(dbPath.c_str(), &db, sqlOpenFlags, nullptr);
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
int status = sqlite3_open_v2(dbPath.c_str(), &db, sqlOpenFlags, nullptr);
|
|
54
|
+
|
|
55
|
+
if (status != SQLITE_OK) {
|
|
52
56
|
return {.type = SQLiteError, .message = sqlite3_errmsg(db)};
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -57,14 +61,9 @@ BridgeResult sqlite_open(std::string const &dbName,
|
|
|
57
61
|
return BridgeResult{.type = SQLiteOk, .affectedRows = 0};
|
|
58
62
|
}
|
|
59
63
|
|
|
60
|
-
BridgeResult
|
|
64
|
+
BridgeResult opsqlite_close(std::string const &dbName) {
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
.type = SQLiteError,
|
|
65
|
-
.message = dbName + " is not open",
|
|
66
|
-
};
|
|
67
|
-
}
|
|
66
|
+
check_db_open(dbName);
|
|
68
67
|
|
|
69
68
|
sqlite3 *db = dbMap[dbName];
|
|
70
69
|
|
|
@@ -77,10 +76,10 @@ BridgeResult sqlite_close(std::string const &dbName) {
|
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
78
|
|
|
80
|
-
BridgeResult
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
79
|
+
BridgeResult opsqlite_attach(std::string const &mainDBName,
|
|
80
|
+
std::string const &docPath,
|
|
81
|
+
std::string const &databaseToAttach,
|
|
82
|
+
std::string const &alias) {
|
|
84
83
|
/**
|
|
85
84
|
* There is no need to check if mainDBName is opened because
|
|
86
85
|
* sqliteExecuteLiteral will do that.
|
|
@@ -88,7 +87,7 @@ BridgeResult sqlite_attach(std::string const &mainDBName,
|
|
|
88
87
|
std::string dbPath = get_db_path(databaseToAttach, docPath);
|
|
89
88
|
std::string statement = "ATTACH DATABASE '" + dbPath + "' AS " + alias;
|
|
90
89
|
|
|
91
|
-
BridgeResult result =
|
|
90
|
+
BridgeResult result = opsqlite_execute_literal(mainDBName, statement);
|
|
92
91
|
|
|
93
92
|
if (result.type == SQLiteError) {
|
|
94
93
|
return {
|
|
@@ -102,14 +101,14 @@ BridgeResult sqlite_attach(std::string const &mainDBName,
|
|
|
102
101
|
};
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
BridgeResult
|
|
106
|
-
|
|
104
|
+
BridgeResult opsqlite_detach(std::string const &mainDBName,
|
|
105
|
+
std::string const &alias) {
|
|
107
106
|
/**
|
|
108
107
|
* There is no need to check if mainDBName is opened because
|
|
109
108
|
* sqliteExecuteLiteral will do that.
|
|
110
109
|
* */
|
|
111
110
|
std::string statement = "DETACH DATABASE " + alias;
|
|
112
|
-
BridgeResult result =
|
|
111
|
+
BridgeResult result = opsqlite_execute_literal(mainDBName, statement);
|
|
113
112
|
if (result.type == SQLiteError) {
|
|
114
113
|
return BridgeResult{
|
|
115
114
|
.type = SQLiteError,
|
|
@@ -122,10 +121,10 @@ BridgeResult sqlite_detach(std::string const &mainDBName,
|
|
|
122
121
|
};
|
|
123
122
|
}
|
|
124
123
|
|
|
125
|
-
BridgeResult
|
|
126
|
-
|
|
124
|
+
BridgeResult opsqlite_remove(std::string const &dbName,
|
|
125
|
+
std::string const &docPath) {
|
|
127
126
|
if (dbMap.count(dbName) == 1) {
|
|
128
|
-
BridgeResult closeResult =
|
|
127
|
+
BridgeResult closeResult = opsqlite_close(dbName);
|
|
129
128
|
if (closeResult.type == SQLiteError) {
|
|
130
129
|
return closeResult;
|
|
131
130
|
}
|
|
@@ -145,8 +144,8 @@ BridgeResult sqlite_remove(std::string const &dbName,
|
|
|
145
144
|
};
|
|
146
145
|
}
|
|
147
146
|
|
|
148
|
-
inline void
|
|
149
|
-
|
|
147
|
+
inline void opsqlite_bind_statement(sqlite3_stmt *statement,
|
|
148
|
+
const std::vector<JSVariant> *values) {
|
|
150
149
|
size_t size = values->size();
|
|
151
150
|
|
|
152
151
|
for (int ii = 0; ii < size; ii++) {
|
|
@@ -175,19 +174,12 @@ inline void bindStatement(sqlite3_stmt *statement,
|
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
|
|
178
|
-
|
|
179
|
-
const std::vector<JSVariant> *params) {
|
|
180
|
-
bindStatement(statement, params);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
BridgeResult sqlite_execute_prepared_statement(
|
|
177
|
+
BridgeResult opsqlite_execute_prepared_statement(
|
|
184
178
|
std::string const &dbName, sqlite3_stmt *statement,
|
|
185
179
|
std::vector<DumbHostObject> *results,
|
|
186
180
|
std::shared_ptr<std::vector<SmartHostObject>> metadatas) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
.message = "[op-sqlite]: Database " + dbName + " is not open"};
|
|
190
|
-
}
|
|
181
|
+
|
|
182
|
+
check_db_open(dbName);
|
|
191
183
|
|
|
192
184
|
sqlite3_reset(statement);
|
|
193
185
|
|
|
@@ -265,7 +257,7 @@ BridgeResult sqlite_execute_prepared_statement(
|
|
|
265
257
|
// Intentionally left blank
|
|
266
258
|
|
|
267
259
|
default:
|
|
268
|
-
row.values.push_back(JSVariant(
|
|
260
|
+
row.values.push_back(JSVariant(nullptr));
|
|
269
261
|
break;
|
|
270
262
|
}
|
|
271
263
|
i++;
|
|
@@ -319,11 +311,9 @@ BridgeResult sqlite_execute_prepared_statement(
|
|
|
319
311
|
.insertId = static_cast<double>(latestInsertRowId)};
|
|
320
312
|
}
|
|
321
313
|
|
|
322
|
-
sqlite3_stmt *
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
throw std::runtime_error("Database not opened");
|
|
326
|
-
}
|
|
314
|
+
sqlite3_stmt *opsqlite_prepare_statement(std::string const &dbName,
|
|
315
|
+
std::string const &query) {
|
|
316
|
+
check_db_open(dbName);
|
|
327
317
|
|
|
328
318
|
sqlite3 *db = dbMap[dbName];
|
|
329
319
|
|
|
@@ -342,16 +332,14 @@ sqlite3_stmt *sqlite_prepare_statement(std::string const &dbName,
|
|
|
342
332
|
return statement;
|
|
343
333
|
}
|
|
344
334
|
|
|
335
|
+
/// Base execution function, returns HostObjects to the JS environment
|
|
345
336
|
BridgeResult
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
337
|
+
opsqlite_execute(std::string const &dbName, std::string const &query,
|
|
338
|
+
const std::vector<JSVariant> *params,
|
|
339
|
+
std::vector<DumbHostObject> *results,
|
|
340
|
+
std::shared_ptr<std::vector<SmartHostObject>> metadatas) {
|
|
350
341
|
|
|
351
|
-
|
|
352
|
-
return {.type = SQLiteError,
|
|
353
|
-
.message = "[op-sqlite]: Database " + dbName + " is not open"};
|
|
354
|
-
}
|
|
342
|
+
check_db_open(dbName);
|
|
355
343
|
|
|
356
344
|
sqlite3 *db = dbMap[dbName];
|
|
357
345
|
|
|
@@ -389,7 +377,7 @@ sqlite_execute(std::string const &dbName, std::string const &query,
|
|
|
389
377
|
}
|
|
390
378
|
|
|
391
379
|
if (params != nullptr && params->size() > 0) {
|
|
392
|
-
|
|
380
|
+
opsqlite_bind_statement(statement, params);
|
|
393
381
|
}
|
|
394
382
|
|
|
395
383
|
isConsuming = true;
|
|
@@ -457,7 +445,7 @@ sqlite_execute(std::string const &dbName, std::string const &query,
|
|
|
457
445
|
// Intentionally left blank
|
|
458
446
|
|
|
459
447
|
default:
|
|
460
|
-
row.values.push_back(JSVariant(
|
|
448
|
+
row.values.push_back(JSVariant(nullptr));
|
|
461
449
|
break;
|
|
462
450
|
}
|
|
463
451
|
i++;
|
|
@@ -518,15 +506,14 @@ sqlite_execute(std::string const &dbName, std::string const &query,
|
|
|
518
506
|
.insertId = static_cast<double>(latestInsertRowId)};
|
|
519
507
|
}
|
|
520
508
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
509
|
+
/// Executes returning data in raw arrays, a small performance optimization for
|
|
510
|
+
/// certain use cases
|
|
511
|
+
BridgeResult
|
|
512
|
+
opsqlite_execute_raw(std::string const &dbName, std::string const &query,
|
|
513
|
+
const std::vector<JSVariant> *params,
|
|
514
|
+
std::vector<std::vector<JSVariant>> *results) {
|
|
525
515
|
|
|
526
|
-
|
|
527
|
-
return {.type = SQLiteError,
|
|
528
|
-
.message = "[op-sqlite]: Database " + dbName + " is not open"};
|
|
529
|
-
}
|
|
516
|
+
check_db_open(dbName);
|
|
530
517
|
|
|
531
518
|
sqlite3 *db = dbMap[dbName];
|
|
532
519
|
|
|
@@ -564,7 +551,7 @@ BridgeResult sqlite_execute_raw(std::string const &dbName,
|
|
|
564
551
|
}
|
|
565
552
|
|
|
566
553
|
if (params != nullptr && params->size() > 0) {
|
|
567
|
-
|
|
554
|
+
opsqlite_bind_statement(statement, params);
|
|
568
555
|
}
|
|
569
556
|
|
|
570
557
|
isConsuming = true;
|
|
@@ -619,8 +606,6 @@ BridgeResult sqlite_execute_raw(std::string const &dbName,
|
|
|
619
606
|
int blob_size = sqlite3_column_bytes(statement, i);
|
|
620
607
|
const void *blob = sqlite3_column_blob(statement, i);
|
|
621
608
|
uint8_t *data = new uint8_t[blob_size];
|
|
622
|
-
// You cannot share raw memory between native and JS
|
|
623
|
-
// always copy the data
|
|
624
609
|
memcpy(data, blob, blob_size);
|
|
625
610
|
row.push_back(
|
|
626
611
|
JSVariant(ArrayBuffer{.data = std::shared_ptr<uint8_t>{data},
|
|
@@ -632,7 +617,7 @@ BridgeResult sqlite_execute_raw(std::string const &dbName,
|
|
|
632
617
|
// Intentionally left blank
|
|
633
618
|
|
|
634
619
|
default:
|
|
635
|
-
row.push_back(JSVariant(
|
|
620
|
+
row.push_back(JSVariant(nullptr));
|
|
636
621
|
break;
|
|
637
622
|
}
|
|
638
623
|
i++;
|
|
@@ -676,11 +661,11 @@ BridgeResult sqlite_execute_raw(std::string const &dbName,
|
|
|
676
661
|
.insertId = static_cast<double>(latestInsertRowId)};
|
|
677
662
|
}
|
|
678
663
|
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
664
|
+
/// Executes without returning any results, Useful for performance critical
|
|
665
|
+
/// operations
|
|
666
|
+
BridgeResult opsqlite_execute_literal(std::string const &dbName,
|
|
667
|
+
std::string const &query) {
|
|
668
|
+
check_db_open(dbName);
|
|
684
669
|
|
|
685
670
|
sqlite3 *db = dbMap[dbName];
|
|
686
671
|
sqlite3_stmt *statement;
|
|
@@ -730,7 +715,7 @@ BridgeResult sqlite_execute_literal(std::string const &dbName,
|
|
|
730
715
|
return {SQLiteOk, "", changedRowCount};
|
|
731
716
|
}
|
|
732
717
|
|
|
733
|
-
void
|
|
718
|
+
void opsqlite_close_all() {
|
|
734
719
|
for (auto const &x : dbMap) {
|
|
735
720
|
// Interrupt will make all pending operations to fail with SQLITE_INTERRUPT
|
|
736
721
|
// The ongoing work from threads will then fail ASAP
|
|
@@ -768,13 +753,9 @@ void update_callback(void *dbName, int operation_type, char const *database,
|
|
|
768
753
|
static_cast<int>(rowid));
|
|
769
754
|
}
|
|
770
755
|
|
|
771
|
-
BridgeResult
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
std::string operation, int rowId)> const callback) {
|
|
775
|
-
if (dbMap.count(dbName) == 0) {
|
|
776
|
-
return {SQLiteError, "[op-sqlite] Database not opened: " + dbName};
|
|
777
|
-
}
|
|
756
|
+
BridgeResult opsqlite_register_update_hook(std::string const &dbName,
|
|
757
|
+
UpdateCallback const callback) {
|
|
758
|
+
check_db_open(dbName);
|
|
778
759
|
|
|
779
760
|
sqlite3 *db = dbMap[dbName];
|
|
780
761
|
updateCallbackMap[dbName] = callback;
|
|
@@ -792,10 +773,8 @@ BridgeResult sqlite_register_update_hook(
|
|
|
792
773
|
return {SQLiteOk};
|
|
793
774
|
}
|
|
794
775
|
|
|
795
|
-
BridgeResult
|
|
796
|
-
|
|
797
|
-
return {SQLiteError, "[op-sqlite] Database not opened: " + dbName};
|
|
798
|
-
}
|
|
776
|
+
BridgeResult opsqlite_deregister_update_hook(std::string const &dbName) {
|
|
777
|
+
check_db_open(dbName);
|
|
799
778
|
|
|
800
779
|
sqlite3 *db = dbMap[dbName];
|
|
801
780
|
updateCallbackMap.erase(dbName);
|
|
@@ -813,12 +792,9 @@ int commit_callback(void *dbName) {
|
|
|
813
792
|
return 0;
|
|
814
793
|
}
|
|
815
794
|
|
|
816
|
-
BridgeResult
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
if (dbMap.count(dbName) == 0) {
|
|
820
|
-
return {SQLiteError, "[op-sqlite] Database not opened: " + dbName};
|
|
821
|
-
}
|
|
795
|
+
BridgeResult opsqlite_register_commit_hook(std::string const &dbName,
|
|
796
|
+
CommitCallback const callback) {
|
|
797
|
+
check_db_open(dbName);
|
|
822
798
|
|
|
823
799
|
sqlite3 *db = dbMap[dbName];
|
|
824
800
|
commitCallbackMap[dbName] = callback;
|
|
@@ -836,10 +812,8 @@ BridgeResult sqlite_register_commit_hook(
|
|
|
836
812
|
return {SQLiteOk};
|
|
837
813
|
}
|
|
838
814
|
|
|
839
|
-
BridgeResult
|
|
840
|
-
|
|
841
|
-
return {SQLiteError, "[op-sqlite] Database not opened: " + dbName};
|
|
842
|
-
}
|
|
815
|
+
BridgeResult opsqlite_deregister_commit_hook(std::string const &dbName) {
|
|
816
|
+
check_db_open(dbName);
|
|
843
817
|
|
|
844
818
|
sqlite3 *db = dbMap[dbName];
|
|
845
819
|
commitCallbackMap.erase(dbName);
|
|
@@ -854,12 +828,9 @@ void rollback_callback(void *dbName) {
|
|
|
854
828
|
callback(strDbName);
|
|
855
829
|
}
|
|
856
830
|
|
|
857
|
-
BridgeResult
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
if (dbMap.count(dbName) == 0) {
|
|
861
|
-
return {SQLiteError, "[op-sqlite] Database not opened: " + dbName};
|
|
862
|
-
}
|
|
831
|
+
BridgeResult opsqlite_register_rollback_hook(std::string const &dbName,
|
|
832
|
+
RollbackCallback const callback) {
|
|
833
|
+
check_db_open(dbName);
|
|
863
834
|
|
|
864
835
|
sqlite3 *db = dbMap[dbName];
|
|
865
836
|
rollbackCallbackMap[dbName] = callback;
|
|
@@ -877,10 +848,8 @@ BridgeResult sqlite_register_rollback_hook(
|
|
|
877
848
|
return {SQLiteOk};
|
|
878
849
|
}
|
|
879
850
|
|
|
880
|
-
BridgeResult
|
|
881
|
-
|
|
882
|
-
return {SQLiteError, "[op-sqlite] Database not opened: " + dbName};
|
|
883
|
-
}
|
|
851
|
+
BridgeResult opsqlite_deregister_rollback_hook(std::string const &dbName) {
|
|
852
|
+
check_db_open(dbName);
|
|
884
853
|
|
|
885
854
|
sqlite3 *db = dbMap[dbName];
|
|
886
855
|
rollbackCallbackMap.erase(dbName);
|
|
@@ -890,11 +859,13 @@ BridgeResult sqlite_deregister_rollback_hook(std::string const &dbName) {
|
|
|
890
859
|
return {SQLiteOk};
|
|
891
860
|
}
|
|
892
861
|
|
|
893
|
-
BridgeResult
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
862
|
+
BridgeResult opsqlite_load_extension(std::string &db_name, std::string &path,
|
|
863
|
+
std::string &entry_point) {
|
|
864
|
+
#ifdef OP_SQLITE_USE_PHONE_VERSION
|
|
865
|
+
throw std::runtime_error(
|
|
866
|
+
"Embedded version of SQLite does not support loading extensions");
|
|
867
|
+
#else
|
|
868
|
+
check_db_open(db_name);
|
|
898
869
|
|
|
899
870
|
sqlite3 *db = dbMap[db_name];
|
|
900
871
|
int loading_extensions_enabled = sqlite3_enable_load_extension(db, 1);
|
|
@@ -915,6 +886,7 @@ BridgeResult sqlite_load_extension(std::string &db_name, std::string &path,
|
|
|
915
886
|
return {SQLiteError, std::string(error_message)};
|
|
916
887
|
}
|
|
917
888
|
return {SQLiteOk};
|
|
889
|
+
#endif
|
|
918
890
|
}
|
|
919
891
|
|
|
920
892
|
} // namespace opsqlite
|
package/cpp/bridge.h
CHANGED
|
@@ -3,73 +3,77 @@
|
|
|
3
3
|
|
|
4
4
|
#include "DumbHostObject.h"
|
|
5
5
|
#include "SmartHostObject.h"
|
|
6
|
+
#include "sqlite3.h"
|
|
6
7
|
#include "types.h"
|
|
7
8
|
#include "utils.h"
|
|
8
|
-
#include <sqlite3.h>
|
|
9
9
|
#include <vector>
|
|
10
10
|
|
|
11
11
|
namespace opsqlite {
|
|
12
12
|
|
|
13
13
|
namespace jsi = facebook::jsi;
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
/// Convenience types to avoid super long types
|
|
16
|
+
typedef std::function<void(std::string dbName, std::string tableName,
|
|
17
|
+
std::string operation, int rowId)>
|
|
18
|
+
UpdateCallback;
|
|
19
|
+
typedef std::function<void(std::string dbName)> CommitCallback;
|
|
20
|
+
typedef std::function<void(std::string dbName)> RollbackCallback;
|
|
16
21
|
|
|
17
|
-
BridgeResult
|
|
22
|
+
BridgeResult opsqlite_open(std::string const &dbName,
|
|
23
|
+
std::string const &dbPath);
|
|
18
24
|
|
|
19
|
-
BridgeResult
|
|
20
|
-
std::string const &docPath);
|
|
25
|
+
BridgeResult opsqlite_close(std::string const &dbName);
|
|
21
26
|
|
|
22
|
-
BridgeResult
|
|
23
|
-
|
|
24
|
-
std::string const &databaseToAttach,
|
|
25
|
-
std::string const &alias);
|
|
27
|
+
BridgeResult opsqlite_remove(std::string const &dbName,
|
|
28
|
+
std::string const &docPath);
|
|
26
29
|
|
|
27
|
-
BridgeResult
|
|
28
|
-
|
|
30
|
+
BridgeResult opsqlite_attach(std::string const &mainDBName,
|
|
31
|
+
std::string const &docPath,
|
|
32
|
+
std::string const &databaseToAttach,
|
|
33
|
+
std::string const &alias);
|
|
34
|
+
|
|
35
|
+
BridgeResult opsqlite_detach(std::string const &mainDBName,
|
|
36
|
+
std::string const &alias);
|
|
29
37
|
|
|
30
38
|
BridgeResult
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
BridgeResult
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
BridgeResult
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
void
|
|
45
|
-
|
|
46
|
-
BridgeResult
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
BridgeResult
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
BridgeResult
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
void sqlite_bind_statement(sqlite3_stmt *statement,
|
|
64
|
-
const std::vector<JSVariant> *params);
|
|
65
|
-
|
|
66
|
-
BridgeResult sqlite_execute_prepared_statement(
|
|
39
|
+
opsqlite_execute(std::string const &dbName, std::string const &query,
|
|
40
|
+
const std::vector<JSVariant> *params,
|
|
41
|
+
std::vector<DumbHostObject> *results,
|
|
42
|
+
std::shared_ptr<std::vector<SmartHostObject>> metadatas);
|
|
43
|
+
|
|
44
|
+
BridgeResult opsqlite_execute_raw(std::string const &dbName,
|
|
45
|
+
std::string const &query,
|
|
46
|
+
const std::vector<JSVariant> *params,
|
|
47
|
+
std::vector<std::vector<JSVariant>> *results);
|
|
48
|
+
|
|
49
|
+
BridgeResult opsqlite_execute_literal(std::string const &dbName,
|
|
50
|
+
std::string const &query);
|
|
51
|
+
|
|
52
|
+
void opsqlite_close_all();
|
|
53
|
+
|
|
54
|
+
BridgeResult opsqlite_register_update_hook(std::string const &dbName,
|
|
55
|
+
UpdateCallback const callback);
|
|
56
|
+
BridgeResult opsqlite_deregister_update_hook(std::string const &dbName);
|
|
57
|
+
BridgeResult opsqlite_register_commit_hook(std::string const &dbName,
|
|
58
|
+
CommitCallback const callback);
|
|
59
|
+
BridgeResult opsqlite_deregister_commit_hook(std::string const &dbName);
|
|
60
|
+
BridgeResult opsqlite_register_rollback_hook(std::string const &dbName,
|
|
61
|
+
RollbackCallback const callback);
|
|
62
|
+
BridgeResult opsqlite_deregister_rollback_hook(std::string const &dbName);
|
|
63
|
+
|
|
64
|
+
sqlite3_stmt *opsqlite_prepare_statement(std::string const &dbName,
|
|
65
|
+
std::string const &query);
|
|
66
|
+
|
|
67
|
+
void opsqlite_bind_statement(sqlite3_stmt *statement,
|
|
68
|
+
const std::vector<JSVariant> *params);
|
|
69
|
+
|
|
70
|
+
BridgeResult opsqlite_execute_prepared_statement(
|
|
67
71
|
std::string const &dbName, sqlite3_stmt *statement,
|
|
68
72
|
std::vector<DumbHostObject> *results,
|
|
69
73
|
std::shared_ptr<std::vector<SmartHostObject>> metadatas);
|
|
70
74
|
|
|
71
|
-
BridgeResult
|
|
72
|
-
|
|
75
|
+
BridgeResult opsqlite_load_extension(std::string &db_name, std::string &path,
|
|
76
|
+
std::string &entry_point);
|
|
73
77
|
|
|
74
78
|
} // namespace opsqlite
|
|
75
79
|
|
package/cpp/sqlbatchexecutor.cpp
CHANGED
|
@@ -57,15 +57,15 @@ BatchResult sqliteExecuteBatch(std::string dbName,
|
|
|
57
57
|
|
|
58
58
|
try {
|
|
59
59
|
int affectedRows = 0;
|
|
60
|
-
|
|
60
|
+
opsqlite_execute_literal(dbName, "BEGIN EXCLUSIVE TRANSACTION");
|
|
61
61
|
for (int i = 0; i < commandCount; i++) {
|
|
62
62
|
auto command = commands->at(i);
|
|
63
63
|
// We do not provide a datastructure to receive query data because we
|
|
64
64
|
// don't need/want to handle this results in a batch execution
|
|
65
|
-
auto result =
|
|
66
|
-
|
|
65
|
+
auto result = opsqlite_execute(dbName, command.sql, command.params.get(),
|
|
66
|
+
nullptr, nullptr);
|
|
67
67
|
if (result.type == SQLiteError) {
|
|
68
|
-
|
|
68
|
+
opsqlite_execute_literal(dbName, "ROLLBACK");
|
|
69
69
|
return BatchResult{
|
|
70
70
|
.type = SQLiteError,
|
|
71
71
|
.message = result.message,
|
|
@@ -74,14 +74,14 @@ BatchResult sqliteExecuteBatch(std::string dbName,
|
|
|
74
74
|
affectedRows += result.affectedRows;
|
|
75
75
|
}
|
|
76
76
|
}
|
|
77
|
-
|
|
77
|
+
opsqlite_execute_literal(dbName, "COMMIT");
|
|
78
78
|
return BatchResult{
|
|
79
79
|
.type = SQLiteOk,
|
|
80
80
|
.affectedRows = affectedRows,
|
|
81
81
|
.commands = static_cast<int>(commandCount),
|
|
82
82
|
};
|
|
83
83
|
} catch (std::exception &exc) {
|
|
84
|
-
|
|
84
|
+
opsqlite_execute_literal(dbName, "ROLLBACK");
|
|
85
85
|
return BatchResult{
|
|
86
86
|
.type = SQLiteError,
|
|
87
87
|
.message = exc.what(),
|