@capacitor-community/sqlite 5.0.7-2 → 5.0.7
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 +6 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +123 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +112 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +140 -78
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +9 -9
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDelete.java +484 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDrop.java +3 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +169 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +4 -4
- package/dist/esm/definitions.d.ts +96 -11
- package/dist/esm/definitions.js +99 -50
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -0
- package/dist/esm/web.js +44 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +143 -50
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +143 -50
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +600 -177
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +119 -0
- package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +128 -0
- package/ios/Plugin/Database.swift +76 -0
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +13 -2
- package/ios/Plugin/Utils/UtilsDelete.swift +116 -114
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +10 -3
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +84 -84
- package/ios/Plugin/Utils/UtilsUpgrade.swift +3 -0
- package/package.json +2 -2
- package/src/definitions.ts +187 -53
- package/src/web.ts +48 -0
package/electron/dist/plugin.js
CHANGED
|
@@ -9,8 +9,8 @@ var require$$3 = require('node-fetch');
|
|
|
9
9
|
var require$$4 = require('os');
|
|
10
10
|
var require$$5 = require('jszip');
|
|
11
11
|
var require$$6 = require('electron');
|
|
12
|
-
var require$$
|
|
13
|
-
var require$$3$
|
|
12
|
+
var require$$4$1 = require('better-sqlite3-multiple-ciphers');
|
|
13
|
+
var require$$3$1 = require('electron-json-storage');
|
|
14
14
|
var require$$1$1 = require('crypto');
|
|
15
15
|
var require$$2$1 = require('crypto-js');
|
|
16
16
|
|
|
@@ -23,8 +23,8 @@ var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
|
23
23
|
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
24
24
|
var require$$5__default = /*#__PURE__*/_interopDefaultLegacy(require$$5);
|
|
25
25
|
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
26
|
+
var require$$4__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$4$1);
|
|
26
27
|
var require$$3__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$3$1);
|
|
27
|
-
var require$$3__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$3$2);
|
|
28
28
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
29
29
|
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
30
30
|
|
|
@@ -48,6 +48,205 @@ var exportToJson = {};
|
|
|
48
48
|
|
|
49
49
|
var utilsSQLite = {};
|
|
50
50
|
|
|
51
|
+
var UtilsSQL92Compatibility$1 = {};
|
|
52
|
+
|
|
53
|
+
Object.defineProperty(UtilsSQL92Compatibility$1, "__esModule", { value: true });
|
|
54
|
+
UtilsSQL92Compatibility$1.UtilsSQL92Compatibility = void 0;
|
|
55
|
+
class UtilsSQL92Compatibility {
|
|
56
|
+
compatibleSQL92(statement) {
|
|
57
|
+
let newStatement = "";
|
|
58
|
+
const action = (statement.trim().substring(0, 6)).toUpperCase();
|
|
59
|
+
switch (action) {
|
|
60
|
+
case "INSERT":
|
|
61
|
+
newStatement = this.insertSQL92(statement);
|
|
62
|
+
break;
|
|
63
|
+
case "UPDATE":
|
|
64
|
+
newStatement = this.updateSQL92(statement);
|
|
65
|
+
break;
|
|
66
|
+
case "DELETE":
|
|
67
|
+
case "SELECT":
|
|
68
|
+
newStatement = this.whereSQL92(statement);
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
throw new Error(`Error: ${action} not implemented`);
|
|
72
|
+
}
|
|
73
|
+
return newStatement;
|
|
74
|
+
}
|
|
75
|
+
;
|
|
76
|
+
insertSQL92(insertStatement) {
|
|
77
|
+
// Split the statement into parts
|
|
78
|
+
const inStmt = insertStatement.trim();
|
|
79
|
+
const valuesStartIndex = inStmt.indexOf('VALUES');
|
|
80
|
+
const columnsPart = inStmt.substring(0, valuesStartIndex);
|
|
81
|
+
const valuesPart = inStmt.substring(valuesStartIndex);
|
|
82
|
+
// Extract values and replace double quotes with single quotes
|
|
83
|
+
const modifiedValuesPart = valuesPart.replace(/"([^"]+)"/g, "'$1'");
|
|
84
|
+
// Reconstruct the modified statement
|
|
85
|
+
const modifiedStatement = columnsPart + modifiedValuesPart;
|
|
86
|
+
return modifiedStatement;
|
|
87
|
+
}
|
|
88
|
+
;
|
|
89
|
+
updateSQL92(updateStatement) {
|
|
90
|
+
// Split the statement into SET and WHERE parts
|
|
91
|
+
let isWhere = true;
|
|
92
|
+
const setWhereSplit = updateStatement.toUpperCase().split('WHERE');
|
|
93
|
+
if (setWhereSplit.length <= 1)
|
|
94
|
+
isWhere = false;
|
|
95
|
+
const setUpdate = setWhereSplit[0].toUpperCase().split('SET')[0].trim();
|
|
96
|
+
const setPart = setWhereSplit[0].toUpperCase().split('SET')[1].trim();
|
|
97
|
+
const modifiedSetPart = this.modSetPart(setPart);
|
|
98
|
+
let modifiedStatement = `${setUpdate} SET ${modifiedSetPart}`;
|
|
99
|
+
if (isWhere) {
|
|
100
|
+
for (let i = 1; i < setWhereSplit.length; i++) {
|
|
101
|
+
const wherePart = setWhereSplit[i].trim();
|
|
102
|
+
const modifiedWherePart = this.modWherePart(wherePart);
|
|
103
|
+
modifiedStatement += ` WHERE ${modifiedWherePart}`;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return modifiedStatement;
|
|
107
|
+
}
|
|
108
|
+
;
|
|
109
|
+
whereSQL92(statement) {
|
|
110
|
+
// Split the statement into SET and WHERE parts
|
|
111
|
+
const setWhereSplit = statement.toUpperCase().split('WHERE');
|
|
112
|
+
if (setWhereSplit.length <= 1)
|
|
113
|
+
return statement;
|
|
114
|
+
let modifiedStatement = `${setWhereSplit[0].trim()}`;
|
|
115
|
+
for (let i = 1; i < setWhereSplit.length; i++) {
|
|
116
|
+
const wherePart = setWhereSplit[1].trim();
|
|
117
|
+
const modifiedWherePart = this.modWherePart(wherePart);
|
|
118
|
+
modifiedStatement += `WHERE ${modifiedWherePart}`;
|
|
119
|
+
}
|
|
120
|
+
return modifiedStatement;
|
|
121
|
+
}
|
|
122
|
+
;
|
|
123
|
+
modSetPart(setStatement) {
|
|
124
|
+
const commaPart = setStatement.split(",");
|
|
125
|
+
const modCommaPart = [];
|
|
126
|
+
for (const com of commaPart) {
|
|
127
|
+
const equalPart = com.split("=");
|
|
128
|
+
const value = equalPart[1].replaceAll(`"`, `'`);
|
|
129
|
+
modCommaPart.push(`${equalPart[0].trim()} = ${value.trim()}`);
|
|
130
|
+
}
|
|
131
|
+
return modCommaPart.toString();
|
|
132
|
+
}
|
|
133
|
+
;
|
|
134
|
+
modWherePart(whereStatement) {
|
|
135
|
+
const keywords = new Set([
|
|
136
|
+
'=',
|
|
137
|
+
'<>',
|
|
138
|
+
'>',
|
|
139
|
+
'>=',
|
|
140
|
+
'<',
|
|
141
|
+
'<=',
|
|
142
|
+
'IN',
|
|
143
|
+
'VALUES',
|
|
144
|
+
'(',
|
|
145
|
+
',',
|
|
146
|
+
')',
|
|
147
|
+
'BETWEEN',
|
|
148
|
+
'LIKE',
|
|
149
|
+
'AND',
|
|
150
|
+
'OR',
|
|
151
|
+
'NOT'
|
|
152
|
+
]);
|
|
153
|
+
const newTokens = [];
|
|
154
|
+
const tokens = whereStatement.split(/(\s|,|\(|\))/).filter(item => item !== ' ').filter(item => item !== '');
|
|
155
|
+
let inClause = false;
|
|
156
|
+
let inValues = false;
|
|
157
|
+
let modValue = false;
|
|
158
|
+
let betwClause = false;
|
|
159
|
+
let opsClause = false;
|
|
160
|
+
let inValValues = false;
|
|
161
|
+
let inValPar = false;
|
|
162
|
+
for (const token of tokens) {
|
|
163
|
+
if ((new Set(['=', '<>', '>', '>=', '<', '<='])).has(token)) {
|
|
164
|
+
newTokens.push(token);
|
|
165
|
+
modValue = true;
|
|
166
|
+
opsClause = false;
|
|
167
|
+
}
|
|
168
|
+
else if (token.toUpperCase() === 'BETWEEN') {
|
|
169
|
+
newTokens.push(token);
|
|
170
|
+
betwClause = true;
|
|
171
|
+
modValue = true;
|
|
172
|
+
opsClause = false;
|
|
173
|
+
}
|
|
174
|
+
else if (betwClause && token.toUpperCase() === 'AND') {
|
|
175
|
+
newTokens.push(token);
|
|
176
|
+
modValue = true;
|
|
177
|
+
betwClause = false;
|
|
178
|
+
}
|
|
179
|
+
else if (token.toUpperCase() === 'LIKE') {
|
|
180
|
+
newTokens.push(token);
|
|
181
|
+
opsClause = false;
|
|
182
|
+
modValue = true;
|
|
183
|
+
}
|
|
184
|
+
else if (token.toUpperCase() === 'AND' ||
|
|
185
|
+
token.toUpperCase() === 'OR' ||
|
|
186
|
+
token.toUpperCase() === 'NOT') {
|
|
187
|
+
newTokens.push(token);
|
|
188
|
+
opsClause = true;
|
|
189
|
+
}
|
|
190
|
+
else if (token.toUpperCase() === 'IN') {
|
|
191
|
+
newTokens.push(token);
|
|
192
|
+
opsClause = false;
|
|
193
|
+
inClause = true;
|
|
194
|
+
}
|
|
195
|
+
else if (inClause && token === '(') {
|
|
196
|
+
newTokens.push(token);
|
|
197
|
+
modValue = true;
|
|
198
|
+
inValues = true;
|
|
199
|
+
}
|
|
200
|
+
else if (inValues && token.toUpperCase() === ',') {
|
|
201
|
+
newTokens.push(token);
|
|
202
|
+
modValue = true;
|
|
203
|
+
}
|
|
204
|
+
else if (inValues && token.toUpperCase() === 'VALUES') {
|
|
205
|
+
newTokens.push(token);
|
|
206
|
+
inValues = false;
|
|
207
|
+
inValValues = true;
|
|
208
|
+
inClause = false;
|
|
209
|
+
}
|
|
210
|
+
else if (inValValues && token === '(') {
|
|
211
|
+
newTokens.push(token);
|
|
212
|
+
inValPar = true;
|
|
213
|
+
modValue = true;
|
|
214
|
+
}
|
|
215
|
+
else if (inValPar && token.toUpperCase() === ',') {
|
|
216
|
+
newTokens.push(token);
|
|
217
|
+
modValue = true;
|
|
218
|
+
}
|
|
219
|
+
else if (inValPar && inValValues && token === ')') {
|
|
220
|
+
newTokens.push(token);
|
|
221
|
+
inValPar = false;
|
|
222
|
+
inValues = true;
|
|
223
|
+
}
|
|
224
|
+
else if ((inValues || inValValues) && token === ')') {
|
|
225
|
+
newTokens.push(token);
|
|
226
|
+
inValValues = false;
|
|
227
|
+
inValues = false;
|
|
228
|
+
inClause = false;
|
|
229
|
+
}
|
|
230
|
+
else if (modValue &&
|
|
231
|
+
!opsClause &&
|
|
232
|
+
!keywords.has(token.toUpperCase())) {
|
|
233
|
+
if (token.length > 0) {
|
|
234
|
+
const nwToken = token.replaceAll(`"`, `'`);
|
|
235
|
+
newTokens.push(nwToken);
|
|
236
|
+
modValue = false;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
newTokens.push(token);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
const ns = newTokens.join(" ");
|
|
244
|
+
return ns;
|
|
245
|
+
}
|
|
246
|
+
;
|
|
247
|
+
}
|
|
248
|
+
UtilsSQL92Compatibility$1.UtilsSQL92Compatibility = UtilsSQL92Compatibility;
|
|
249
|
+
|
|
51
250
|
var utilsDelete = {};
|
|
52
251
|
|
|
53
252
|
Object.defineProperty(utilsDelete, "__esModule", { value: true });
|
|
@@ -75,7 +274,7 @@ class UtilsDelete {
|
|
|
75
274
|
if (refValue.length > 0) {
|
|
76
275
|
const arr = refValue.split(new RegExp('REFERENCES', 'i'));
|
|
77
276
|
if (arr.length === 2) {
|
|
78
|
-
const oPar = arr[1].indexOf(
|
|
277
|
+
const oPar = arr[1].indexOf('(');
|
|
79
278
|
tableName = arr[1].substring(0, oPar).trim();
|
|
80
279
|
}
|
|
81
280
|
}
|
|
@@ -787,7 +986,9 @@ class UtilsSQLStatement {
|
|
|
787
986
|
this.replaceString = (originalStr, searchStr, replaceStr) => {
|
|
788
987
|
const range = originalStr.indexOf(searchStr);
|
|
789
988
|
if (range !== -1) {
|
|
790
|
-
const modifiedStr = originalStr.substring(0, range) +
|
|
989
|
+
const modifiedStr = originalStr.substring(0, range) +
|
|
990
|
+
replaceStr +
|
|
991
|
+
originalStr.substring(range + searchStr.length);
|
|
791
992
|
return modifiedStr;
|
|
792
993
|
}
|
|
793
994
|
return originalStr;
|
|
@@ -813,18 +1014,15 @@ class UtilsSQLStatement {
|
|
|
813
1014
|
}
|
|
814
1015
|
addPrefixToWhereClause(whereClause, colNames, refNames, prefix) {
|
|
815
1016
|
let columnValuePairs;
|
|
816
|
-
if (whereClause.includes(
|
|
1017
|
+
if (whereClause.includes('AND')) {
|
|
817
1018
|
// Split the WHERE clause based on the "AND" keyword
|
|
818
|
-
const subSequenceArray = whereClause.split(
|
|
819
|
-
|
|
820
|
-
console.log(" subSequenceArray", subSequenceArray);
|
|
821
|
-
columnValuePairs = subSequenceArray.map((pair) => pair.trim());
|
|
1019
|
+
const subSequenceArray = whereClause.split('AND');
|
|
1020
|
+
columnValuePairs = subSequenceArray.map(pair => pair.trim());
|
|
822
1021
|
}
|
|
823
1022
|
else {
|
|
824
1023
|
columnValuePairs = [whereClause];
|
|
825
1024
|
}
|
|
826
|
-
|
|
827
|
-
const modifiedPairs = columnValuePairs.map((pair) => {
|
|
1025
|
+
const modifiedPairs = columnValuePairs.map(pair => {
|
|
828
1026
|
const match = pair.match(/(\w+)\s*(=|IN|BETWEEN|LIKE)\s*(.+)/);
|
|
829
1027
|
if (!match) {
|
|
830
1028
|
return pair;
|
|
@@ -841,7 +1039,7 @@ class UtilsSQLStatement {
|
|
|
841
1039
|
const ret = `${modifiedColumn} ${operator} ${value}`;
|
|
842
1040
|
return ret;
|
|
843
1041
|
});
|
|
844
|
-
return modifiedPairs.join(
|
|
1042
|
+
return modifiedPairs.join(' AND ');
|
|
845
1043
|
}
|
|
846
1044
|
findIndexOfStringInArray(target, array) {
|
|
847
1045
|
return array.indexOf(target);
|
|
@@ -860,60 +1058,100 @@ class UtilsSQLStatement {
|
|
|
860
1058
|
const matches = sqlStatement.match(foreignKeyPattern);
|
|
861
1059
|
if (matches) {
|
|
862
1060
|
const foreignKeyInfo = {
|
|
863
|
-
forKeys: matches[1].split(
|
|
1061
|
+
forKeys: matches[1].split(',').map(key => key.trim()),
|
|
864
1062
|
tableName: matches[2],
|
|
865
|
-
refKeys: matches[3].split(
|
|
866
|
-
action: matches[5] ? matches[5] :
|
|
1063
|
+
refKeys: matches[3].split(',').map(key => key.trim()),
|
|
1064
|
+
action: matches[5] ? matches[5] : 'NO ACTION',
|
|
867
1065
|
};
|
|
868
1066
|
return foreignKeyInfo;
|
|
869
1067
|
}
|
|
870
1068
|
else {
|
|
871
|
-
throw new Error(
|
|
1069
|
+
throw new Error('extractForeignKeyInfo: No FOREIGN KEY found');
|
|
872
1070
|
}
|
|
873
1071
|
}
|
|
1072
|
+
/*
|
|
1073
|
+
public extractColumnNames(whereClause: string): string[] {
|
|
1074
|
+
const regex = /\b(\w+)\s*(?=[=<>])|(?<=\()\s*(\w+),\s*(\w+)\s*(?=\))|(?<=\bIN\s*\(VALUES\s*\().*?(?=\))|(?<=\bIN\s*\().*?(?=\))|(?<=\bBETWEEN\s*).*?(?=\bAND\b)|(?<=\bLIKE\s*')\w+|\bAND\b/g;
|
|
1075
|
+
const matches = whereClause.matchAll(regex);
|
|
1076
|
+
const columnNames: string[] = [];
|
|
1077
|
+
|
|
1078
|
+
let andGroup: string[] = [];
|
|
1079
|
+
|
|
1080
|
+
for (const match of matches) {
|
|
1081
|
+
if (match[0] === 'AND') {
|
|
1082
|
+
columnNames.push(...andGroup);
|
|
1083
|
+
andGroup = [];
|
|
1084
|
+
} else if (match[1]) {
|
|
1085
|
+
andGroup.push(match[1]);
|
|
1086
|
+
} else if (match[2] && match[3]) {
|
|
1087
|
+
andGroup.push(match[2]);
|
|
1088
|
+
andGroup.push(match[3]);
|
|
1089
|
+
} else if (match[0]) {
|
|
1090
|
+
const values = match[0]
|
|
1091
|
+
.replace(/[()']/g, '') // Remove parentheses and single quotes
|
|
1092
|
+
.split(',')
|
|
1093
|
+
.map(value => value.trim());
|
|
1094
|
+
andGroup.push(...values);
|
|
1095
|
+
}
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
columnNames.push(...andGroup);
|
|
1099
|
+
|
|
1100
|
+
return columnNames;
|
|
1101
|
+
}
|
|
1102
|
+
*/
|
|
874
1103
|
extractColumnNames(whereClause) {
|
|
875
|
-
const
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
}
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1104
|
+
const keywords = new Set([
|
|
1105
|
+
'AND',
|
|
1106
|
+
'OR',
|
|
1107
|
+
'IN',
|
|
1108
|
+
'VALUES',
|
|
1109
|
+
'LIKE',
|
|
1110
|
+
'BETWEEN',
|
|
1111
|
+
'NOT',
|
|
1112
|
+
]);
|
|
1113
|
+
const tokens = whereClause.split(/(\s|,|\(|\))/).filter(item => item !== ' ');
|
|
1114
|
+
const columns = [];
|
|
1115
|
+
let inClause = false;
|
|
1116
|
+
let inValues = false;
|
|
1117
|
+
for (const token of tokens) {
|
|
1118
|
+
if (token === 'IN') {
|
|
1119
|
+
inClause = true;
|
|
1120
|
+
}
|
|
1121
|
+
else if (inClause && token === '(') {
|
|
1122
|
+
inValues = true;
|
|
1123
|
+
}
|
|
1124
|
+
else if (inValues && token === ')') {
|
|
1125
|
+
inValues = false;
|
|
1126
|
+
}
|
|
1127
|
+
else if (token.match(/\b[a-zA-Z]\w*\b/) &&
|
|
1128
|
+
!inValues &&
|
|
1129
|
+
!keywords.has(token.toUpperCase())) {
|
|
1130
|
+
if (token.length > 0) {
|
|
1131
|
+
columns.push(token);
|
|
1132
|
+
}
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
return Array.from(new Set(columns));
|
|
901
1136
|
}
|
|
902
1137
|
flattenMultilineString(input) {
|
|
903
1138
|
const lines = input.split(/\r?\n/);
|
|
904
|
-
return lines.join(
|
|
1139
|
+
return lines.join(' ');
|
|
905
1140
|
}
|
|
906
1141
|
getStmtAndRetColNames(sqlStmt, retMode) {
|
|
907
|
-
const retWord =
|
|
908
|
-
const retStmtNames = {
|
|
1142
|
+
const retWord = 'RETURNING';
|
|
1143
|
+
const retStmtNames = {
|
|
1144
|
+
stmt: sqlStmt,
|
|
1145
|
+
names: '',
|
|
1146
|
+
};
|
|
909
1147
|
const retWordIndex = sqlStmt.toUpperCase().indexOf(retWord);
|
|
910
1148
|
if (retWordIndex !== -1) {
|
|
911
1149
|
const prefix = sqlStmt.substring(0, retWordIndex);
|
|
912
1150
|
retStmtNames.stmt = `${prefix};`;
|
|
913
|
-
if (retMode.substring(0, 2) ===
|
|
1151
|
+
if (retMode.substring(0, 2) === 'wA') {
|
|
914
1152
|
const suffix = sqlStmt.substring(retWordIndex + retWord.length);
|
|
915
1153
|
const names = suffix.trim();
|
|
916
|
-
if (names.endsWith(
|
|
1154
|
+
if (names.endsWith(';')) {
|
|
917
1155
|
retStmtNames.names = names.substring(0, names.length - 1);
|
|
918
1156
|
}
|
|
919
1157
|
else {
|
|
@@ -930,7 +1168,7 @@ class UtilsSQLStatement {
|
|
|
930
1168
|
const primaryKeySets = [];
|
|
931
1169
|
for (const match of matches) {
|
|
932
1170
|
const keysString = match[1].trim();
|
|
933
|
-
const keys = keysString.split(
|
|
1171
|
+
const keys = keysString.split(',').map(key => key.trim());
|
|
934
1172
|
primaryKeySets.push(keys);
|
|
935
1173
|
}
|
|
936
1174
|
return primaryKeySets.length === 0 ? null : primaryKeySets;
|
|
@@ -938,7 +1176,7 @@ class UtilsSQLStatement {
|
|
|
938
1176
|
getWhereStmtForCombinedPK(whStmt, withRefs, colNames, keys) {
|
|
939
1177
|
let retWhere = whStmt;
|
|
940
1178
|
for (const grpKeys of keys) {
|
|
941
|
-
const repKeys = grpKeys.join(
|
|
1179
|
+
const repKeys = grpKeys.join(',') === withRefs.join(',') ? colNames : withRefs;
|
|
942
1180
|
for (const [index, key] of grpKeys.entries()) {
|
|
943
1181
|
retWhere = this.replaceAllString(retWhere, key, repKeys[index]);
|
|
944
1182
|
}
|
|
@@ -959,20 +1197,20 @@ class UtilsSQLStatement {
|
|
|
959
1197
|
return indices;
|
|
960
1198
|
}
|
|
961
1199
|
getWhereStmtForNonCombinedPK(whStmt, withRefs, colNames) {
|
|
962
|
-
let whereStmt =
|
|
1200
|
+
let whereStmt = '';
|
|
963
1201
|
let stmt = whStmt.substring(6);
|
|
964
1202
|
for (let idx = 0; idx < withRefs.length; idx++) {
|
|
965
|
-
let colType =
|
|
1203
|
+
let colType = 'withRefsNames';
|
|
966
1204
|
let idxs = this.indicesOf(stmt, withRefs[idx]);
|
|
967
1205
|
if (idxs.length === 0) {
|
|
968
1206
|
idxs = this.indicesOf(stmt, colNames[idx]);
|
|
969
|
-
colType =
|
|
1207
|
+
colType = 'colNames';
|
|
970
1208
|
}
|
|
971
1209
|
if (idxs.length > 0) {
|
|
972
|
-
let valStr =
|
|
973
|
-
const indicesEqual = this.indicesOf(stmt,
|
|
1210
|
+
let valStr = '';
|
|
1211
|
+
const indicesEqual = this.indicesOf(stmt, '=', idxs[0]);
|
|
974
1212
|
if (indicesEqual.length > 0) {
|
|
975
|
-
const indicesAnd = this.indicesOf(stmt,
|
|
1213
|
+
const indicesAnd = this.indicesOf(stmt, 'AND', indicesEqual[0]);
|
|
976
1214
|
if (indicesAnd.length > 0) {
|
|
977
1215
|
valStr = stmt.substring(indicesEqual[0] + 1, indicesAnd[0] - 1);
|
|
978
1216
|
stmt = stmt.substring(indicesAnd[0] + 3);
|
|
@@ -981,26 +1219,26 @@ class UtilsSQLStatement {
|
|
|
981
1219
|
valStr = stmt.substring(indicesEqual[0] + 1);
|
|
982
1220
|
}
|
|
983
1221
|
if (idx > 0) {
|
|
984
|
-
whereStmt +=
|
|
1222
|
+
whereStmt += ' AND ';
|
|
985
1223
|
}
|
|
986
|
-
if (colType ===
|
|
987
|
-
whereStmt += colNames[idx] +
|
|
1224
|
+
if (colType === 'withRefsNames') {
|
|
1225
|
+
whereStmt += colNames[idx] + ' = ' + valStr;
|
|
988
1226
|
}
|
|
989
1227
|
else {
|
|
990
|
-
whereStmt += withRefs[idx] +
|
|
1228
|
+
whereStmt += withRefs[idx] + ' = ' + valStr;
|
|
991
1229
|
}
|
|
992
1230
|
}
|
|
993
1231
|
}
|
|
994
1232
|
}
|
|
995
|
-
whereStmt =
|
|
1233
|
+
whereStmt = 'WHERE ' + whereStmt;
|
|
996
1234
|
return whereStmt;
|
|
997
1235
|
}
|
|
998
1236
|
updateWhere(whStmt, withRefs, colNames) {
|
|
999
|
-
let whereStmt =
|
|
1237
|
+
let whereStmt = '';
|
|
1000
1238
|
if (whStmt.length <= 0) {
|
|
1001
1239
|
return whereStmt;
|
|
1002
1240
|
}
|
|
1003
|
-
if (whStmt.toUpperCase().substring(0, 5) !==
|
|
1241
|
+
if (whStmt.toUpperCase().substring(0, 5) !== 'WHERE') {
|
|
1004
1242
|
return whereStmt;
|
|
1005
1243
|
}
|
|
1006
1244
|
if (withRefs.length === colNames.length) {
|
|
@@ -1021,6 +1259,7 @@ utilsSqlstatement.UtilsSQLStatement = UtilsSQLStatement;
|
|
|
1021
1259
|
|
|
1022
1260
|
Object.defineProperty(utilsSQLite, "__esModule", { value: true });
|
|
1023
1261
|
utilsSQLite.UtilsSQLite = void 0;
|
|
1262
|
+
const UtilsSQL92Compatibility_1$1 = UtilsSQL92Compatibility$1;
|
|
1024
1263
|
const utilsDelete_1 = utilsDelete;
|
|
1025
1264
|
const utilsFile_1$4 = utilsFile;
|
|
1026
1265
|
const utilsSqlstatement_1 = utilsSqlstatement;
|
|
@@ -1030,7 +1269,8 @@ class UtilsSQLite {
|
|
|
1030
1269
|
this.fileUtil = new utilsFile_1$4.UtilsFile();
|
|
1031
1270
|
this.statUtil = new utilsSqlstatement_1.UtilsSQLStatement();
|
|
1032
1271
|
this.delUtil = new utilsDelete_1.UtilsDelete();
|
|
1033
|
-
this.
|
|
1272
|
+
this.sql92Utils = new UtilsSQL92Compatibility_1$1.UtilsSQL92Compatibility();
|
|
1273
|
+
this.BCSQLite3 = require$$4__default$1["default"];
|
|
1034
1274
|
}
|
|
1035
1275
|
/**
|
|
1036
1276
|
* OpenOrCreateDatabase
|
|
@@ -1315,7 +1555,7 @@ class UtilsSQLite {
|
|
|
1315
1555
|
* @param mDB
|
|
1316
1556
|
* @param sql
|
|
1317
1557
|
*/
|
|
1318
|
-
execute(mDB, sql, fromJson) {
|
|
1558
|
+
execute(mDB, sql, fromJson, isSQL92) {
|
|
1319
1559
|
const result = { changes: 0, lastId: -1 };
|
|
1320
1560
|
const msg = 'Execute';
|
|
1321
1561
|
let changes = -1;
|
|
@@ -1324,11 +1564,8 @@ class UtilsSQLite {
|
|
|
1324
1564
|
try {
|
|
1325
1565
|
initChanges = this.dbChanges(mDB);
|
|
1326
1566
|
let sqlStmt = sql;
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
sql.toLowerCase().includes('UPDATE'.toLowerCase())) {
|
|
1330
|
-
sqlStmt = this.checkStatements(mDB, sql, fromJson);
|
|
1331
|
-
}
|
|
1567
|
+
// modify sql to sql92 compatible
|
|
1568
|
+
sqlStmt = this.statementsToSQL92(mDB, sql, fromJson, isSQL92);
|
|
1332
1569
|
this.execDB(mDB, sqlStmt);
|
|
1333
1570
|
changes = this.dbChanges(mDB) - initChanges;
|
|
1334
1571
|
lastId = this.getLastId(mDB);
|
|
@@ -1341,7 +1578,7 @@ class UtilsSQLite {
|
|
|
1341
1578
|
throw new Error(`${msg} ${errmsg}`);
|
|
1342
1579
|
}
|
|
1343
1580
|
}
|
|
1344
|
-
|
|
1581
|
+
statementsToSQL92(mDB, sql, fromJson, isSQL92) {
|
|
1345
1582
|
// split the statements in an array of statement
|
|
1346
1583
|
let sqlStmt = sql.replace(/\n/g, '');
|
|
1347
1584
|
// deal with trigger
|
|
@@ -1351,11 +1588,10 @@ class UtilsSQLite {
|
|
|
1351
1588
|
const resArr = [];
|
|
1352
1589
|
// loop through the statement
|
|
1353
1590
|
for (const stmt of sqlStmts) {
|
|
1354
|
-
|
|
1355
|
-
|
|
1591
|
+
let rStmt = stmt.trim();
|
|
1592
|
+
const method = rStmt
|
|
1356
1593
|
.substring(0, Math.min(stmt.trim().length, 6))
|
|
1357
1594
|
.toUpperCase();
|
|
1358
|
-
let rStmt = stmt.trim();
|
|
1359
1595
|
switch (method) {
|
|
1360
1596
|
case 'CREATE':
|
|
1361
1597
|
if (rStmt.includes('&END')) {
|
|
@@ -1363,24 +1599,29 @@ class UtilsSQLite {
|
|
|
1363
1599
|
}
|
|
1364
1600
|
break;
|
|
1365
1601
|
case 'DELETE':
|
|
1366
|
-
if (!fromJson &&
|
|
1367
|
-
|
|
1602
|
+
if (!fromJson && rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1603
|
+
let whereStmt = rStmt;
|
|
1604
|
+
if (!isSQL92)
|
|
1605
|
+
whereStmt = this.cleanStatement(rStmt);
|
|
1368
1606
|
rStmt = this.deleteSQL(mDB, whereStmt, []);
|
|
1369
1607
|
}
|
|
1370
1608
|
break;
|
|
1371
1609
|
case 'INSERT':
|
|
1372
|
-
if (
|
|
1373
|
-
|
|
1610
|
+
if (rStmt.toLowerCase().includes('VALUES'.toLowerCase())) {
|
|
1611
|
+
if (!isSQL92)
|
|
1612
|
+
rStmt = this.cleanStatement(rStmt);
|
|
1374
1613
|
}
|
|
1375
1614
|
break;
|
|
1376
1615
|
case 'UPDATE':
|
|
1377
|
-
if (
|
|
1378
|
-
|
|
1616
|
+
if (rStmt.toLowerCase().includes('SET'.toLowerCase())) {
|
|
1617
|
+
if (!isSQL92)
|
|
1618
|
+
rStmt = this.cleanStatement(`${stmt.trim()}`);
|
|
1379
1619
|
}
|
|
1380
1620
|
break;
|
|
1381
1621
|
case 'SELECT':
|
|
1382
|
-
if (!fromJson &&
|
|
1383
|
-
|
|
1622
|
+
if (!fromJson && rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1623
|
+
if (!isSQL92)
|
|
1624
|
+
rStmt = this.cleanStatement(rStmt);
|
|
1384
1625
|
}
|
|
1385
1626
|
break;
|
|
1386
1627
|
}
|
|
@@ -1411,7 +1652,7 @@ class UtilsSQLite {
|
|
|
1411
1652
|
* @param set
|
|
1412
1653
|
* @param fromJson
|
|
1413
1654
|
*/
|
|
1414
|
-
executeSet(mDB, set, fromJson, returnMode) {
|
|
1655
|
+
executeSet(mDB, set, fromJson, returnMode, isSQL92) {
|
|
1415
1656
|
const ret = { changes: 0, lastId: -1, values: [] };
|
|
1416
1657
|
let result = { changes: 0, lastId: -1 };
|
|
1417
1658
|
const msg = 'ExecuteSet';
|
|
@@ -1442,7 +1683,11 @@ class UtilsSQLite {
|
|
|
1442
1683
|
result = this.prepareRun(mDB, statement, mVal, fromJson, returnMode);
|
|
1443
1684
|
}
|
|
1444
1685
|
else {
|
|
1445
|
-
|
|
1686
|
+
let nStatement = statement;
|
|
1687
|
+
if (!isSQL92) {
|
|
1688
|
+
nStatement = this.cleanStatement(statement);
|
|
1689
|
+
}
|
|
1690
|
+
result = this.prepareRun(mDB, nStatement, [], fromJson, returnMode);
|
|
1446
1691
|
}
|
|
1447
1692
|
ret.changes += result.changes;
|
|
1448
1693
|
ret.lastId = result.lastId;
|
|
@@ -1465,6 +1710,7 @@ class UtilsSQLite {
|
|
|
1465
1710
|
* @param statement
|
|
1466
1711
|
* @param values
|
|
1467
1712
|
* @param fromJson
|
|
1713
|
+
* @param returnMode
|
|
1468
1714
|
*/
|
|
1469
1715
|
prepareRun(mDB, statement, values, fromJson, returnMode) {
|
|
1470
1716
|
const result = { changes: 0, lastId: -1 };
|
|
@@ -1512,8 +1758,7 @@ class UtilsSQLite {
|
|
|
1512
1758
|
let result = { changes: 0, lastInsertRowid: -1, values: [] };
|
|
1513
1759
|
const msg = 'runExec: ';
|
|
1514
1760
|
try {
|
|
1515
|
-
const
|
|
1516
|
-
const params = this.getStmtAndNames(cStmt, returnMode);
|
|
1761
|
+
const params = this.getStmtAndNames(stmt, returnMode);
|
|
1517
1762
|
switch (params.mMode) {
|
|
1518
1763
|
case 'one': {
|
|
1519
1764
|
const iniChanges = this.dbChanges(mDB);
|
|
@@ -1528,7 +1773,7 @@ class UtilsSQLite {
|
|
|
1528
1773
|
const res = statement.run(values);
|
|
1529
1774
|
result.lastInsertRowid = res.lastInsertRowid;
|
|
1530
1775
|
const sql = `SELECT ${params.names} FROM ${params.tableName} WHERE rowid = ${lowerId};`;
|
|
1531
|
-
const value = this.queryOne(mDB, sql, []);
|
|
1776
|
+
const value = this.queryOne(mDB, sql, [], true);
|
|
1532
1777
|
result.values.push(value);
|
|
1533
1778
|
}
|
|
1534
1779
|
result.changes = this.dbChanges(mDB) - iniChanges;
|
|
@@ -1546,7 +1791,7 @@ class UtilsSQLite {
|
|
|
1546
1791
|
const res = statement.run(values);
|
|
1547
1792
|
const upperId = res.lastInsertRowid;
|
|
1548
1793
|
const sql = `SELECT ${params.names} FROM ${params.tableName} WHERE rowid BETWEEN ${lowerId} AND ${upperId};`;
|
|
1549
|
-
result.values = this.queryAll(mDB, sql, []);
|
|
1794
|
+
result.values = this.queryAll(mDB, sql, [], true);
|
|
1550
1795
|
result.lastInsertRowid = res.lastInsertRowid;
|
|
1551
1796
|
}
|
|
1552
1797
|
result.changes = this.dbChanges(mDB) - iniChanges;
|
|
@@ -1675,7 +1920,7 @@ class UtilsSQLite {
|
|
|
1675
1920
|
// Get the column names
|
|
1676
1921
|
const colNames = foreignKeyInfo.refKeys;
|
|
1677
1922
|
if (colNames.length !== withRefsNames.length) {
|
|
1678
|
-
const msg =
|
|
1923
|
+
const msg = 'findReferencesAndUpdate: mismatch length';
|
|
1679
1924
|
throw new Error(msg);
|
|
1680
1925
|
}
|
|
1681
1926
|
const action = foreignKeyInfo.action;
|
|
@@ -1712,8 +1957,7 @@ class UtilsSQLite {
|
|
|
1712
1957
|
else {
|
|
1713
1958
|
throw new Error('Not implemented. Please transfer your example to the maintener');
|
|
1714
1959
|
}
|
|
1715
|
-
if (results.setStmt.length > 0 &&
|
|
1716
|
-
results.uWhereStmt.length > 0) {
|
|
1960
|
+
if (results.setStmt.length > 0 && results.uWhereStmt.length > 0) {
|
|
1717
1961
|
this.executeUpdateForDelete(mDB, updTableName, results.uWhereStmt, results.setStmt, updColNames, values);
|
|
1718
1962
|
}
|
|
1719
1963
|
}
|
|
@@ -1731,14 +1975,16 @@ class UtilsSQLite {
|
|
|
1731
1975
|
* @returns
|
|
1732
1976
|
*/
|
|
1733
1977
|
getReferences(db, tableName) {
|
|
1734
|
-
const sqlStmt =
|
|
1978
|
+
const sqlStmt = 'SELECT sql FROM sqlite_master ' +
|
|
1735
1979
|
"WHERE sql LIKE('%FOREIGN KEY%') AND sql LIKE('%REFERENCES%') AND " +
|
|
1736
|
-
"sql LIKE('%" +
|
|
1980
|
+
"sql LIKE('%" +
|
|
1981
|
+
tableName +
|
|
1982
|
+
"%') AND sql LIKE('%ON DELETE%');";
|
|
1737
1983
|
try {
|
|
1738
|
-
const res = this.queryAll(db, sqlStmt, []);
|
|
1984
|
+
const res = this.queryAll(db, sqlStmt, [], true);
|
|
1739
1985
|
// get the reference's string(s)
|
|
1740
1986
|
let retRefs = [];
|
|
1741
|
-
let tableWithRefs =
|
|
1987
|
+
let tableWithRefs = '';
|
|
1742
1988
|
if (res.length > 0) {
|
|
1743
1989
|
const result = this.getRefs(res[0].sql);
|
|
1744
1990
|
retRefs = result.foreignKeys;
|
|
@@ -1812,7 +2058,7 @@ class UtilsSQLite {
|
|
|
1812
2058
|
}
|
|
1813
2059
|
}
|
|
1814
2060
|
const retObj = this.runExec(mDB, stmt, selValues, 'no');
|
|
1815
|
-
lastId = retObj[
|
|
2061
|
+
lastId = retObj['lastInsertRowid'];
|
|
1816
2062
|
if (lastId === -1) {
|
|
1817
2063
|
const msg = `UPDATE sql_deleted failed for table: ${tableName}`;
|
|
1818
2064
|
throw new Error(msg);
|
|
@@ -1829,11 +2075,24 @@ class UtilsSQLite {
|
|
|
1829
2075
|
* @param sql
|
|
1830
2076
|
* @param values
|
|
1831
2077
|
*/
|
|
1832
|
-
queryAll(mDB, sql, values) {
|
|
2078
|
+
queryAll(mDB, sql, values, isSQL92) {
|
|
1833
2079
|
const msg = 'QueryAll';
|
|
1834
2080
|
try {
|
|
1835
|
-
|
|
2081
|
+
let cSql = sql;
|
|
2082
|
+
if (!isSQL92) {
|
|
2083
|
+
cSql = this.cleanStatement(sql);
|
|
2084
|
+
}
|
|
1836
2085
|
const stmt = mDB.prepare(cSql);
|
|
2086
|
+
if (!stmt.reader) {
|
|
2087
|
+
// statement doesn't returns data
|
|
2088
|
+
if (values != null && values.length > 0) {
|
|
2089
|
+
stmt.run(values);
|
|
2090
|
+
}
|
|
2091
|
+
else {
|
|
2092
|
+
stmt.run();
|
|
2093
|
+
}
|
|
2094
|
+
return [];
|
|
2095
|
+
}
|
|
1837
2096
|
let rows;
|
|
1838
2097
|
if (values != null && values.length > 0) {
|
|
1839
2098
|
rows = stmt.all(values);
|
|
@@ -1857,10 +2116,13 @@ class UtilsSQLite {
|
|
|
1857
2116
|
* @param sql
|
|
1858
2117
|
* @param values
|
|
1859
2118
|
*/
|
|
1860
|
-
queryOne(mDB, sql, values) {
|
|
2119
|
+
queryOne(mDB, sql, values, isSQL92) {
|
|
1861
2120
|
const msg = 'QueryOne';
|
|
1862
2121
|
try {
|
|
1863
|
-
|
|
2122
|
+
let cSql = sql;
|
|
2123
|
+
if (!isSQL92) {
|
|
2124
|
+
cSql = this.cleanStatement(sql);
|
|
2125
|
+
}
|
|
1864
2126
|
const stmt = mDB.prepare(cSql);
|
|
1865
2127
|
let row;
|
|
1866
2128
|
if (values != null && values.length > 0) {
|
|
@@ -1889,7 +2151,7 @@ class UtilsSQLite {
|
|
|
1889
2151
|
sql += 'ORDER BY rootpage DESC;';
|
|
1890
2152
|
const retArr = [];
|
|
1891
2153
|
try {
|
|
1892
|
-
const retQuery = this.queryAll(mDb, sql, []);
|
|
2154
|
+
const retQuery = this.queryAll(mDb, sql, [], true);
|
|
1893
2155
|
for (const query of retQuery) {
|
|
1894
2156
|
retArr.push(query.name);
|
|
1895
2157
|
}
|
|
@@ -1911,7 +2173,7 @@ class UtilsSQLite {
|
|
|
1911
2173
|
sql += 'ORDER BY rootpage DESC;';
|
|
1912
2174
|
const retArr = [];
|
|
1913
2175
|
try {
|
|
1914
|
-
const retQuery = this.queryAll(mDb, sql, []);
|
|
2176
|
+
const retQuery = this.queryAll(mDb, sql, [], true);
|
|
1915
2177
|
for (const query of retQuery) {
|
|
1916
2178
|
retArr.push(query.name);
|
|
1917
2179
|
}
|
|
@@ -2042,31 +2304,25 @@ class UtilsSQLite {
|
|
|
2042
2304
|
}
|
|
2043
2305
|
searchForRelatedItems(mDB, updTableName, tableName, whStmt, withRefsNames, colNames, values) {
|
|
2044
2306
|
const relatedItems = [];
|
|
2045
|
-
let key =
|
|
2046
|
-
const t1Names = withRefsNames.map(
|
|
2047
|
-
const t2Names = colNames.map(
|
|
2048
|
-
console.log(" whStmt ", whStmt);
|
|
2049
|
-
console.log(" t1Names ", t1Names);
|
|
2050
|
-
console.log(" t2Names ", t2Names);
|
|
2307
|
+
let key = '';
|
|
2308
|
+
const t1Names = withRefsNames.map(name => `t1.${name}`);
|
|
2309
|
+
const t2Names = colNames.map(name => `t2.${name}`);
|
|
2051
2310
|
try {
|
|
2052
2311
|
// addPrefix to the whereClause and swap colNames with withRefsNames
|
|
2053
|
-
let whereClause = this.statUtil
|
|
2054
|
-
.addPrefixToWhereClause(whStmt, colNames, withRefsNames, "t2.");
|
|
2312
|
+
let whereClause = this.statUtil.addPrefixToWhereClause(whStmt, colNames, withRefsNames, 't2.');
|
|
2055
2313
|
// look at the whereclause and change colNames with withRefsNames
|
|
2056
|
-
if (whereClause.endsWith(
|
|
2314
|
+
if (whereClause.endsWith(';')) {
|
|
2057
2315
|
whereClause = whereClause.slice(0, -1);
|
|
2058
2316
|
}
|
|
2059
|
-
console.log(" whereClause ", whereClause);
|
|
2060
2317
|
const resultString = t1Names
|
|
2061
2318
|
.map((t1, index) => `${t1} = ${t2Names[index]}`)
|
|
2062
|
-
.join(
|
|
2319
|
+
.join(' AND ');
|
|
2063
2320
|
const sql = `SELECT t1.rowid FROM ${updTableName} t1 ` +
|
|
2064
2321
|
`JOIN ${tableName} t2 ON ${resultString} ` +
|
|
2065
2322
|
`WHERE ${whereClause} AND t1.sql_deleted = 0;`;
|
|
2066
|
-
|
|
2067
|
-
const vals = this.queryAll(mDB, sql, values);
|
|
2323
|
+
const vals = this.queryAll(mDB, sql, values, true);
|
|
2068
2324
|
if (vals.length > 0) {
|
|
2069
|
-
key =
|
|
2325
|
+
key = Object.keys(vals[0])[0];
|
|
2070
2326
|
relatedItems.push(...vals);
|
|
2071
2327
|
}
|
|
2072
2328
|
return { key: key, relatedItems: relatedItems };
|
|
@@ -2084,7 +2340,7 @@ class UtilsSQLite {
|
|
|
2084
2340
|
stmt.toLowerCase().includes('DELETE FROM'.toLowerCase())) {
|
|
2085
2341
|
// check for JSON string
|
|
2086
2342
|
sql = this.dealJsonString(stmt);
|
|
2087
|
-
sql =
|
|
2343
|
+
sql = this.sql92Utils.compatibleSQL92(sql);
|
|
2088
2344
|
sql = sql.replaceAll('§', '"');
|
|
2089
2345
|
}
|
|
2090
2346
|
else {
|
|
@@ -2178,7 +2434,7 @@ class UtilsJson {
|
|
|
2178
2434
|
}
|
|
2179
2435
|
let query = 'SELECT name FROM sqlite_master WHERE ';
|
|
2180
2436
|
query += `type='table' AND name='${tableName}';`;
|
|
2181
|
-
const rows = this.sqliteUtil.queryAll(mDB, query, []);
|
|
2437
|
+
const rows = this.sqliteUtil.queryAll(mDB, query, [], true);
|
|
2182
2438
|
if (rows.length > 0) {
|
|
2183
2439
|
ret = true;
|
|
2184
2440
|
}
|
|
@@ -2198,7 +2454,7 @@ class UtilsJson {
|
|
|
2198
2454
|
}
|
|
2199
2455
|
let query = 'SELECT name FROM sqlite_master WHERE ';
|
|
2200
2456
|
query += `type='view' AND name='${viewName}';`;
|
|
2201
|
-
const rows = this.sqliteUtil.queryAll(mDB, query, []);
|
|
2457
|
+
const rows = this.sqliteUtil.queryAll(mDB, query, [], true);
|
|
2202
2458
|
if (rows.length > 0) {
|
|
2203
2459
|
ret = true;
|
|
2204
2460
|
}
|
|
@@ -2215,7 +2471,8 @@ class UtilsJson {
|
|
|
2215
2471
|
let changes = 0;
|
|
2216
2472
|
try {
|
|
2217
2473
|
// start a transaction
|
|
2218
|
-
this.sqliteUtil.beginTransaction(mDB, true);
|
|
2474
|
+
this.sqliteUtil.beginTransaction(mDB.database, true);
|
|
2475
|
+
mDB.setIsTransActive(true);
|
|
2219
2476
|
}
|
|
2220
2477
|
catch (err) {
|
|
2221
2478
|
throw new Error(`${msg} ${err}`);
|
|
@@ -2224,11 +2481,12 @@ class UtilsJson {
|
|
|
2224
2481
|
if (stmts.length > 0) {
|
|
2225
2482
|
const schemaStmt = stmts.join('\n');
|
|
2226
2483
|
try {
|
|
2227
|
-
const results = this.sqliteUtil.execute(mDB, schemaStmt, true);
|
|
2484
|
+
const results = this.sqliteUtil.execute(mDB.database, schemaStmt, true, true);
|
|
2228
2485
|
changes = results.changes;
|
|
2229
2486
|
if (changes < 0) {
|
|
2230
2487
|
try {
|
|
2231
|
-
this.sqliteUtil.rollbackTransaction(mDB, true);
|
|
2488
|
+
this.sqliteUtil.rollbackTransaction(mDB.database, true);
|
|
2489
|
+
mDB.setIsTransActive(false);
|
|
2232
2490
|
}
|
|
2233
2491
|
catch (err) {
|
|
2234
2492
|
throw new Error(`${msg} changes < 0 ${err}`);
|
|
@@ -2238,7 +2496,8 @@ class UtilsJson {
|
|
|
2238
2496
|
catch (err) {
|
|
2239
2497
|
const msg = err;
|
|
2240
2498
|
try {
|
|
2241
|
-
this.sqliteUtil.rollbackTransaction(mDB, true);
|
|
2499
|
+
this.sqliteUtil.rollbackTransaction(mDB.database, true);
|
|
2500
|
+
mDB.setIsTransActive(false);
|
|
2242
2501
|
throw new Error(`CreateSchema: ${msg}`);
|
|
2243
2502
|
}
|
|
2244
2503
|
catch (err) {
|
|
@@ -2247,7 +2506,8 @@ class UtilsJson {
|
|
|
2247
2506
|
}
|
|
2248
2507
|
}
|
|
2249
2508
|
try {
|
|
2250
|
-
this.sqliteUtil.commitTransaction(mDB, true);
|
|
2509
|
+
this.sqliteUtil.commitTransaction(mDB.database, true);
|
|
2510
|
+
mDB.setIsTransActive(false);
|
|
2251
2511
|
return changes;
|
|
2252
2512
|
}
|
|
2253
2513
|
catch (err) {
|
|
@@ -2532,7 +2792,7 @@ class UtilsJson {
|
|
|
2532
2792
|
else {
|
|
2533
2793
|
throw new Error(`${msg} Table ${tableName} no names`);
|
|
2534
2794
|
}
|
|
2535
|
-
const retValues = this.sqliteUtil.queryAll(mDb, query, []);
|
|
2795
|
+
const retValues = this.sqliteUtil.queryAll(mDb, query, [], true);
|
|
2536
2796
|
for (const rValue of retValues) {
|
|
2537
2797
|
const row = [];
|
|
2538
2798
|
for (const rName of rowNames) {
|
|
@@ -2611,7 +2871,7 @@ class UtilsJson {
|
|
|
2611
2871
|
if (typeof key === 'string')
|
|
2612
2872
|
query += `'${key}';`;
|
|
2613
2873
|
try {
|
|
2614
|
-
const resQuery = this.sqliteUtil.queryAll(mDB, query, []);
|
|
2874
|
+
const resQuery = this.sqliteUtil.queryAll(mDB, query, [], true);
|
|
2615
2875
|
if (resQuery.length === 1)
|
|
2616
2876
|
ret = true;
|
|
2617
2877
|
return ret;
|
|
@@ -2985,7 +3245,7 @@ class UtilsJson {
|
|
|
2985
3245
|
const msg = 'CreateView';
|
|
2986
3246
|
const stmt = `CREATE VIEW IF NOT EXISTS ${view.name} AS ${view.value};`;
|
|
2987
3247
|
try {
|
|
2988
|
-
const results = this.sqliteUtil.execute(mDB, stmt, true);
|
|
3248
|
+
const results = this.sqliteUtil.execute(mDB, stmt, true, true);
|
|
2989
3249
|
if (results.changes < 0) {
|
|
2990
3250
|
throw new Error(`${msg} ${view.name} failed`);
|
|
2991
3251
|
}
|
|
@@ -3077,7 +3337,7 @@ class ExportToJson {
|
|
|
3077
3337
|
sql += "AND name NOT LIKE 'sqlite_%';";
|
|
3078
3338
|
let retQuery = [];
|
|
3079
3339
|
try {
|
|
3080
|
-
retQuery = this.sqliteUtil.queryAll(mDb, sql, []);
|
|
3340
|
+
retQuery = this.sqliteUtil.queryAll(mDb, sql, [], true);
|
|
3081
3341
|
return retQuery;
|
|
3082
3342
|
}
|
|
3083
3343
|
catch (err) {
|
|
@@ -3090,7 +3350,7 @@ class ExportToJson {
|
|
|
3090
3350
|
try {
|
|
3091
3351
|
// get the last sync date
|
|
3092
3352
|
const stmt = `SELECT sync_date FROM sync_table WHERE id = ?;`;
|
|
3093
|
-
const row = this.sqliteUtil.queryOne(mDb, stmt, [2]);
|
|
3353
|
+
const row = this.sqliteUtil.queryOne(mDb, stmt, [2], true);
|
|
3094
3354
|
if (row != null) {
|
|
3095
3355
|
const key = Object.keys(row)[0];
|
|
3096
3356
|
retDate = row[key];
|
|
@@ -3122,7 +3382,7 @@ class ExportToJson {
|
|
|
3122
3382
|
else {
|
|
3123
3383
|
stmt = `INSERT INTO sync_table (sync_date) VALUES (${sDate});`;
|
|
3124
3384
|
}
|
|
3125
|
-
const results = this.sqliteUtil.execute(mDb, stmt, false);
|
|
3385
|
+
const results = this.sqliteUtil.execute(mDb, stmt, false, true);
|
|
3126
3386
|
if (results.changes < 0) {
|
|
3127
3387
|
return { result: false, message: `${msg} failed` };
|
|
3128
3388
|
}
|
|
@@ -3182,7 +3442,7 @@ class ExportToJson {
|
|
|
3182
3442
|
sql += "type='view' AND name NOT LIKE 'sqlite_%';";
|
|
3183
3443
|
let retQuery = [];
|
|
3184
3444
|
try {
|
|
3185
|
-
retQuery = this.sqliteUtil.queryAll(mDb, sql, []);
|
|
3445
|
+
retQuery = this.sqliteUtil.queryAll(mDb, sql, [], true);
|
|
3186
3446
|
for (const query of retQuery) {
|
|
3187
3447
|
const view = {};
|
|
3188
3448
|
view.name = query.name;
|
|
@@ -3204,7 +3464,7 @@ class ExportToJson {
|
|
|
3204
3464
|
let retDate = -1;
|
|
3205
3465
|
// get the last sync date
|
|
3206
3466
|
const stmt = `SELECT sync_date FROM sync_table WHERE id = ?;`;
|
|
3207
|
-
const row = this.sqliteUtil.queryOne(mDb, stmt, [1]);
|
|
3467
|
+
const row = this.sqliteUtil.queryOne(mDb, stmt, [1], true);
|
|
3208
3468
|
if (row != null) {
|
|
3209
3469
|
const key = Object.keys(row)[0];
|
|
3210
3470
|
retDate = row[key];
|
|
@@ -3378,7 +3638,7 @@ class ExportToJson {
|
|
|
3378
3638
|
let stmt = 'SELECT name,tbl_name,sql FROM sqlite_master WHERE ';
|
|
3379
3639
|
stmt += `type = 'index' AND tbl_name = '${tableName}' `;
|
|
3380
3640
|
stmt += `AND sql NOTNULL;`;
|
|
3381
|
-
const retIndexes = this.sqliteUtil.queryAll(mDb, stmt, []);
|
|
3641
|
+
const retIndexes = this.sqliteUtil.queryAll(mDb, stmt, [], true);
|
|
3382
3642
|
if (retIndexes.length > 0) {
|
|
3383
3643
|
for (const rIndex of retIndexes) {
|
|
3384
3644
|
const keys = Object.keys(rIndex);
|
|
@@ -3428,7 +3688,7 @@ class ExportToJson {
|
|
|
3428
3688
|
let stmt = 'SELECT name,tbl_name,sql FROM sqlite_master WHERE ';
|
|
3429
3689
|
stmt += `type = 'trigger' AND tbl_name = '${tableName}' `;
|
|
3430
3690
|
stmt += `AND sql NOT NULL;`;
|
|
3431
|
-
const retTriggers = this.sqliteUtil.queryAll(mDb, stmt, []);
|
|
3691
|
+
const retTriggers = this.sqliteUtil.queryAll(mDb, stmt, [], true);
|
|
3432
3692
|
if (retTriggers.length > 0) {
|
|
3433
3693
|
for (const rTrg of retTriggers) {
|
|
3434
3694
|
const keys = Object.keys(rTrg);
|
|
@@ -3632,7 +3892,7 @@ class ExportToJson {
|
|
|
3632
3892
|
// get total count of the table
|
|
3633
3893
|
let stmt = 'SELECT count(*) AS tcount ';
|
|
3634
3894
|
stmt += `FROM ${rTable.name};`;
|
|
3635
|
-
let retQuery = this.sqliteUtil.queryAll(mDb, stmt, []);
|
|
3895
|
+
let retQuery = this.sqliteUtil.queryAll(mDb, stmt, [], true);
|
|
3636
3896
|
if (retQuery.length != 1) {
|
|
3637
3897
|
errmsg = `${msg} total count not returned`;
|
|
3638
3898
|
break;
|
|
@@ -3642,7 +3902,7 @@ class ExportToJson {
|
|
|
3642
3902
|
stmt = 'SELECT count(*) AS mcount FROM ';
|
|
3643
3903
|
stmt += `${rTable.name} WHERE last_modified > `;
|
|
3644
3904
|
stmt += `${syncDate};`;
|
|
3645
|
-
retQuery = this.sqliteUtil.queryAll(mDb, stmt, []);
|
|
3905
|
+
retQuery = this.sqliteUtil.queryAll(mDb, stmt, [], true);
|
|
3646
3906
|
if (retQuery.length != 1)
|
|
3647
3907
|
break;
|
|
3648
3908
|
const totalModifiedCount = retQuery[0]['mcount'];
|
|
@@ -3749,7 +4009,7 @@ class UtilsDrop {
|
|
|
3749
4009
|
let stmt = 'SELECT name FROM sqlite_master WHERE ';
|
|
3750
4010
|
stmt += `type = '${type}' ${stmt1};`;
|
|
3751
4011
|
try {
|
|
3752
|
-
const elements = this.sqliteUtil.queryAll(db, stmt, []);
|
|
4012
|
+
const elements = this.sqliteUtil.queryAll(db, stmt, [], true);
|
|
3753
4013
|
if (elements.length > 0) {
|
|
3754
4014
|
const upType = type.toUpperCase();
|
|
3755
4015
|
const statements = [];
|
|
@@ -3808,7 +4068,7 @@ class UtilsDrop {
|
|
|
3808
4068
|
statements.push(stmt);
|
|
3809
4069
|
}
|
|
3810
4070
|
try {
|
|
3811
|
-
const results = this.sqliteUtil.execute(db, statements.join('\n'), false);
|
|
4071
|
+
const results = this.sqliteUtil.execute(db, statements.join('\n'), false, true);
|
|
3812
4072
|
if (results.changes < 0) {
|
|
3813
4073
|
throw new Error('DropTempTables: changes < 0');
|
|
3814
4074
|
}
|
|
@@ -3842,10 +4102,10 @@ class ImportFromJson {
|
|
|
3842
4102
|
const version = jsonData.version;
|
|
3843
4103
|
try {
|
|
3844
4104
|
// set User Version PRAGMA
|
|
3845
|
-
this.sqliteUtil.setVersion(mDB, version);
|
|
4105
|
+
this.sqliteUtil.setVersion(mDB.database, version);
|
|
3846
4106
|
// DROP ALL when mode="full"
|
|
3847
4107
|
if (jsonData.mode === 'full') {
|
|
3848
|
-
this.dropUtil.dropAll(mDB);
|
|
4108
|
+
this.dropUtil.dropAll(mDB.database);
|
|
3849
4109
|
}
|
|
3850
4110
|
// create database schema
|
|
3851
4111
|
changes = this.jsonUtil.createSchema(mDB, jsonData);
|
|
@@ -3862,7 +4122,8 @@ class ImportFromJson {
|
|
|
3862
4122
|
let message = '';
|
|
3863
4123
|
try {
|
|
3864
4124
|
// start a transaction
|
|
3865
|
-
this.sqliteUtil.beginTransaction(mDB, true);
|
|
4125
|
+
this.sqliteUtil.beginTransaction(mDB.database, true);
|
|
4126
|
+
mDB.setIsTransActive(true);
|
|
3866
4127
|
}
|
|
3867
4128
|
catch (err) {
|
|
3868
4129
|
throw new Error(`${msg} ${err}`);
|
|
@@ -3871,7 +4132,7 @@ class ImportFromJson {
|
|
|
3871
4132
|
if (jTable.values != null && jTable.values.length >= 1) {
|
|
3872
4133
|
// Create the table's data
|
|
3873
4134
|
try {
|
|
3874
|
-
results = this.jsonUtil.createDataTable(mDB, jTable, jsonData.mode);
|
|
4135
|
+
results = this.jsonUtil.createDataTable(mDB.database, jTable, jsonData.mode);
|
|
3875
4136
|
if (results.lastId < 0)
|
|
3876
4137
|
break;
|
|
3877
4138
|
isValue = true;
|
|
@@ -3885,7 +4146,8 @@ class ImportFromJson {
|
|
|
3885
4146
|
}
|
|
3886
4147
|
if (isValue) {
|
|
3887
4148
|
try {
|
|
3888
|
-
this.sqliteUtil.commitTransaction(mDB, true);
|
|
4149
|
+
this.sqliteUtil.commitTransaction(mDB.database, true);
|
|
4150
|
+
mDB.setIsTransActive(false);
|
|
3889
4151
|
return results.changes;
|
|
3890
4152
|
}
|
|
3891
4153
|
catch (err) {
|
|
@@ -3895,7 +4157,8 @@ class ImportFromJson {
|
|
|
3895
4157
|
else {
|
|
3896
4158
|
if (message.length > 0) {
|
|
3897
4159
|
try {
|
|
3898
|
-
this.sqliteUtil.rollbackTransaction(mDB, true);
|
|
4160
|
+
this.sqliteUtil.rollbackTransaction(mDB.database, true);
|
|
4161
|
+
mDB.setIsTransActive(false);
|
|
3899
4162
|
throw new Error(`${msg} ${message}`);
|
|
3900
4163
|
}
|
|
3901
4164
|
catch (err) {
|
|
@@ -3920,7 +4183,8 @@ class ImportFromJson {
|
|
|
3920
4183
|
let results;
|
|
3921
4184
|
try {
|
|
3922
4185
|
// start a transaction
|
|
3923
|
-
this.sqliteUtil.beginTransaction(mDB, true);
|
|
4186
|
+
this.sqliteUtil.beginTransaction(mDB.database, true);
|
|
4187
|
+
mDB.setIsTransActive(true);
|
|
3924
4188
|
}
|
|
3925
4189
|
catch (err) {
|
|
3926
4190
|
throw new Error(`${msg} ${err}`);
|
|
@@ -3929,7 +4193,7 @@ class ImportFromJson {
|
|
|
3929
4193
|
if (jView.value != null) {
|
|
3930
4194
|
// Create the view
|
|
3931
4195
|
try {
|
|
3932
|
-
results = this.jsonUtil.createView(mDB, jView);
|
|
4196
|
+
results = this.jsonUtil.createView(mDB.database, jView);
|
|
3933
4197
|
isView = true;
|
|
3934
4198
|
}
|
|
3935
4199
|
catch (err) {
|
|
@@ -3941,7 +4205,8 @@ class ImportFromJson {
|
|
|
3941
4205
|
}
|
|
3942
4206
|
if (isView) {
|
|
3943
4207
|
try {
|
|
3944
|
-
this.sqliteUtil.commitTransaction(mDB, true);
|
|
4208
|
+
this.sqliteUtil.commitTransaction(mDB.database, true);
|
|
4209
|
+
mDB.setIsTransActive(false);
|
|
3945
4210
|
return results.changes;
|
|
3946
4211
|
}
|
|
3947
4212
|
catch (err) {
|
|
@@ -3951,7 +4216,8 @@ class ImportFromJson {
|
|
|
3951
4216
|
else {
|
|
3952
4217
|
if (message.length > 0) {
|
|
3953
4218
|
try {
|
|
3954
|
-
this.sqliteUtil.rollbackTransaction(mDB, true);
|
|
4219
|
+
this.sqliteUtil.rollbackTransaction(mDB.database, true);
|
|
4220
|
+
mDB.setIsTransActive(false);
|
|
3955
4221
|
throw new Error(`${msg} ${message}`);
|
|
3956
4222
|
}
|
|
3957
4223
|
catch (err) {
|
|
@@ -3981,7 +4247,7 @@ class UtilsSecret {
|
|
|
3981
4247
|
this.globalUtil = new GlobalSQLite_1$2.GlobalSQLite();
|
|
3982
4248
|
this.sqliteUtil = new utilsSQLite_1$4.UtilsSQLite();
|
|
3983
4249
|
this.fileUtil = new utilsFile_1$3.UtilsFile();
|
|
3984
|
-
this.storage = require$$3__default$
|
|
4250
|
+
this.storage = require$$3__default$1["default"];
|
|
3985
4251
|
}
|
|
3986
4252
|
isSecretStored() {
|
|
3987
4253
|
const secret = this.getPassphrase();
|
|
@@ -4226,13 +4492,13 @@ class UtilsUpgrade {
|
|
|
4226
4492
|
}
|
|
4227
4493
|
try {
|
|
4228
4494
|
// set Foreign Keys Off
|
|
4229
|
-
|
|
4230
|
-
const initChanges =
|
|
4495
|
+
this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB.database, false);
|
|
4496
|
+
const initChanges = this.sqliteUtil.dbChanges(mDB.database);
|
|
4231
4497
|
await this.executeStatementsProcess(mDB, statements);
|
|
4232
|
-
|
|
4498
|
+
this.sqliteUtil.setVersion(mDB.database, versionKey);
|
|
4233
4499
|
// set Foreign Keys On
|
|
4234
|
-
|
|
4235
|
-
changes = (await this.sqliteUtil.dbChanges(mDB)) - initChanges;
|
|
4500
|
+
this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB.database, true);
|
|
4501
|
+
changes = (await this.sqliteUtil.dbChanges(mDB.database)) - initChanges;
|
|
4236
4502
|
}
|
|
4237
4503
|
catch (err) {
|
|
4238
4504
|
return Promise.reject(`onUpgrade: ${err}`);
|
|
@@ -4248,15 +4514,18 @@ class UtilsUpgrade {
|
|
|
4248
4514
|
*/
|
|
4249
4515
|
async executeStatementsProcess(mDB, statements) {
|
|
4250
4516
|
try {
|
|
4251
|
-
|
|
4517
|
+
this.sqliteUtil.beginTransaction(mDB.database, true);
|
|
4518
|
+
mDB.setIsTransActive(true);
|
|
4252
4519
|
for (const statement of statements) {
|
|
4253
|
-
|
|
4520
|
+
this.sqliteUtil.execute(mDB.database, statement, false, true);
|
|
4254
4521
|
}
|
|
4255
|
-
|
|
4522
|
+
this.sqliteUtil.commitTransaction(mDB.database, true);
|
|
4523
|
+
mDB.setIsTransActive(false);
|
|
4256
4524
|
return Promise.resolve();
|
|
4257
4525
|
}
|
|
4258
4526
|
catch (err) {
|
|
4259
|
-
|
|
4527
|
+
this.sqliteUtil.rollbackTransaction(mDB.database, true);
|
|
4528
|
+
mDB.setIsTransActive(false);
|
|
4260
4529
|
return Promise.reject(`ExecuteStatementProcess: ${err}`);
|
|
4261
4530
|
}
|
|
4262
4531
|
}
|
|
@@ -4270,6 +4539,7 @@ const exportToJson_1 = exportToJson;
|
|
|
4270
4539
|
const importFromJson_1 = importFromJson;
|
|
4271
4540
|
const utilsJson_1$1 = utilsJson;
|
|
4272
4541
|
const utilsJsonEncryption_1$1 = utilsJsonEncryption;
|
|
4542
|
+
const UtilsSQL92Compatibility_1 = UtilsSQL92Compatibility$1;
|
|
4273
4543
|
const utilsEncryption_1 = utilsEncryption;
|
|
4274
4544
|
const utilsFile_1$1 = utilsFile;
|
|
4275
4545
|
const utilsSQLite_1$1 = utilsSQLite;
|
|
@@ -4288,6 +4558,7 @@ class Database {
|
|
|
4288
4558
|
this.importFromJsonUtil = new importFromJson_1.ImportFromJson();
|
|
4289
4559
|
this.exportToJsonUtil = new exportToJson_1.ExportToJson();
|
|
4290
4560
|
this.upgradeVersionDict = {};
|
|
4561
|
+
this.sql92Utils = new UtilsSQL92Compatibility_1.UtilsSQL92Compatibility();
|
|
4291
4562
|
this.dbName = dbName;
|
|
4292
4563
|
this._encrypted = encrypted;
|
|
4293
4564
|
this._mode = mode;
|
|
@@ -4297,6 +4568,7 @@ class Database {
|
|
|
4297
4568
|
this.upgradeVersionDict = upgDict;
|
|
4298
4569
|
this.pathDB = this.fileUtil.getFilePath(dbName);
|
|
4299
4570
|
this._isDbOpen = false;
|
|
4571
|
+
this.isTransactionActive = false;
|
|
4300
4572
|
this.globalUtil = globalUtil ? globalUtil : new GlobalSQLite_1$1.GlobalSQLite();
|
|
4301
4573
|
if (this.pathDB.length === 0)
|
|
4302
4574
|
throw new Error('Could not generate a path to ' + dbName);
|
|
@@ -4340,7 +4612,7 @@ class Database {
|
|
|
4340
4612
|
try {
|
|
4341
4613
|
await this.fileUtil.copyFileName(this.dbName, `backup-${this.dbName}`);
|
|
4342
4614
|
// execute the upgrade flow process
|
|
4343
|
-
await this.upgradeUtil.onUpgrade(this
|
|
4615
|
+
await this.upgradeUtil.onUpgrade(this, this.upgradeVersionDict, curVersion, this.version);
|
|
4344
4616
|
// delete the backup database
|
|
4345
4617
|
await this.fileUtil.deleteFileName(`backup-${this.dbName}`);
|
|
4346
4618
|
}
|
|
@@ -4369,8 +4641,8 @@ class Database {
|
|
|
4369
4641
|
* @returns Promise<boolean>
|
|
4370
4642
|
*/
|
|
4371
4643
|
dbClose() {
|
|
4372
|
-
this.ensureDatabaseIsOpen();
|
|
4373
4644
|
try {
|
|
4645
|
+
this.ensureDatabaseIsOpen();
|
|
4374
4646
|
this.sqliteUtil.closeDB(this.database);
|
|
4375
4647
|
}
|
|
4376
4648
|
catch (err) {
|
|
@@ -4381,6 +4653,70 @@ class Database {
|
|
|
4381
4653
|
}
|
|
4382
4654
|
return;
|
|
4383
4655
|
}
|
|
4656
|
+
/**
|
|
4657
|
+
* IsTransActive
|
|
4658
|
+
* Is Database Transaction Active
|
|
4659
|
+
* @returns
|
|
4660
|
+
*/
|
|
4661
|
+
isTransActive() {
|
|
4662
|
+
return this.isTransactionActive;
|
|
4663
|
+
}
|
|
4664
|
+
/**
|
|
4665
|
+
* SetIsTransActive
|
|
4666
|
+
* Set the Database Transaction to Active
|
|
4667
|
+
* @returns
|
|
4668
|
+
*/
|
|
4669
|
+
setIsTransActive(value) {
|
|
4670
|
+
this.isTransactionActive = value;
|
|
4671
|
+
}
|
|
4672
|
+
/**
|
|
4673
|
+
* DbBeginTransaction
|
|
4674
|
+
* Database Begin Transaction
|
|
4675
|
+
* @returns
|
|
4676
|
+
*/
|
|
4677
|
+
dbBeginTransaction() {
|
|
4678
|
+
try {
|
|
4679
|
+
this.ensureDatabaseIsOpen();
|
|
4680
|
+
this.sqliteUtil.beginTransaction(this.database, true);
|
|
4681
|
+
this.setIsTransActive(true);
|
|
4682
|
+
return 0;
|
|
4683
|
+
}
|
|
4684
|
+
catch (err) {
|
|
4685
|
+
throw new Error(`DbBeginTransaction: ${err}`);
|
|
4686
|
+
}
|
|
4687
|
+
}
|
|
4688
|
+
/**
|
|
4689
|
+
* DbCommitTransaction
|
|
4690
|
+
* Database Commit Transaction
|
|
4691
|
+
* @returns
|
|
4692
|
+
*/
|
|
4693
|
+
dbCommitTransaction() {
|
|
4694
|
+
try {
|
|
4695
|
+
this.ensureDatabaseIsOpen();
|
|
4696
|
+
this.sqliteUtil.commitTransaction(this.database, true);
|
|
4697
|
+
this.setIsTransActive(false);
|
|
4698
|
+
return 0;
|
|
4699
|
+
}
|
|
4700
|
+
catch (err) {
|
|
4701
|
+
throw new Error(`DbCommitTransaction: ${err}`);
|
|
4702
|
+
}
|
|
4703
|
+
}
|
|
4704
|
+
/**
|
|
4705
|
+
* DbRollbackTransaction
|
|
4706
|
+
* Database Rollback Transaction
|
|
4707
|
+
* @returns
|
|
4708
|
+
*/
|
|
4709
|
+
dbRollbackTransaction() {
|
|
4710
|
+
try {
|
|
4711
|
+
this.ensureDatabaseIsOpen();
|
|
4712
|
+
this.sqliteUtil.rollbackTransaction(this.database, true);
|
|
4713
|
+
this.setIsTransActive(false);
|
|
4714
|
+
return 0;
|
|
4715
|
+
}
|
|
4716
|
+
catch (err) {
|
|
4717
|
+
throw new Error(`DbCommitTransaction: ${err}`);
|
|
4718
|
+
}
|
|
4719
|
+
}
|
|
4384
4720
|
/**
|
|
4385
4721
|
* ChangeSecret
|
|
4386
4722
|
* open the @journeyapps/sqlcipher sqlite3 database
|
|
@@ -4493,7 +4829,7 @@ class Database {
|
|
|
4493
4829
|
);`;
|
|
4494
4830
|
stmts += `INSERT INTO sync_table (sync_date) VALUES (
|
|
4495
4831
|
${date});`;
|
|
4496
|
-
const results = this.sqliteUtil.execute(this.database, stmts, false);
|
|
4832
|
+
const results = this.sqliteUtil.execute(this.database, stmts, false, true);
|
|
4497
4833
|
changes = results.changes;
|
|
4498
4834
|
if (results.changes < 0) {
|
|
4499
4835
|
throw new Error(`CreateSyncTable: failed changes < 0`);
|
|
@@ -4528,7 +4864,7 @@ class Database {
|
|
|
4528
4864
|
const syncDateUnixTimestamp = Math.round(new Date(syncDate).getTime() / 1000);
|
|
4529
4865
|
let stmt = `UPDATE sync_table SET sync_date = `;
|
|
4530
4866
|
stmt += `${syncDateUnixTimestamp} WHERE id = 1;`;
|
|
4531
|
-
const results = this.sqliteUtil.execute(this.database, stmt, false);
|
|
4867
|
+
const results = this.sqliteUtil.execute(this.database, stmt, false, true);
|
|
4532
4868
|
if (results.changes < 0) {
|
|
4533
4869
|
return { result: false, message: 'setSyncDate failed' };
|
|
4534
4870
|
}
|
|
@@ -4568,9 +4904,11 @@ class Database {
|
|
|
4568
4904
|
* ExecuteSQL
|
|
4569
4905
|
* execute raw sql statements store in a string
|
|
4570
4906
|
* @param sql: string
|
|
4907
|
+
* @param transaction: boolean
|
|
4908
|
+
* @param isSQL92: boolean
|
|
4571
4909
|
* @returns Promise<number>
|
|
4572
4910
|
*/
|
|
4573
|
-
executeSQL(sql, transaction) {
|
|
4911
|
+
executeSQL(sql, transaction, isSQL92) {
|
|
4574
4912
|
this.ensureDatabaseIsOpen();
|
|
4575
4913
|
try {
|
|
4576
4914
|
if (transaction) {
|
|
@@ -4578,7 +4916,7 @@ class Database {
|
|
|
4578
4916
|
console.log(`$$$ in executeSQL journal_mode: ${mode} $$$`);
|
|
4579
4917
|
this.sqliteUtil.beginTransaction(this.database, this._isDbOpen);
|
|
4580
4918
|
}
|
|
4581
|
-
const results = this.sqliteUtil.execute(this.database, sql, false);
|
|
4919
|
+
const results = this.sqliteUtil.execute(this.database, sql, false, isSQL92);
|
|
4582
4920
|
if (results.changes < 0) {
|
|
4583
4921
|
throw new Error('ExecuteSQL: changes < 0');
|
|
4584
4922
|
}
|
|
@@ -4605,12 +4943,13 @@ class Database {
|
|
|
4605
4943
|
* execute a sql query with/without binding values
|
|
4606
4944
|
* @param sql: string
|
|
4607
4945
|
* @param values: string[]
|
|
4946
|
+
* @param isSQL92: boolean
|
|
4608
4947
|
* @returns Promise<any[]>
|
|
4609
4948
|
*/
|
|
4610
|
-
selectSQL(sql, values) {
|
|
4949
|
+
selectSQL(sql, values, isSQL92) {
|
|
4611
4950
|
this.ensureDatabaseIsOpen();
|
|
4612
4951
|
try {
|
|
4613
|
-
const selectResult = this.sqliteUtil.queryAll(this.database, sql, values);
|
|
4952
|
+
const selectResult = this.sqliteUtil.queryAll(this.database, sql, values, isSQL92);
|
|
4614
4953
|
return selectResult;
|
|
4615
4954
|
}
|
|
4616
4955
|
catch (err) {
|
|
@@ -4622,9 +4961,10 @@ class Database {
|
|
|
4622
4961
|
* execute a raw sql statement with/without binding values
|
|
4623
4962
|
* @param sql: string
|
|
4624
4963
|
* @param values: string[]
|
|
4964
|
+
* @param isSQL92: boolean,
|
|
4625
4965
|
* @returns Promise<{changes:number, lastId:number}>
|
|
4626
4966
|
*/
|
|
4627
|
-
runSQL(statement, values, transaction, returnMode) {
|
|
4967
|
+
runSQL(statement, values, transaction, returnMode, isSQL92) {
|
|
4628
4968
|
this.ensureDatabaseIsOpen();
|
|
4629
4969
|
try {
|
|
4630
4970
|
// start a transaction
|
|
@@ -4638,7 +4978,11 @@ class Database {
|
|
|
4638
4978
|
throw new Error(`RunSQL: ${err}`);
|
|
4639
4979
|
}
|
|
4640
4980
|
try {
|
|
4641
|
-
|
|
4981
|
+
let nStmt = statement;
|
|
4982
|
+
if (!isSQL92 && values.length === 0) {
|
|
4983
|
+
nStmt = this.sql92Utils.compatibleSQL92(statement);
|
|
4984
|
+
}
|
|
4985
|
+
const results = this.sqliteUtil.prepareRun(this.database, nStmt, values, false, returnMode);
|
|
4642
4986
|
if (results.lastId < 0) {
|
|
4643
4987
|
if (transaction) {
|
|
4644
4988
|
this.sqliteUtil.rollbackTransaction(this.database, this._isDbOpen);
|
|
@@ -4661,9 +5005,12 @@ class Database {
|
|
|
4661
5005
|
* ExecSet
|
|
4662
5006
|
* execute a set of raw sql statements with/without binding values
|
|
4663
5007
|
* @param set: any[]
|
|
5008
|
+
* @param transaction: boolean,
|
|
5009
|
+
* @param returnMode: string,
|
|
5010
|
+
* @param isSQL92: boolean,
|
|
4664
5011
|
* @returns Promise<{changes:number, lastId:number}>
|
|
4665
5012
|
*/
|
|
4666
|
-
execSet(set, transaction, returnMode) {
|
|
5013
|
+
execSet(set, transaction, returnMode, isSQL92) {
|
|
4667
5014
|
this.ensureDatabaseIsOpen();
|
|
4668
5015
|
let results = { changes: 0, lastId: -1 };
|
|
4669
5016
|
try {
|
|
@@ -4678,7 +5025,7 @@ class Database {
|
|
|
4678
5025
|
throw new Error(`ExecSet: ${err}`);
|
|
4679
5026
|
}
|
|
4680
5027
|
try {
|
|
4681
|
-
results = this.sqliteUtil.executeSet(this.database, set, false, returnMode);
|
|
5028
|
+
results = this.sqliteUtil.executeSet(this.database, set, false, returnMode, isSQL92);
|
|
4682
5029
|
if (transaction) {
|
|
4683
5030
|
this.sqliteUtil.commitTransaction(this.database, this._isDbOpen);
|
|
4684
5031
|
}
|
|
@@ -4729,15 +5076,15 @@ class Database {
|
|
|
4729
5076
|
this.sqliteUtil.setForeignKeyConstraintsEnabled(this.database, false);
|
|
4730
5077
|
if (jsonData.tables && jsonData.tables.length > 0) {
|
|
4731
5078
|
// create the database schema
|
|
4732
|
-
changes = this.importFromJsonUtil.createDatabaseSchema(this
|
|
5079
|
+
changes = this.importFromJsonUtil.createDatabaseSchema(this, jsonData);
|
|
4733
5080
|
if (changes != -1) {
|
|
4734
5081
|
// create the tables data
|
|
4735
|
-
changes += this.importFromJsonUtil.createTablesData(this
|
|
5082
|
+
changes += this.importFromJsonUtil.createTablesData(this, jsonData);
|
|
4736
5083
|
}
|
|
4737
5084
|
}
|
|
4738
5085
|
if (jsonData.views && jsonData.views.length > 0) {
|
|
4739
5086
|
// create the views
|
|
4740
|
-
changes += this.importFromJsonUtil.createViews(this
|
|
5087
|
+
changes += this.importFromJsonUtil.createViews(this, jsonData);
|
|
4741
5088
|
}
|
|
4742
5089
|
// set Foreign Keys On
|
|
4743
5090
|
this.sqliteUtil.setForeignKeyConstraintsEnabled(this.database, true);
|
|
@@ -4907,6 +5254,78 @@ class CapacitorSQLite {
|
|
|
4907
5254
|
throw new Error(`Close: ${msg}`);
|
|
4908
5255
|
}
|
|
4909
5256
|
}
|
|
5257
|
+
async beginTransaction(options) {
|
|
5258
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
5259
|
+
const connName = 'RW_' + dbName;
|
|
5260
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5261
|
+
if (database.isDBOpen()) {
|
|
5262
|
+
try {
|
|
5263
|
+
const changes = database.dbBeginTransaction();
|
|
5264
|
+
return { changes: { changes: changes } };
|
|
5265
|
+
}
|
|
5266
|
+
catch (err) {
|
|
5267
|
+
throw new Error(`BeginTransaction: ${err}`);
|
|
5268
|
+
}
|
|
5269
|
+
}
|
|
5270
|
+
else {
|
|
5271
|
+
const msg = `Database ${dbName} not opened`;
|
|
5272
|
+
throw new Error(`BeginTransaction: ${msg}`);
|
|
5273
|
+
}
|
|
5274
|
+
}
|
|
5275
|
+
async commitTransaction(options) {
|
|
5276
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
5277
|
+
const connName = 'RW_' + dbName;
|
|
5278
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5279
|
+
if (database.isDBOpen()) {
|
|
5280
|
+
try {
|
|
5281
|
+
const changes = database.dbCommitTransaction();
|
|
5282
|
+
return { changes: { changes: changes } };
|
|
5283
|
+
}
|
|
5284
|
+
catch (err) {
|
|
5285
|
+
throw new Error(`CommitTransaction: ${err}`);
|
|
5286
|
+
}
|
|
5287
|
+
}
|
|
5288
|
+
else {
|
|
5289
|
+
const msg = `Database ${dbName} not opened`;
|
|
5290
|
+
throw new Error(`CommitTransaction: ${msg}`);
|
|
5291
|
+
}
|
|
5292
|
+
}
|
|
5293
|
+
async rollbackTransaction(options) {
|
|
5294
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
5295
|
+
const connName = 'RW_' + dbName;
|
|
5296
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5297
|
+
if (database.isDBOpen()) {
|
|
5298
|
+
try {
|
|
5299
|
+
const changes = database.dbRollbackTransaction();
|
|
5300
|
+
return { changes: { changes: changes } };
|
|
5301
|
+
}
|
|
5302
|
+
catch (err) {
|
|
5303
|
+
throw new Error(`RollbackTransaction: ${err}`);
|
|
5304
|
+
}
|
|
5305
|
+
}
|
|
5306
|
+
else {
|
|
5307
|
+
const msg = `Database ${dbName} not opened`;
|
|
5308
|
+
throw new Error(`RollbackTransaction: ${msg}`);
|
|
5309
|
+
}
|
|
5310
|
+
}
|
|
5311
|
+
async isTransactionActive(options) {
|
|
5312
|
+
const dbName = this.getOptionValue(options, 'database');
|
|
5313
|
+
const connName = 'RW_' + dbName;
|
|
5314
|
+
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5315
|
+
if (database.isDBOpen()) {
|
|
5316
|
+
try {
|
|
5317
|
+
const ret = database.isTransActive();
|
|
5318
|
+
return { result: ret };
|
|
5319
|
+
}
|
|
5320
|
+
catch (err) {
|
|
5321
|
+
throw new Error(`IsTransactionActive: ${err}`);
|
|
5322
|
+
}
|
|
5323
|
+
}
|
|
5324
|
+
else {
|
|
5325
|
+
const msg = `Database ${dbName} not opened`;
|
|
5326
|
+
throw new Error(`IsTransactionActive: ${msg}`);
|
|
5327
|
+
}
|
|
5328
|
+
}
|
|
4910
5329
|
async getVersion(options) {
|
|
4911
5330
|
const dbName = this.getOptionValue(options, 'database');
|
|
4912
5331
|
const readonly = options.readonly ? options.readonly : false;
|
|
@@ -4954,6 +5373,7 @@ class CapacitorSQLite {
|
|
|
4954
5373
|
const statements = this.getOptionValue(options, 'statements');
|
|
4955
5374
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
4956
5375
|
const readonly = options.readonly ? options.readonly : false;
|
|
5376
|
+
const isSQL92 = (Object.keys(options)).includes('isSQL92') ? options.isSQL92 : true;
|
|
4957
5377
|
const connName = 'RW_' + dbName;
|
|
4958
5378
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4959
5379
|
if (database.isDBOpen()) {
|
|
@@ -4962,7 +5382,7 @@ class CapacitorSQLite {
|
|
|
4962
5382
|
throw new Error(`Execute: ${msg}`);
|
|
4963
5383
|
}
|
|
4964
5384
|
try {
|
|
4965
|
-
const executeResult = database.executeSQL(statements, transaction);
|
|
5385
|
+
const executeResult = database.executeSQL(statements, transaction, isSQL92);
|
|
4966
5386
|
if (executeResult < 0) {
|
|
4967
5387
|
throw new Error('Execute changes < 0');
|
|
4968
5388
|
}
|
|
@@ -4985,6 +5405,7 @@ class CapacitorSQLite {
|
|
|
4985
5405
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
4986
5406
|
const readonly = options.readonly ? options.readonly : false;
|
|
4987
5407
|
const returnMode = options.returnMode ? options.returnMode : 'no';
|
|
5408
|
+
const isSQL92 = (Object.keys(options)).includes('isSQL92') ? options.isSQL92 : true;
|
|
4988
5409
|
const connName = 'RW_' + dbName;
|
|
4989
5410
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
4990
5411
|
for (const sStmt of setOfStatements) {
|
|
@@ -4998,7 +5419,7 @@ class CapacitorSQLite {
|
|
|
4998
5419
|
throw new Error(`ExecuteSet failed: ${msg}`);
|
|
4999
5420
|
}
|
|
5000
5421
|
try {
|
|
5001
|
-
const execSetResult = database.execSet(setOfStatements, transaction, returnMode);
|
|
5422
|
+
const execSetResult = database.execSet(setOfStatements, transaction, returnMode, isSQL92);
|
|
5002
5423
|
if (execSetResult.lastId < 0) {
|
|
5003
5424
|
throw new Error(`ExecuteSet failed changes <0`);
|
|
5004
5425
|
}
|
|
@@ -5022,6 +5443,7 @@ class CapacitorSQLite {
|
|
|
5022
5443
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
5023
5444
|
const readonly = options.readonly ? options.readonly : false;
|
|
5024
5445
|
const returnMode = options.returnMode ? options.returnMode : 'no';
|
|
5446
|
+
const isSQL92 = (Object.keys(options)).includes('isSQL92') ? options.isSQL92 : true;
|
|
5025
5447
|
const connName = 'RW_' + dbName;
|
|
5026
5448
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5027
5449
|
if (database.isDBOpen()) {
|
|
@@ -5030,7 +5452,7 @@ class CapacitorSQLite {
|
|
|
5030
5452
|
throw new Error(`Run failed: ${msg}`);
|
|
5031
5453
|
}
|
|
5032
5454
|
try {
|
|
5033
|
-
const runResult = database.runSQL(statement, values, transaction, returnMode);
|
|
5455
|
+
const runResult = database.runSQL(statement, values, transaction, returnMode, isSQL92);
|
|
5034
5456
|
return { changes: runResult };
|
|
5035
5457
|
}
|
|
5036
5458
|
catch (err) {
|
|
@@ -5050,11 +5472,12 @@ class CapacitorSQLite {
|
|
|
5050
5472
|
throw new Error('Query: Statement may not be an empty string.');
|
|
5051
5473
|
}
|
|
5052
5474
|
const readonly = options.readonly ? options.readonly : false;
|
|
5475
|
+
const isSQL92 = (Object.keys(options)).includes('isSQL92') ? options.isSQL92 : true;
|
|
5053
5476
|
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
5054
5477
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5055
5478
|
if (database.isDBOpen()) {
|
|
5056
5479
|
try {
|
|
5057
|
-
const queryResult = database.selectSQL(statement, values);
|
|
5480
|
+
const queryResult = database.selectSQL(statement, values, isSQL92);
|
|
5058
5481
|
return { values: queryResult };
|
|
5059
5482
|
}
|
|
5060
5483
|
catch (err) {
|