1 | #include <stdint.h>
|
2 | #include <sstream>
|
3 | #include <cstring>
|
4 | #include <string>
|
5 | #include <sqlite3.h>
|
6 |
|
7 | #include "macros.h"
|
8 | #include "database.h"
|
9 | #include "statement.h"
|
10 | #include "backup.h"
|
11 |
|
12 | using namespace node_sqlite3;
|
13 |
|
14 | namespace {
|
15 |
|
16 | Napi::Object RegisterModule(Napi::Env env, Napi::Object exports) {
|
17 | Napi::HandleScope scope(env);
|
18 |
|
19 | Database::Init(env, exports);
|
20 | Statement::Init(env, exports);
|
21 | Backup::Init(env, exports);
|
22 |
|
23 | exports.DefineProperties({
|
24 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_READONLY, OPEN_READONLY)
|
25 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_READWRITE, OPEN_READWRITE)
|
26 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_CREATE, OPEN_CREATE)
|
27 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_FULLMUTEX, OPEN_FULLMUTEX)
|
28 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_URI, OPEN_URI)
|
29 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_SHAREDCACHE, OPEN_SHAREDCACHE)
|
30 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OPEN_PRIVATECACHE, OPEN_PRIVATECACHE)
|
31 | DEFINE_CONSTANT_STRING(exports, SQLITE_VERSION, VERSION)
|
32 | #ifdef SQLITE_SOURCE_ID
|
33 | DEFINE_CONSTANT_STRING(exports, SQLITE_SOURCE_ID, SOURCE_ID)
|
34 | #endif
|
35 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_VERSION_NUMBER, VERSION_NUMBER)
|
36 |
|
37 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_OK, OK)
|
38 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_ERROR, ERROR)
|
39 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_INTERNAL, INTERNAL)
|
40 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_PERM, PERM)
|
41 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_ABORT, ABORT)
|
42 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_BUSY, BUSY)
|
43 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LOCKED, LOCKED)
|
44 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOMEM, NOMEM)
|
45 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_READONLY, READONLY)
|
46 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_INTERRUPT, INTERRUPT)
|
47 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_IOERR, IOERR)
|
48 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_CORRUPT, CORRUPT)
|
49 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOTFOUND, NOTFOUND)
|
50 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_FULL, FULL)
|
51 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_CANTOPEN, CANTOPEN)
|
52 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_PROTOCOL, PROTOCOL)
|
53 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_EMPTY, EMPTY)
|
54 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_SCHEMA, SCHEMA)
|
55 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_TOOBIG, TOOBIG)
|
56 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_CONSTRAINT, CONSTRAINT)
|
57 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_MISMATCH, MISMATCH)
|
58 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_MISUSE, MISUSE)
|
59 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOLFS, NOLFS)
|
60 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_AUTH, AUTH)
|
61 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_FORMAT, FORMAT)
|
62 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_RANGE, RANGE)
|
63 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_NOTADB, NOTADB)
|
64 |
|
65 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_LENGTH, LIMIT_LENGTH)
|
66 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_SQL_LENGTH, LIMIT_SQL_LENGTH)
|
67 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_COLUMN, LIMIT_COLUMN)
|
68 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_EXPR_DEPTH, LIMIT_EXPR_DEPTH)
|
69 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_COMPOUND_SELECT, LIMIT_COMPOUND_SELECT)
|
70 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_VDBE_OP, LIMIT_VDBE_OP)
|
71 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_FUNCTION_ARG, LIMIT_FUNCTION_ARG)
|
72 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_ATTACHED, LIMIT_ATTACHED)
|
73 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_LIKE_PATTERN_LENGTH, LIMIT_LIKE_PATTERN_LENGTH)
|
74 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_VARIABLE_NUMBER, LIMIT_VARIABLE_NUMBER)
|
75 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_TRIGGER_DEPTH, LIMIT_TRIGGER_DEPTH)
|
76 | DEFINE_CONSTANT_INTEGER(exports, SQLITE_LIMIT_WORKER_THREADS, LIMIT_WORKER_THREADS)
|
77 | });
|
78 |
|
79 | return exports;
|
80 | }
|
81 |
|
82 | }
|
83 |
|
84 | const char* sqlite_code_string(int code) {
|
85 | switch (code) {
|
86 | case SQLITE_OK: return "SQLITE_OK";
|
87 | case SQLITE_ERROR: return "SQLITE_ERROR";
|
88 | case SQLITE_INTERNAL: return "SQLITE_INTERNAL";
|
89 | case SQLITE_PERM: return "SQLITE_PERM";
|
90 | case SQLITE_ABORT: return "SQLITE_ABORT";
|
91 | case SQLITE_BUSY: return "SQLITE_BUSY";
|
92 | case SQLITE_LOCKED: return "SQLITE_LOCKED";
|
93 | case SQLITE_NOMEM: return "SQLITE_NOMEM";
|
94 | case SQLITE_READONLY: return "SQLITE_READONLY";
|
95 | case SQLITE_INTERRUPT: return "SQLITE_INTERRUPT";
|
96 | case SQLITE_IOERR: return "SQLITE_IOERR";
|
97 | case SQLITE_CORRUPT: return "SQLITE_CORRUPT";
|
98 | case SQLITE_NOTFOUND: return "SQLITE_NOTFOUND";
|
99 | case SQLITE_FULL: return "SQLITE_FULL";
|
100 | case SQLITE_CANTOPEN: return "SQLITE_CANTOPEN";
|
101 | case SQLITE_PROTOCOL: return "SQLITE_PROTOCOL";
|
102 | case SQLITE_EMPTY: return "SQLITE_EMPTY";
|
103 | case SQLITE_SCHEMA: return "SQLITE_SCHEMA";
|
104 | case SQLITE_TOOBIG: return "SQLITE_TOOBIG";
|
105 | case SQLITE_CONSTRAINT: return "SQLITE_CONSTRAINT";
|
106 | case SQLITE_MISMATCH: return "SQLITE_MISMATCH";
|
107 | case SQLITE_MISUSE: return "SQLITE_MISUSE";
|
108 | case SQLITE_NOLFS: return "SQLITE_NOLFS";
|
109 | case SQLITE_AUTH: return "SQLITE_AUTH";
|
110 | case SQLITE_FORMAT: return "SQLITE_FORMAT";
|
111 | case SQLITE_RANGE: return "SQLITE_RANGE";
|
112 | case SQLITE_NOTADB: return "SQLITE_NOTADB";
|
113 | case SQLITE_ROW: return "SQLITE_ROW";
|
114 | case SQLITE_DONE: return "SQLITE_DONE";
|
115 | default: return "UNKNOWN";
|
116 | }
|
117 | }
|
118 |
|
119 | const char* sqlite_authorizer_string(int type) {
|
120 | switch (type) {
|
121 | case SQLITE_INSERT: return "insert";
|
122 | case SQLITE_UPDATE: return "update";
|
123 | case SQLITE_DELETE: return "delete";
|
124 | default: return "";
|
125 | }
|
126 | }
|
127 |
|
128 | NODE_API_MODULE(node_sqlite3, RegisterModule)
|