@capacitor-community/sqlite 5.0.8 → 5.2.4
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/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +5 -6
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +12 -7
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +20 -7
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLCipher.java +62 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +20 -14
- package/dist/esm/definitions.d.ts +6 -6
- package/dist/esm/definitions.js +42 -23
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +42 -23
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +42 -23
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +72 -78
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +1082 -1139
- package/ios/Plugin/CapacitorSQLitePlugin.swift +3 -2
- package/ios/Plugin/Database.swift +27 -3
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +2 -2
- package/ios/Plugin/Utils/UtilsDelete.swift +2 -3
- package/ios/Plugin/Utils/UtilsEncryption.swift +75 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +3 -3
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +81 -17
- package/ios/Plugin/Utils/UtilsSecret.swift +1 -0
- package/package.json +7 -7
- package/src/definitions.ts +88 -56
- package/src/web.ts +10 -4
package/electron/dist/plugin.js
CHANGED
|
@@ -54,17 +54,17 @@ Object.defineProperty(UtilsSQL92Compatibility$1, "__esModule", { value: true });
|
|
|
54
54
|
UtilsSQL92Compatibility$1.UtilsSQL92Compatibility = void 0;
|
|
55
55
|
class UtilsSQL92Compatibility {
|
|
56
56
|
compatibleSQL92(statement) {
|
|
57
|
-
let newStatement =
|
|
58
|
-
const action =
|
|
57
|
+
let newStatement = '';
|
|
58
|
+
const action = statement.trim().substring(0, 6).toUpperCase();
|
|
59
59
|
switch (action) {
|
|
60
|
-
case
|
|
60
|
+
case 'INSERT':
|
|
61
61
|
newStatement = this.insertSQL92(statement);
|
|
62
62
|
break;
|
|
63
|
-
case
|
|
63
|
+
case 'UPDATE':
|
|
64
64
|
newStatement = this.updateSQL92(statement);
|
|
65
65
|
break;
|
|
66
|
-
case
|
|
67
|
-
case
|
|
66
|
+
case 'DELETE':
|
|
67
|
+
case 'SELECT':
|
|
68
68
|
newStatement = this.whereSQL92(statement);
|
|
69
69
|
break;
|
|
70
70
|
default:
|
|
@@ -72,7 +72,6 @@ class UtilsSQL92Compatibility {
|
|
|
72
72
|
}
|
|
73
73
|
return newStatement;
|
|
74
74
|
}
|
|
75
|
-
;
|
|
76
75
|
insertSQL92(insertStatement) {
|
|
77
76
|
// Split the statement into parts
|
|
78
77
|
const inStmt = insertStatement.trim();
|
|
@@ -85,7 +84,6 @@ class UtilsSQL92Compatibility {
|
|
|
85
84
|
const modifiedStatement = columnsPart + modifiedValuesPart;
|
|
86
85
|
return modifiedStatement;
|
|
87
86
|
}
|
|
88
|
-
;
|
|
89
87
|
updateSQL92(updateStatement) {
|
|
90
88
|
// Split the statement into SET and WHERE parts
|
|
91
89
|
let isWhere = true;
|
|
@@ -105,7 +103,6 @@ class UtilsSQL92Compatibility {
|
|
|
105
103
|
}
|
|
106
104
|
return modifiedStatement;
|
|
107
105
|
}
|
|
108
|
-
;
|
|
109
106
|
whereSQL92(statement) {
|
|
110
107
|
// Split the statement into SET and WHERE parts
|
|
111
108
|
const setWhereSplit = statement.toUpperCase().split('WHERE');
|
|
@@ -119,18 +116,16 @@ class UtilsSQL92Compatibility {
|
|
|
119
116
|
}
|
|
120
117
|
return modifiedStatement;
|
|
121
118
|
}
|
|
122
|
-
;
|
|
123
119
|
modSetPart(setStatement) {
|
|
124
|
-
const commaPart = setStatement.split(
|
|
120
|
+
const commaPart = setStatement.split(',');
|
|
125
121
|
const modCommaPart = [];
|
|
126
122
|
for (const com of commaPart) {
|
|
127
|
-
const equalPart = com.split(
|
|
123
|
+
const equalPart = com.split('=');
|
|
128
124
|
const value = equalPart[1].replaceAll(`"`, `'`);
|
|
129
125
|
modCommaPart.push(`${equalPart[0].trim()} = ${value.trim()}`);
|
|
130
126
|
}
|
|
131
127
|
return modCommaPart.toString();
|
|
132
128
|
}
|
|
133
|
-
;
|
|
134
129
|
modWherePart(whereStatement) {
|
|
135
130
|
const keywords = new Set([
|
|
136
131
|
'=',
|
|
@@ -148,10 +143,13 @@ class UtilsSQL92Compatibility {
|
|
|
148
143
|
'LIKE',
|
|
149
144
|
'AND',
|
|
150
145
|
'OR',
|
|
151
|
-
'NOT'
|
|
146
|
+
'NOT',
|
|
152
147
|
]);
|
|
153
148
|
const newTokens = [];
|
|
154
|
-
const tokens = whereStatement
|
|
149
|
+
const tokens = whereStatement
|
|
150
|
+
.split(/(\s|,|\(|\))/)
|
|
151
|
+
.filter(item => item !== ' ')
|
|
152
|
+
.filter(item => item !== '');
|
|
155
153
|
let inClause = false;
|
|
156
154
|
let inValues = false;
|
|
157
155
|
let modValue = false;
|
|
@@ -160,7 +158,7 @@ class UtilsSQL92Compatibility {
|
|
|
160
158
|
let inValValues = false;
|
|
161
159
|
let inValPar = false;
|
|
162
160
|
for (const token of tokens) {
|
|
163
|
-
if (
|
|
161
|
+
if (new Set(['=', '<>', '>', '>=', '<', '<=']).has(token)) {
|
|
164
162
|
newTokens.push(token);
|
|
165
163
|
modValue = true;
|
|
166
164
|
opsClause = false;
|
|
@@ -227,9 +225,7 @@ class UtilsSQL92Compatibility {
|
|
|
227
225
|
inValues = false;
|
|
228
226
|
inClause = false;
|
|
229
227
|
}
|
|
230
|
-
else if (modValue &&
|
|
231
|
-
!opsClause &&
|
|
232
|
-
!keywords.has(token.toUpperCase())) {
|
|
228
|
+
else if (modValue && !opsClause && !keywords.has(token.toUpperCase())) {
|
|
233
229
|
if (token.length > 0) {
|
|
234
230
|
const nwToken = token.replaceAll(`"`, `'`);
|
|
235
231
|
newTokens.push(nwToken);
|
|
@@ -240,10 +236,9 @@ class UtilsSQL92Compatibility {
|
|
|
240
236
|
newTokens.push(token);
|
|
241
237
|
}
|
|
242
238
|
}
|
|
243
|
-
const ns = newTokens.join(
|
|
239
|
+
const ns = newTokens.join(' ');
|
|
244
240
|
return ns;
|
|
245
241
|
}
|
|
246
|
-
;
|
|
247
242
|
}
|
|
248
243
|
UtilsSQL92Compatibility$1.UtilsSQL92Compatibility = UtilsSQL92Compatibility;
|
|
249
244
|
|
|
@@ -1069,37 +1064,6 @@ class UtilsSQLStatement {
|
|
|
1069
1064
|
throw new Error('extractForeignKeyInfo: No FOREIGN KEY found');
|
|
1070
1065
|
}
|
|
1071
1066
|
}
|
|
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
|
-
*/
|
|
1103
1067
|
extractColumnNames(whereClause) {
|
|
1104
1068
|
const keywords = new Set([
|
|
1105
1069
|
'AND',
|
|
@@ -1110,29 +1074,25 @@ class UtilsSQLStatement {
|
|
|
1110
1074
|
'BETWEEN',
|
|
1111
1075
|
'NOT',
|
|
1112
1076
|
]);
|
|
1113
|
-
const
|
|
1077
|
+
const regex = /\b[a-zA-Z]\w*\b(?=\s*(?:<=?|>=?|<>?|=|AND|OR|BETWEEN|NOT|IN|LIKE))|\b[a-zA-Z]\w*\b\s+BETWEEN\s+'[^']+'\s+AND\s+'[^']+'|\(([^)]+)\)\s+IN\s+\(?\s*VALUES\s*\(/g;
|
|
1078
|
+
let match;
|
|
1114
1079
|
const columns = [];
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
inValues = true;
|
|
1123
|
-
}
|
|
1124
|
-
else if (inValues && token === ')') {
|
|
1125
|
-
inValues = false;
|
|
1080
|
+
while ((match = regex.exec(whereClause)) !== null) {
|
|
1081
|
+
const columnList = match[1];
|
|
1082
|
+
if (columnList) {
|
|
1083
|
+
const columnNamesArray = columnList.split(',');
|
|
1084
|
+
for (const columnName of columnNamesArray) {
|
|
1085
|
+
columns.push(columnName.trim());
|
|
1086
|
+
}
|
|
1126
1087
|
}
|
|
1127
|
-
else
|
|
1128
|
-
|
|
1129
|
-
!keywords.has(
|
|
1130
|
-
|
|
1131
|
-
columns.push(token);
|
|
1088
|
+
else {
|
|
1089
|
+
const matchedText = match[0];
|
|
1090
|
+
if (!keywords.has(matchedText.trim().toUpperCase())) {
|
|
1091
|
+
columns.push(matchedText.trim());
|
|
1132
1092
|
}
|
|
1133
1093
|
}
|
|
1134
1094
|
}
|
|
1135
|
-
return
|
|
1095
|
+
return columns;
|
|
1136
1096
|
}
|
|
1137
1097
|
flattenMultilineString(input) {
|
|
1138
1098
|
const lines = input.split(/\r?\n/);
|
|
@@ -1599,7 +1559,8 @@ class UtilsSQLite {
|
|
|
1599
1559
|
}
|
|
1600
1560
|
break;
|
|
1601
1561
|
case 'DELETE':
|
|
1602
|
-
if (!fromJson &&
|
|
1562
|
+
if (!fromJson &&
|
|
1563
|
+
rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1603
1564
|
let whereStmt = rStmt;
|
|
1604
1565
|
if (!isSQL92)
|
|
1605
1566
|
whereStmt = this.cleanStatement(rStmt);
|
|
@@ -1619,7 +1580,8 @@ class UtilsSQLite {
|
|
|
1619
1580
|
}
|
|
1620
1581
|
break;
|
|
1621
1582
|
case 'SELECT':
|
|
1622
|
-
if (!fromJson &&
|
|
1583
|
+
if (!fromJson &&
|
|
1584
|
+
rStmt.toLowerCase().includes('WHERE'.toLowerCase())) {
|
|
1623
1585
|
if (!isSQL92)
|
|
1624
1586
|
rStmt = this.cleanStatement(rStmt);
|
|
1625
1587
|
}
|
|
@@ -2240,7 +2202,6 @@ class UtilsSQLite {
|
|
|
2240
2202
|
const msg = 'getJournalMode';
|
|
2241
2203
|
try {
|
|
2242
2204
|
const retMode = mDB.pragma('journal_mode');
|
|
2243
|
-
console.log(`journal_mode: ${retMode[0].journal_mode}`);
|
|
2244
2205
|
return retMode[0].journal_mode;
|
|
2245
2206
|
}
|
|
2246
2207
|
catch (err) {
|
|
@@ -4249,6 +4210,14 @@ class UtilsSecret {
|
|
|
4249
4210
|
this.fileUtil = new utilsFile_1$3.UtilsFile();
|
|
4250
4211
|
this.storage = require$$3__default$1["default"];
|
|
4251
4212
|
}
|
|
4213
|
+
isPassphraseValid(passphrase) {
|
|
4214
|
+
let isValid = false;
|
|
4215
|
+
const secret = this.getPassphrase();
|
|
4216
|
+
if (secret === passphrase) {
|
|
4217
|
+
isValid = true;
|
|
4218
|
+
}
|
|
4219
|
+
return isValid;
|
|
4220
|
+
}
|
|
4252
4221
|
isSecretStored() {
|
|
4253
4222
|
const secret = this.getPassphrase();
|
|
4254
4223
|
if (secret.length <= 0)
|
|
@@ -4498,7 +4467,8 @@ class UtilsUpgrade {
|
|
|
4498
4467
|
this.sqliteUtil.setVersion(mDB.database, versionKey);
|
|
4499
4468
|
// set Foreign Keys On
|
|
4500
4469
|
this.sqliteUtil.setForeignKeyConstraintsEnabled(mDB.database, true);
|
|
4501
|
-
changes =
|
|
4470
|
+
changes =
|
|
4471
|
+
(await this.sqliteUtil.dbChanges(mDB.database)) - initChanges;
|
|
4502
4472
|
}
|
|
4503
4473
|
catch (err) {
|
|
4504
4474
|
return Promise.reject(`onUpgrade: ${err}`);
|
|
@@ -5373,7 +5343,9 @@ class CapacitorSQLite {
|
|
|
5373
5343
|
const statements = this.getOptionValue(options, 'statements');
|
|
5374
5344
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
5375
5345
|
const readonly = options.readonly ? options.readonly : false;
|
|
5376
|
-
const isSQL92 =
|
|
5346
|
+
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5347
|
+
? options.isSQL92
|
|
5348
|
+
: true;
|
|
5377
5349
|
const connName = 'RW_' + dbName;
|
|
5378
5350
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5379
5351
|
if (database.isDBOpen()) {
|
|
@@ -5405,7 +5377,9 @@ class CapacitorSQLite {
|
|
|
5405
5377
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
5406
5378
|
const readonly = options.readonly ? options.readonly : false;
|
|
5407
5379
|
const returnMode = options.returnMode ? options.returnMode : 'no';
|
|
5408
|
-
const isSQL92 =
|
|
5380
|
+
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5381
|
+
? options.isSQL92
|
|
5382
|
+
: true;
|
|
5409
5383
|
const connName = 'RW_' + dbName;
|
|
5410
5384
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5411
5385
|
for (const sStmt of setOfStatements) {
|
|
@@ -5443,7 +5417,9 @@ class CapacitorSQLite {
|
|
|
5443
5417
|
const transaction = this.getOptionValue(options, 'transaction', true);
|
|
5444
5418
|
const readonly = options.readonly ? options.readonly : false;
|
|
5445
5419
|
const returnMode = options.returnMode ? options.returnMode : 'no';
|
|
5446
|
-
const isSQL92 =
|
|
5420
|
+
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5421
|
+
? options.isSQL92
|
|
5422
|
+
: true;
|
|
5447
5423
|
const connName = 'RW_' + dbName;
|
|
5448
5424
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5449
5425
|
if (database.isDBOpen()) {
|
|
@@ -5472,7 +5448,9 @@ class CapacitorSQLite {
|
|
|
5472
5448
|
throw new Error('Query: Statement may not be an empty string.');
|
|
5473
5449
|
}
|
|
5474
5450
|
const readonly = options.readonly ? options.readonly : false;
|
|
5475
|
-
const isSQL92 =
|
|
5451
|
+
const isSQL92 = Object.keys(options).includes('isSQL92')
|
|
5452
|
+
? options.isSQL92
|
|
5453
|
+
: true;
|
|
5476
5454
|
const connName = readonly ? 'RO_' + dbName : 'RW_' + dbName;
|
|
5477
5455
|
const database = this.getDatabaseConnectionOrThrowError(connName);
|
|
5478
5456
|
if (database.isDBOpen()) {
|
|
@@ -5882,6 +5860,22 @@ class CapacitorSQLite {
|
|
|
5882
5860
|
throw new Error(`isSecretStored: ${err}`);
|
|
5883
5861
|
}
|
|
5884
5862
|
}
|
|
5863
|
+
async isPassphraseValid(options) {
|
|
5864
|
+
if (!this.isEncryption) {
|
|
5865
|
+
throw new Error(`isPassphraseValid: Not available electronIsEncryption = false in capacitor.config.ts`);
|
|
5866
|
+
}
|
|
5867
|
+
const passphrase = options.passphrase ? options.passphrase : '';
|
|
5868
|
+
if (passphrase.length <= 0) {
|
|
5869
|
+
throw new Error(`isPassphraseValid: You must give a passphrase`);
|
|
5870
|
+
}
|
|
5871
|
+
try {
|
|
5872
|
+
const isValid = this.secretUtil.isPassphraseValid(passphrase);
|
|
5873
|
+
return { result: isValid };
|
|
5874
|
+
}
|
|
5875
|
+
catch (err) {
|
|
5876
|
+
throw new Error(`isPassphraseValid: ${err}`);
|
|
5877
|
+
}
|
|
5878
|
+
}
|
|
5885
5879
|
async setEncryptionSecret(options) {
|
|
5886
5880
|
const isEncrypt = this.fileUtil.getIsEncryption();
|
|
5887
5881
|
if (!isEncrypt) {
|