@op-engineering/op-sqlite 2.0.16 → 2.0.17
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 +20 -2
- package/cpp/PreparedStatementHostObject.cpp +3 -3
- package/cpp/bindings.cpp +18 -19
- package/cpp/bridge.cpp +98 -126
- 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/package.json +1 -1
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(),
|