@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
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
package com.getcapacitor.community.database.sqlite.SQLite;
|
|
2
|
+
|
|
3
|
+
import java.util.ArrayList;
|
|
4
|
+
import java.util.Arrays;
|
|
5
|
+
import java.util.HashSet;
|
|
6
|
+
import java.util.List;
|
|
7
|
+
import java.util.Set;
|
|
8
|
+
import java.util.regex.Matcher;
|
|
9
|
+
import java.util.regex.Pattern;
|
|
10
|
+
|
|
11
|
+
public class UtilsSQLStatement {
|
|
12
|
+
|
|
13
|
+
public static String flattenMultilineString(String input) {
|
|
14
|
+
String[] lines = input.split("\\r?\\n");
|
|
15
|
+
return String.join(" ", lines);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public static String extractTableName(String statement) {
|
|
19
|
+
Pattern pattern = Pattern.compile("(?:INSERT\\s+INTO|UPDATE|DELETE\\s+FROM)\\s+([^\\s]+)", Pattern.CASE_INSENSITIVE);
|
|
20
|
+
Matcher match = pattern.matcher(statement);
|
|
21
|
+
if (match.find() && match.groupCount() > 0) {
|
|
22
|
+
String tableName = match.group(1);
|
|
23
|
+
return tableName;
|
|
24
|
+
}
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public static String extractWhereClause(String statement) {
|
|
29
|
+
Pattern pattern = Pattern.compile("WHERE(.+?)(?:ORDER\\s+BY|LIMIT|$)", Pattern.CASE_INSENSITIVE);
|
|
30
|
+
Matcher match = pattern.matcher(statement);
|
|
31
|
+
if (match.find() && match.groupCount() > 0) {
|
|
32
|
+
String whereClause = match.group(1).trim();
|
|
33
|
+
return whereClause;
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
public static String addPrefixToWhereClause(String whereClause, String[] colNames, String[] refNames, String prefix) {
|
|
39
|
+
String[] columnValuePairs = null;
|
|
40
|
+
String[] logicalOperators = new String[] { "AND", "OR", "NOT" };
|
|
41
|
+
|
|
42
|
+
for (String logicalOperator : logicalOperators) {
|
|
43
|
+
if (whereClause.contains(logicalOperator)) {
|
|
44
|
+
columnValuePairs = whereClause.split("\\s*" + logicalOperator + "\\s*");
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (columnValuePairs == null) {
|
|
50
|
+
columnValuePairs = new String[] { whereClause };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
List<String> modifiedPairs = new ArrayList<>();
|
|
54
|
+
|
|
55
|
+
for (String pair : columnValuePairs) {
|
|
56
|
+
String trimmedPair = pair.trim();
|
|
57
|
+
|
|
58
|
+
int operatorIndex = -1;
|
|
59
|
+
String operator = null;
|
|
60
|
+
for (String op : new String[] { "=", "<>", "<", "<=", ">", ">=", "IN", "BETWEEN", "LIKE" }) {
|
|
61
|
+
operatorIndex = trimmedPair.indexOf(op);
|
|
62
|
+
if (operatorIndex != -1) {
|
|
63
|
+
operator = op;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (operator == null) {
|
|
69
|
+
modifiedPairs.add(trimmedPair);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
String column = trimmedPair.substring(0, operatorIndex).trim();
|
|
74
|
+
String value = trimmedPair.substring(operatorIndex + operator.length()).trim();
|
|
75
|
+
|
|
76
|
+
String newColumn = column;
|
|
77
|
+
int index = findIndexOfStringInArray(column, refNames);
|
|
78
|
+
if (index != -1) {
|
|
79
|
+
newColumn = getStringAtIndex(colNames, index);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
String modifiedColumn = prefix + newColumn;
|
|
83
|
+
String modifiedPair = modifiedColumn + " " + operator + " " + value;
|
|
84
|
+
modifiedPairs.add(modifiedPair);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
String logicalOperatorUsed = logicalOperators[0];
|
|
88
|
+
for (String logicalOperator : logicalOperators) {
|
|
89
|
+
if (whereClause.contains(logicalOperator)) {
|
|
90
|
+
logicalOperatorUsed = logicalOperator;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
String modWhereClause = String.join(" " + logicalOperatorUsed + " ", modifiedPairs);
|
|
95
|
+
return modWhereClause;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
public static int findIndexOfStringInArray(String target, String[] array) {
|
|
99
|
+
for (int i = 0; i < array.length; i++) {
|
|
100
|
+
if (array[i].equals(target)) {
|
|
101
|
+
return i;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
public static String getStringAtIndex(String[] array, int index) {
|
|
108
|
+
if (index >= 0 && index < array.length) {
|
|
109
|
+
return array[index];
|
|
110
|
+
} else {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
public static UtilsDelete.ForeignKeyInfo extractForeignKeyInfo(String sqlStatement) throws Exception {
|
|
116
|
+
// Define the regular expression pattern for extracting the FOREIGN KEY clause
|
|
117
|
+
String foreignKeyPattern =
|
|
118
|
+
"\\bFOREIGN\\s+KEY\\s*\\(([^)]+)\\)\\s+REFERENCES\\s+(\\w+)\\s*\\(([^)]+)\\)\\s+(ON\\s+DELETE\\s+(RESTRICT|CASCADE|SET\\s+NULL|SET\\s+DEFAULT|NO\\s+ACTION))?";
|
|
119
|
+
Pattern pattern = Pattern.compile(foreignKeyPattern);
|
|
120
|
+
Matcher matcher = pattern.matcher(sqlStatement);
|
|
121
|
+
|
|
122
|
+
if (matcher.find()) {
|
|
123
|
+
String[] forKeys = matcher.group(1).split(",");
|
|
124
|
+
String tableName = matcher.group(2);
|
|
125
|
+
String[] refKeys = matcher.group(3).split(",");
|
|
126
|
+
String action = matcher.group(5) != null ? matcher.group(5) : "NO ACTION";
|
|
127
|
+
List<String> lForKeys = new ArrayList<>(Arrays.asList(forKeys));
|
|
128
|
+
List<String> lRefKeys = new ArrayList<>(Arrays.asList(refKeys));
|
|
129
|
+
return new UtilsDelete.ForeignKeyInfo(lForKeys, tableName, lRefKeys, action);
|
|
130
|
+
} else {
|
|
131
|
+
throw new Exception("extractForeignKeyInfo: No FOREIGN KEY found");
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public static List<String> extractColumnNames(String whereClause) {
|
|
136
|
+
Set<String> keywords = new HashSet<>(Arrays.asList("AND", "OR", "IN", "VALUES", "LIKE", "BETWEEN", "NOT"));
|
|
137
|
+
String[] tokens = whereClause.split("\\s|,|\\(|\\)");
|
|
138
|
+
|
|
139
|
+
List<String> columns = new ArrayList<>();
|
|
140
|
+
boolean inClause = false;
|
|
141
|
+
boolean inValues = false;
|
|
142
|
+
|
|
143
|
+
for (String token : tokens) {
|
|
144
|
+
if (token.equals("IN")) {
|
|
145
|
+
inClause = true;
|
|
146
|
+
} else if (inClause && token.equals("(")) {
|
|
147
|
+
inValues = true;
|
|
148
|
+
} else if (inValues && token.equals(")")) {
|
|
149
|
+
inValues = false;
|
|
150
|
+
} else if (token.matches("\\b[a-zA-Z]\\w*\\b") && !inValues && !keywords.contains(token.toUpperCase())) {
|
|
151
|
+
columns.add(token);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return new ArrayList<>(new HashSet<>(columns));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public static List<Integer> indicesOf(String str, String searchStr, int fromIndex) {
|
|
159
|
+
List<Integer> indices = new ArrayList<>();
|
|
160
|
+
|
|
161
|
+
int currentIndex = str.indexOf(searchStr, fromIndex);
|
|
162
|
+
while (currentIndex != -1) {
|
|
163
|
+
indices.add(currentIndex);
|
|
164
|
+
currentIndex = str.indexOf(searchStr, currentIndex + 1);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return indices;
|
|
168
|
+
}
|
|
169
|
+
}
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java
CHANGED
|
@@ -69,15 +69,15 @@ public class UtilsUpgrade {
|
|
|
69
69
|
* @throws Exception
|
|
70
70
|
*/
|
|
71
71
|
private void executeStatementsProcess(Database db, String[] statements) throws Exception {
|
|
72
|
-
db.
|
|
72
|
+
db.beginTransaction();
|
|
73
73
|
try {
|
|
74
|
-
db.execute(statements);
|
|
74
|
+
db.execute(statements, false);
|
|
75
75
|
|
|
76
|
-
db.
|
|
76
|
+
db.commitTransaction();
|
|
77
77
|
} catch (Exception e) {
|
|
78
78
|
throw new Exception("Error: executeStatementsProcess " + " failed " + e);
|
|
79
79
|
} finally {
|
|
80
|
-
db.
|
|
80
|
+
db.rollbackTransaction();
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -112,6 +112,34 @@ export interface CapacitorSQLitePlugin {
|
|
|
112
112
|
* @since 0.0.1
|
|
113
113
|
*/
|
|
114
114
|
close(options: capSQLiteOptions): Promise<void>;
|
|
115
|
+
/**
|
|
116
|
+
* Begin Database Transaction
|
|
117
|
+
* @param options
|
|
118
|
+
* @returns capSQLiteChanges
|
|
119
|
+
* @since 5.0.7
|
|
120
|
+
*/
|
|
121
|
+
beginTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges>;
|
|
122
|
+
/**
|
|
123
|
+
* Commit Database Transaction
|
|
124
|
+
* @param options
|
|
125
|
+
* @returns capSQLiteChanges
|
|
126
|
+
* @since 5.0.7
|
|
127
|
+
*/
|
|
128
|
+
commitTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges>;
|
|
129
|
+
/**
|
|
130
|
+
* Rollback Database Transaction
|
|
131
|
+
* @param options
|
|
132
|
+
* @returns capSQLiteChanges
|
|
133
|
+
* @since 5.0.7
|
|
134
|
+
*/
|
|
135
|
+
rollbackTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges>;
|
|
136
|
+
/**
|
|
137
|
+
* Is Database Transaction Active
|
|
138
|
+
* @param options
|
|
139
|
+
* @returns capSQLiteResult
|
|
140
|
+
* @since 5.0.7
|
|
141
|
+
*/
|
|
142
|
+
isTransactionActive(options: capSQLiteOptions): Promise<capSQLiteResult>;
|
|
115
143
|
/**
|
|
116
144
|
* Load a SQlite extension
|
|
117
145
|
* @param options :capSQLiteExtensionPath
|
|
@@ -514,6 +542,13 @@ export interface capSQLiteExecuteOptions {
|
|
|
514
542
|
* @since 4.1.0-7
|
|
515
543
|
*/
|
|
516
544
|
readonly?: boolean;
|
|
545
|
+
/**
|
|
546
|
+
* Compatibility SQL92
|
|
547
|
+
* !!! ELECTRON ONLY
|
|
548
|
+
* default (true)
|
|
549
|
+
* @since 5.0.7
|
|
550
|
+
*/
|
|
551
|
+
isSQL92?: boolean;
|
|
517
552
|
}
|
|
518
553
|
export interface capSQLiteSetOptions {
|
|
519
554
|
/**
|
|
@@ -544,6 +579,13 @@ export interface capSQLiteSetOptions {
|
|
|
544
579
|
* @since 5.0.5-3
|
|
545
580
|
*/
|
|
546
581
|
returnMode?: string;
|
|
582
|
+
/**
|
|
583
|
+
* Compatibility SQL92
|
|
584
|
+
* !!! ELECTRON ONLY
|
|
585
|
+
* default (true)
|
|
586
|
+
* @since 5.0.7
|
|
587
|
+
*/
|
|
588
|
+
isSQL92?: boolean;
|
|
547
589
|
}
|
|
548
590
|
export interface capSQLiteRunOptions {
|
|
549
591
|
/**
|
|
@@ -578,6 +620,13 @@ export interface capSQLiteRunOptions {
|
|
|
578
620
|
* @since 5.0.5-3
|
|
579
621
|
*/
|
|
580
622
|
returnMode?: string;
|
|
623
|
+
/**
|
|
624
|
+
* Compatibility SQL92
|
|
625
|
+
* !!! ELECTRON ONLY
|
|
626
|
+
* default (true)
|
|
627
|
+
* @since 5.0.7
|
|
628
|
+
*/
|
|
629
|
+
isSQL92?: boolean;
|
|
581
630
|
}
|
|
582
631
|
export interface capSQLiteQueryOptions {
|
|
583
632
|
/**
|
|
@@ -600,6 +649,13 @@ export interface capSQLiteQueryOptions {
|
|
|
600
649
|
* @since 4.1.0-7
|
|
601
650
|
*/
|
|
602
651
|
readonly?: boolean;
|
|
652
|
+
/**
|
|
653
|
+
* Compatibility SQL92
|
|
654
|
+
* !!! ELECTRON ONLY
|
|
655
|
+
* default (true)
|
|
656
|
+
* @since 5.0.7
|
|
657
|
+
*/
|
|
658
|
+
isSQL92?: boolean;
|
|
603
659
|
}
|
|
604
660
|
export interface capSQLiteImportOptions {
|
|
605
661
|
/**
|
|
@@ -1301,6 +1357,30 @@ export interface ISQLiteDBConnection {
|
|
|
1301
1357
|
* @since 2.9.0 refactor
|
|
1302
1358
|
*/
|
|
1303
1359
|
close(): Promise<void>;
|
|
1360
|
+
/**
|
|
1361
|
+
* Begin Database Transaction
|
|
1362
|
+
* @returns capSQLiteChanges
|
|
1363
|
+
* @since 5.0.7
|
|
1364
|
+
*/
|
|
1365
|
+
beginTransaction(): Promise<capSQLiteChanges>;
|
|
1366
|
+
/**
|
|
1367
|
+
* Commit Database Transaction
|
|
1368
|
+
* @returns capSQLiteChanges
|
|
1369
|
+
* @since 5.0.7
|
|
1370
|
+
*/
|
|
1371
|
+
commitTransaction(): Promise<capSQLiteChanges>;
|
|
1372
|
+
/**
|
|
1373
|
+
* Rollback Database Transaction
|
|
1374
|
+
* @returns capSQLiteChanges
|
|
1375
|
+
* @since 5.0.7
|
|
1376
|
+
*/
|
|
1377
|
+
rollbackTransaction(): Promise<capSQLiteChanges>;
|
|
1378
|
+
/**
|
|
1379
|
+
* Is Database Transaction Active
|
|
1380
|
+
* @returns capSQLiteResult
|
|
1381
|
+
* @since 5.0.7
|
|
1382
|
+
*/
|
|
1383
|
+
isTransactionActive(): Promise<capSQLiteResult>;
|
|
1304
1384
|
/**
|
|
1305
1385
|
* Get Database Url
|
|
1306
1386
|
* @returns Promise<capSQLiteUrl>
|
|
@@ -1333,7 +1413,7 @@ export interface ISQLiteDBConnection {
|
|
|
1333
1413
|
* @returns Promise<capSQLiteChanges>
|
|
1334
1414
|
* @since 2.9.0 refactor
|
|
1335
1415
|
*/
|
|
1336
|
-
execute(statements: string, transaction?: boolean): Promise<capSQLiteChanges>;
|
|
1416
|
+
execute(statements: string, transaction?: boolean, isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1337
1417
|
/**
|
|
1338
1418
|
* Execute SQLite DB Connection Query
|
|
1339
1419
|
* @param statement
|
|
@@ -1341,7 +1421,7 @@ export interface ISQLiteDBConnection {
|
|
|
1341
1421
|
* @returns Promise<Promise<DBSQLiteValues>
|
|
1342
1422
|
* @since 2.9.0 refactor
|
|
1343
1423
|
*/
|
|
1344
|
-
query(statement: string, values?: any[]): Promise<DBSQLiteValues>;
|
|
1424
|
+
query(statement: string, values?: any[], isSQL92?: boolean): Promise<DBSQLiteValues>;
|
|
1345
1425
|
/**
|
|
1346
1426
|
* Execute SQLite DB Connection Raw Statement
|
|
1347
1427
|
* @param statement
|
|
@@ -1349,14 +1429,14 @@ export interface ISQLiteDBConnection {
|
|
|
1349
1429
|
* @returns Promise<capSQLiteChanges>
|
|
1350
1430
|
* @since 2.9.0 refactor
|
|
1351
1431
|
*/
|
|
1352
|
-
run(statement: string, values?: any[], transaction?: boolean, returnMode?: string): Promise<capSQLiteChanges>;
|
|
1432
|
+
run(statement: string, values?: any[], transaction?: boolean, returnMode?: string, isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1353
1433
|
/**
|
|
1354
1434
|
* Execute SQLite DB Connection Set
|
|
1355
1435
|
* @param set
|
|
1356
1436
|
* @returns Promise<capSQLiteChanges>
|
|
1357
1437
|
* @since 2.9.0 refactor
|
|
1358
1438
|
*/
|
|
1359
|
-
executeSet(set: capSQLiteSet[], transaction?: boolean, returnMode?: string): Promise<capSQLiteChanges>;
|
|
1439
|
+
executeSet(set: capSQLiteSet[], transaction?: boolean, returnMode?: string, isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1360
1440
|
/**
|
|
1361
1441
|
* Check if a SQLite DB Connection exists
|
|
1362
1442
|
* @returns Promise<capSQLiteResult>
|
|
@@ -1421,13 +1501,14 @@ export interface ISQLiteDBConnection {
|
|
|
1421
1501
|
/**
|
|
1422
1502
|
*
|
|
1423
1503
|
* @param txn
|
|
1424
|
-
* @
|
|
1504
|
+
* @param isSQL92
|
|
1505
|
+
* @returns Promise<capSQLiteChanges> since 5.0.7
|
|
1425
1506
|
* @since 3.4.0
|
|
1426
1507
|
*/
|
|
1427
1508
|
executeTransaction(txn: {
|
|
1428
1509
|
statement: string;
|
|
1429
1510
|
values?: any[];
|
|
1430
|
-
}[]): Promise<
|
|
1511
|
+
}[], isSQL92: boolean): Promise<capSQLiteChanges>;
|
|
1431
1512
|
}
|
|
1432
1513
|
/**
|
|
1433
1514
|
* SQLiteDBConnection Class
|
|
@@ -1441,15 +1522,19 @@ export declare class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
1441
1522
|
getConnectionReadOnly(): boolean;
|
|
1442
1523
|
open(): Promise<void>;
|
|
1443
1524
|
close(): Promise<void>;
|
|
1525
|
+
beginTransaction(): Promise<capSQLiteChanges>;
|
|
1526
|
+
commitTransaction(): Promise<capSQLiteChanges>;
|
|
1527
|
+
rollbackTransaction(): Promise<capSQLiteChanges>;
|
|
1528
|
+
isTransactionActive(): Promise<capSQLiteResult>;
|
|
1444
1529
|
loadExtension(path: string): Promise<void>;
|
|
1445
1530
|
enableLoadExtension(toggle: boolean): Promise<void>;
|
|
1446
1531
|
getUrl(): Promise<capSQLiteUrl>;
|
|
1447
1532
|
getVersion(): Promise<capVersionResult>;
|
|
1448
1533
|
getTableList(): Promise<DBSQLiteValues>;
|
|
1449
|
-
execute(statements: string, transaction?: boolean): Promise<capSQLiteChanges>;
|
|
1450
|
-
query(statement: string, values?: any[]): Promise<DBSQLiteValues>;
|
|
1451
|
-
run(statement: string, values?: any[], transaction?: boolean, returnMode?: string): Promise<capSQLiteChanges>;
|
|
1452
|
-
executeSet(set: capSQLiteSet[], transaction?: boolean, returnMode?: string): Promise<capSQLiteChanges>;
|
|
1534
|
+
execute(statements: string, transaction?: boolean, isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1535
|
+
query(statement: string, values?: any[], isSQL92?: boolean): Promise<DBSQLiteValues>;
|
|
1536
|
+
run(statement: string, values?: any[], transaction?: boolean, returnMode?: string, isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1537
|
+
executeSet(set: capSQLiteSet[], transaction?: boolean, returnMode?: string, isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1453
1538
|
isExists(): Promise<capSQLiteResult>;
|
|
1454
1539
|
isTable(table: string): Promise<capSQLiteResult>;
|
|
1455
1540
|
isDBOpen(): Promise<capSQLiteResult>;
|
|
@@ -1462,6 +1547,6 @@ export declare class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
1462
1547
|
executeTransaction(txn: {
|
|
1463
1548
|
statement: string;
|
|
1464
1549
|
values?: any[];
|
|
1465
|
-
}[]): Promise<
|
|
1550
|
+
}[], isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1466
1551
|
private reorderRows;
|
|
1467
1552
|
}
|
package/dist/esm/definitions.js
CHANGED
|
@@ -468,40 +468,69 @@ export class SQLiteDBConnection {
|
|
|
468
468
|
return Promise.reject(err);
|
|
469
469
|
}
|
|
470
470
|
}
|
|
471
|
+
async beginTransaction() {
|
|
472
|
+
try {
|
|
473
|
+
const changes = await this.sqlite
|
|
474
|
+
.beginTransaction({ database: this.dbName });
|
|
475
|
+
return Promise.resolve(changes);
|
|
476
|
+
}
|
|
477
|
+
catch (err) {
|
|
478
|
+
return Promise.reject(err);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
async commitTransaction() {
|
|
482
|
+
try {
|
|
483
|
+
const changes = await this.sqlite
|
|
484
|
+
.commitTransaction({ database: this.dbName });
|
|
485
|
+
return Promise.resolve(changes);
|
|
486
|
+
}
|
|
487
|
+
catch (err) {
|
|
488
|
+
return Promise.reject(err);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
async rollbackTransaction() {
|
|
492
|
+
try {
|
|
493
|
+
const changes = await this.sqlite
|
|
494
|
+
.rollbackTransaction({ database: this.dbName });
|
|
495
|
+
return Promise.resolve(changes);
|
|
496
|
+
}
|
|
497
|
+
catch (err) {
|
|
498
|
+
return Promise.reject(err);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
async isTransactionActive() {
|
|
502
|
+
try {
|
|
503
|
+
const result = await this.sqlite
|
|
504
|
+
.isTransactionActive({ database: this.dbName });
|
|
505
|
+
return Promise.resolve(result);
|
|
506
|
+
}
|
|
507
|
+
catch (err) {
|
|
508
|
+
return Promise.reject(err);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
471
511
|
async loadExtension(path) {
|
|
472
512
|
try {
|
|
473
|
-
console.log(`database: ${this.dbName}`);
|
|
474
|
-
console.log(`readonly: ${this.readonly}}`);
|
|
475
|
-
console.log(`path: ${path}}`);
|
|
476
513
|
await this.sqlite.loadExtension({
|
|
477
514
|
database: this.dbName,
|
|
478
515
|
path: path,
|
|
479
516
|
readonly: this.readonly,
|
|
480
517
|
});
|
|
481
|
-
console.log(`loadExtension successful`);
|
|
482
518
|
return Promise.resolve();
|
|
483
519
|
}
|
|
484
520
|
catch (err) {
|
|
485
|
-
console.log(`loadExtension failed `);
|
|
486
521
|
return Promise.reject(err);
|
|
487
522
|
}
|
|
488
523
|
}
|
|
489
524
|
async enableLoadExtension(toggle) {
|
|
490
525
|
try {
|
|
491
|
-
console.log(`database: ${this.dbName}`);
|
|
492
|
-
console.log(`readonly: ${this.readonly}`);
|
|
493
|
-
console.log(`toggle: ${toggle}`);
|
|
494
526
|
await this.sqlite.enableLoadExtension({
|
|
495
527
|
database: this.dbName,
|
|
496
528
|
toggle: toggle,
|
|
497
529
|
readonly: this.readonly,
|
|
498
530
|
});
|
|
499
|
-
console.log(`enableLoadExtension successful`);
|
|
500
531
|
return Promise.resolve();
|
|
501
532
|
}
|
|
502
533
|
catch (err) {
|
|
503
|
-
console.log(err);
|
|
504
|
-
console.log(`enableLoadExtension failed `);
|
|
505
534
|
return Promise.reject(err);
|
|
506
535
|
}
|
|
507
536
|
}
|
|
@@ -541,7 +570,7 @@ export class SQLiteDBConnection {
|
|
|
541
570
|
return Promise.reject(err);
|
|
542
571
|
}
|
|
543
572
|
}
|
|
544
|
-
async execute(statements, transaction = true) {
|
|
573
|
+
async execute(statements, transaction = true, isSQL92 = true) {
|
|
545
574
|
try {
|
|
546
575
|
if (!this.readonly) {
|
|
547
576
|
const res = await this.sqlite.execute({
|
|
@@ -549,6 +578,7 @@ export class SQLiteDBConnection {
|
|
|
549
578
|
statements: statements,
|
|
550
579
|
transaction: transaction,
|
|
551
580
|
readonly: false,
|
|
581
|
+
isSQL92: isSQL92
|
|
552
582
|
});
|
|
553
583
|
return Promise.resolve(res);
|
|
554
584
|
}
|
|
@@ -560,7 +590,7 @@ export class SQLiteDBConnection {
|
|
|
560
590
|
return Promise.reject(err);
|
|
561
591
|
}
|
|
562
592
|
}
|
|
563
|
-
async query(statement, values) {
|
|
593
|
+
async query(statement, values, isSQL92 = true) {
|
|
564
594
|
let res;
|
|
565
595
|
try {
|
|
566
596
|
if (values && values.length > 0) {
|
|
@@ -569,6 +599,7 @@ export class SQLiteDBConnection {
|
|
|
569
599
|
statement: statement,
|
|
570
600
|
values: values,
|
|
571
601
|
readonly: this.readonly,
|
|
602
|
+
isSql92: true
|
|
572
603
|
});
|
|
573
604
|
}
|
|
574
605
|
else {
|
|
@@ -577,6 +608,7 @@ export class SQLiteDBConnection {
|
|
|
577
608
|
statement: statement,
|
|
578
609
|
values: [],
|
|
579
610
|
readonly: this.readonly,
|
|
611
|
+
isSQL92: isSQL92
|
|
580
612
|
});
|
|
581
613
|
}
|
|
582
614
|
// reorder rows for ios
|
|
@@ -587,7 +619,7 @@ export class SQLiteDBConnection {
|
|
|
587
619
|
return Promise.reject(err);
|
|
588
620
|
}
|
|
589
621
|
}
|
|
590
|
-
async run(statement, values, transaction = true, returnMode = 'no') {
|
|
622
|
+
async run(statement, values, transaction = true, returnMode = 'no', isSQL92 = true) {
|
|
591
623
|
let res;
|
|
592
624
|
try {
|
|
593
625
|
if (!this.readonly) {
|
|
@@ -602,6 +634,7 @@ export class SQLiteDBConnection {
|
|
|
602
634
|
transaction: transaction,
|
|
603
635
|
readonly: false,
|
|
604
636
|
returnMode: mRetMode,
|
|
637
|
+
isSQL92: true
|
|
605
638
|
});
|
|
606
639
|
// }
|
|
607
640
|
}
|
|
@@ -616,6 +649,7 @@ export class SQLiteDBConnection {
|
|
|
616
649
|
transaction: transaction,
|
|
617
650
|
readonly: false,
|
|
618
651
|
returnMode: mRetMode,
|
|
652
|
+
isSQL92: isSQL92
|
|
619
653
|
});
|
|
620
654
|
}
|
|
621
655
|
// reorder rows for ios
|
|
@@ -630,7 +664,7 @@ export class SQLiteDBConnection {
|
|
|
630
664
|
return Promise.reject(err);
|
|
631
665
|
}
|
|
632
666
|
}
|
|
633
|
-
async executeSet(set, transaction = true, returnMode = 'no') {
|
|
667
|
+
async executeSet(set, transaction = true, returnMode = 'no', isSQL92 = true) {
|
|
634
668
|
let res;
|
|
635
669
|
try {
|
|
636
670
|
if (!this.readonly) {
|
|
@@ -640,6 +674,7 @@ export class SQLiteDBConnection {
|
|
|
640
674
|
transaction: transaction,
|
|
641
675
|
readonly: false,
|
|
642
676
|
returnMode: returnMode,
|
|
677
|
+
isSQL92: isSQL92
|
|
643
678
|
});
|
|
644
679
|
// }
|
|
645
680
|
// reorder rows for ios
|
|
@@ -788,17 +823,25 @@ export class SQLiteDBConnection {
|
|
|
788
823
|
return Promise.reject(err);
|
|
789
824
|
}
|
|
790
825
|
}
|
|
791
|
-
async executeTransaction(txn) {
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
826
|
+
async executeTransaction(txn, isSQL92 = true) {
|
|
827
|
+
let changes = 0;
|
|
828
|
+
let isActive = false;
|
|
829
|
+
if (!this.readonly) {
|
|
830
|
+
try {
|
|
831
|
+
await this.sqlite.beginTransaction({
|
|
832
|
+
database: this.dbName
|
|
798
833
|
});
|
|
799
|
-
|
|
800
|
-
|
|
834
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
835
|
+
database: this.dbName
|
|
836
|
+
});
|
|
837
|
+
if (!isActive) {
|
|
838
|
+
return Promise.reject('After Begin Transaction, no transaction active');
|
|
801
839
|
}
|
|
840
|
+
}
|
|
841
|
+
catch (err) {
|
|
842
|
+
return Promise.reject(err);
|
|
843
|
+
}
|
|
844
|
+
try {
|
|
802
845
|
for (const task of txn) {
|
|
803
846
|
if (task.values && task.values.length > 0) {
|
|
804
847
|
const retMode = task.statement.toUpperCase().includes('RETURNING')
|
|
@@ -811,11 +854,12 @@ export class SQLiteDBConnection {
|
|
|
811
854
|
transaction: false,
|
|
812
855
|
readonly: false,
|
|
813
856
|
returnMode: retMode,
|
|
857
|
+
isSQL92: isSQL92
|
|
814
858
|
});
|
|
815
|
-
if (ret.changes.
|
|
816
|
-
|
|
817
|
-
return Promise.reject('Error in transaction run ');
|
|
859
|
+
if (ret.changes.changes <= 0) {
|
|
860
|
+
throw new Error('Error in transaction method run ');
|
|
818
861
|
}
|
|
862
|
+
changes += ret.changes.changes;
|
|
819
863
|
}
|
|
820
864
|
else {
|
|
821
865
|
const ret = await this.sqlite.execute({
|
|
@@ -824,37 +868,42 @@ export class SQLiteDBConnection {
|
|
|
824
868
|
transaction: false,
|
|
825
869
|
readonly: false,
|
|
826
870
|
});
|
|
871
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
872
|
+
database: this.dbName
|
|
873
|
+
});
|
|
827
874
|
if (ret.changes.changes < 0) {
|
|
828
|
-
|
|
829
|
-
database: this.dbName,
|
|
830
|
-
statements: 'ROLLBACK;',
|
|
831
|
-
transaction: false,
|
|
832
|
-
readonly: false,
|
|
833
|
-
});
|
|
834
|
-
return Promise.reject('Error in transaction execute ');
|
|
875
|
+
throw new Error('Error in transaction method execute ');
|
|
835
876
|
}
|
|
877
|
+
changes += ret.changes.changes;
|
|
836
878
|
}
|
|
837
879
|
}
|
|
838
|
-
await this.sqlite.
|
|
839
|
-
database: this.dbName
|
|
840
|
-
statements: 'COMMIT;',
|
|
841
|
-
transaction: false,
|
|
842
|
-
readonly: false,
|
|
880
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
881
|
+
database: this.dbName
|
|
843
882
|
});
|
|
844
|
-
|
|
883
|
+
if (isActive) {
|
|
884
|
+
const retC = await this.sqlite.commitTransaction({
|
|
885
|
+
database: this.dbName
|
|
886
|
+
});
|
|
887
|
+
changes += retC.changes.changes;
|
|
888
|
+
}
|
|
889
|
+
const retChanges = { changes: { changes: changes } };
|
|
890
|
+
return Promise.resolve(retChanges);
|
|
845
891
|
}
|
|
846
|
-
|
|
847
|
-
|
|
892
|
+
catch (err) {
|
|
893
|
+
const msg = err.message ? err.message : err;
|
|
894
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
895
|
+
database: this.dbName
|
|
896
|
+
});
|
|
897
|
+
if (isActive) {
|
|
898
|
+
await this.sqlite.rollbackTransaction({
|
|
899
|
+
database: this.dbName,
|
|
900
|
+
});
|
|
901
|
+
}
|
|
902
|
+
return Promise.reject(msg);
|
|
848
903
|
}
|
|
849
904
|
}
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
database: this.dbName,
|
|
853
|
-
statements: 'ROLLBACK;',
|
|
854
|
-
transaction: false,
|
|
855
|
-
readonly: false,
|
|
856
|
-
});
|
|
857
|
-
return Promise.reject(err);
|
|
905
|
+
else {
|
|
906
|
+
return Promise.reject('not allowed in read-only mode');
|
|
858
907
|
}
|
|
859
908
|
}
|
|
860
909
|
async reorderRows(res) {
|