@capacitor-community/sqlite 4.1.0-4 → 4.1.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 +8 -5
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +160 -92
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +41 -21
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +92 -107
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +36 -319
- package/dist/esm/definitions.d.ts +32 -15
- package/dist/esm/definitions.js +191 -105
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +191 -105
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +191 -105
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +47 -332
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +123 -59
- package/ios/Plugin/CapacitorSQLitePlugin.swift +53 -20
- package/ios/Plugin/Database.swift +15 -11
- package/ios/Plugin/Utils/UtilsUpgrade.swift +36 -369
- package/package.json +2 -2
package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java
CHANGED
|
@@ -284,7 +284,7 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
284
284
|
dbName = call.getString("database");
|
|
285
285
|
dbVersion = call.getInt("version", 1);
|
|
286
286
|
|
|
287
|
-
|
|
287
|
+
Boolean encrypted = call.getBoolean("encrypted", false);
|
|
288
288
|
if (encrypted) {
|
|
289
289
|
inMode = call.getString("mode", "no-encryption");
|
|
290
290
|
if (
|
|
@@ -299,10 +299,11 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
299
299
|
} else {
|
|
300
300
|
inMode = "no-encryption";
|
|
301
301
|
}
|
|
302
|
+
boolean readOnly = call.getBoolean("readonly", false);
|
|
302
303
|
Dictionary<Integer, JSONObject> upgDict = versionUpgrades.get(dbName);
|
|
303
304
|
if (implementation != null) {
|
|
304
305
|
try {
|
|
305
|
-
implementation.createConnection(dbName, encrypted, inMode, dbVersion, upgDict);
|
|
306
|
+
implementation.createConnection(dbName, encrypted, inMode, dbVersion, upgDict, readOnly);
|
|
306
307
|
rHandler.retResult(call, null, null);
|
|
307
308
|
return;
|
|
308
309
|
} catch (Exception e) {
|
|
@@ -330,9 +331,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
330
331
|
return;
|
|
331
332
|
}
|
|
332
333
|
String dbName = call.getString("database");
|
|
334
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
333
335
|
if (implementation != null) {
|
|
334
336
|
try {
|
|
335
|
-
implementation.open(dbName);
|
|
337
|
+
implementation.open(dbName, readOnly);
|
|
336
338
|
rHandler.retResult(call, null, null);
|
|
337
339
|
return;
|
|
338
340
|
} catch (Exception e) {
|
|
@@ -360,9 +362,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
360
362
|
return;
|
|
361
363
|
}
|
|
362
364
|
String dbName = call.getString("database");
|
|
365
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
363
366
|
if (implementation != null) {
|
|
364
367
|
try {
|
|
365
|
-
implementation.close(dbName);
|
|
368
|
+
implementation.close(dbName, readOnly);
|
|
366
369
|
rHandler.retResult(call, null, null);
|
|
367
370
|
return;
|
|
368
371
|
} catch (Exception e) {
|
|
@@ -390,9 +393,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
390
393
|
return;
|
|
391
394
|
}
|
|
392
395
|
String dbName = call.getString("database");
|
|
396
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
393
397
|
if (implementation != null) {
|
|
394
398
|
try {
|
|
395
|
-
String res = implementation.getUrl(dbName);
|
|
399
|
+
String res = implementation.getUrl(dbName, readOnly);
|
|
396
400
|
rHandler.retUrl(call, res, null);
|
|
397
401
|
return;
|
|
398
402
|
} catch (Exception e) {
|
|
@@ -420,9 +424,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
420
424
|
return;
|
|
421
425
|
}
|
|
422
426
|
String dbName = call.getString("database");
|
|
427
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
423
428
|
if (implementation != null) {
|
|
424
429
|
try {
|
|
425
|
-
Integer res = implementation.getVersion(dbName);
|
|
430
|
+
Integer res = implementation.getVersion(dbName, readOnly);
|
|
426
431
|
rHandler.retVersion(call, res, null);
|
|
427
432
|
return;
|
|
428
433
|
} catch (Exception e) {
|
|
@@ -480,9 +485,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
480
485
|
return;
|
|
481
486
|
}
|
|
482
487
|
String dbName = call.getString("database");
|
|
488
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
483
489
|
if (implementation != null) {
|
|
484
490
|
try {
|
|
485
|
-
implementation.closeConnection(dbName);
|
|
491
|
+
implementation.closeConnection(dbName, readOnly);
|
|
486
492
|
rHandler.retResult(call, null, null);
|
|
487
493
|
return;
|
|
488
494
|
} catch (Exception e) {
|
|
@@ -602,9 +608,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
602
608
|
return;
|
|
603
609
|
}
|
|
604
610
|
String tableName = call.getString("table");
|
|
611
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
605
612
|
if (implementation != null) {
|
|
606
613
|
try {
|
|
607
|
-
Boolean res = implementation.isTableExists(dbName, tableName);
|
|
614
|
+
Boolean res = implementation.isTableExists(dbName, tableName, readOnly);
|
|
608
615
|
rHandler.retResult(call, res, null);
|
|
609
616
|
return;
|
|
610
617
|
} catch (Exception e) {
|
|
@@ -794,10 +801,11 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
794
801
|
}
|
|
795
802
|
String statements = call.getString("statements");
|
|
796
803
|
Boolean transaction = call.getBoolean("transaction", true);
|
|
804
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
797
805
|
|
|
798
806
|
if (implementation != null) {
|
|
799
807
|
try {
|
|
800
|
-
JSObject res = implementation.execute(dbName, statements, transaction);
|
|
808
|
+
JSObject res = implementation.execute(dbName, statements, transaction, readOnly);
|
|
801
809
|
rHandler.retChanges(call, res, null);
|
|
802
810
|
return;
|
|
803
811
|
} catch (Exception e) {
|
|
@@ -852,9 +860,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
852
860
|
}
|
|
853
861
|
}
|
|
854
862
|
Boolean transaction = call.getBoolean("transaction", true);
|
|
863
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
855
864
|
if (implementation != null) {
|
|
856
865
|
try {
|
|
857
|
-
JSObject res = implementation.executeSet(dbName, set, transaction);
|
|
866
|
+
JSObject res = implementation.executeSet(dbName, set, transaction, readOnly);
|
|
858
867
|
rHandler.retChanges(call, res, null);
|
|
859
868
|
return;
|
|
860
869
|
} catch (Exception e) {
|
|
@@ -898,9 +907,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
898
907
|
JSArray values = call.getArray("values");
|
|
899
908
|
|
|
900
909
|
Boolean transaction = call.getBoolean("transaction", true);
|
|
910
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
901
911
|
if (implementation != null) {
|
|
902
912
|
try {
|
|
903
|
-
JSObject res = implementation.run(dbName, statement, values, transaction);
|
|
913
|
+
JSObject res = implementation.run(dbName, statement, values, transaction, readOnly);
|
|
904
914
|
rHandler.retChanges(call, res, null);
|
|
905
915
|
return;
|
|
906
916
|
} catch (Exception e) {
|
|
@@ -940,9 +950,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
940
950
|
return;
|
|
941
951
|
}
|
|
942
952
|
JSArray values = call.getArray("values");
|
|
953
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
943
954
|
if (implementation != null) {
|
|
944
955
|
try {
|
|
945
|
-
JSArray res = implementation.query(dbName, statement, values);
|
|
956
|
+
JSArray res = implementation.query(dbName, statement, values, readOnly);
|
|
946
957
|
rHandler.retValues(call, res, null);
|
|
947
958
|
return;
|
|
948
959
|
} catch (Exception e) {
|
|
@@ -964,9 +975,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
964
975
|
return;
|
|
965
976
|
}
|
|
966
977
|
String dbName = call.getString("database");
|
|
978
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
967
979
|
if (implementation != null) {
|
|
968
980
|
try {
|
|
969
|
-
JSArray res = implementation.getTableList(dbName);
|
|
981
|
+
JSArray res = implementation.getTableList(dbName, readOnly);
|
|
970
982
|
rHandler.retValues(call, res, null);
|
|
971
983
|
return;
|
|
972
984
|
} catch (Exception e) {
|
|
@@ -994,10 +1006,11 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
994
1006
|
return;
|
|
995
1007
|
}
|
|
996
1008
|
String dbName = call.getString("database");
|
|
1009
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
997
1010
|
|
|
998
1011
|
if (implementation != null) {
|
|
999
1012
|
try {
|
|
1000
|
-
Boolean res = implementation.isDBExists(dbName);
|
|
1013
|
+
Boolean res = implementation.isDBExists(dbName, readOnly);
|
|
1001
1014
|
rHandler.retResult(call, res, null);
|
|
1002
1015
|
return;
|
|
1003
1016
|
} catch (Exception e) {
|
|
@@ -1025,9 +1038,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1025
1038
|
return;
|
|
1026
1039
|
}
|
|
1027
1040
|
String dbName = call.getString("database");
|
|
1041
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
1028
1042
|
if (implementation != null) {
|
|
1029
1043
|
try {
|
|
1030
|
-
Boolean res = implementation.isDBOpen(dbName);
|
|
1044
|
+
Boolean res = implementation.isDBOpen(dbName, readOnly);
|
|
1031
1045
|
rHandler.retResult(call, res, null);
|
|
1032
1046
|
return;
|
|
1033
1047
|
} catch (Exception e) {
|
|
@@ -1055,9 +1069,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1055
1069
|
return;
|
|
1056
1070
|
}
|
|
1057
1071
|
String dbName = call.getString("database");
|
|
1072
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
1058
1073
|
if (implementation != null) {
|
|
1059
1074
|
try {
|
|
1060
|
-
implementation.deleteDatabase(dbName);
|
|
1075
|
+
implementation.deleteDatabase(dbName, readOnly);
|
|
1061
1076
|
rHandler.retResult(call, null, null);
|
|
1062
1077
|
return;
|
|
1063
1078
|
} catch (Exception e) {
|
|
@@ -1087,9 +1102,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1087
1102
|
return;
|
|
1088
1103
|
}
|
|
1089
1104
|
String dbName = call.getString("database");
|
|
1105
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
1090
1106
|
if (implementation != null) {
|
|
1091
1107
|
try {
|
|
1092
|
-
JSObject res = implementation.createSyncTable(dbName);
|
|
1108
|
+
JSObject res = implementation.createSyncTable(dbName, readOnly);
|
|
1093
1109
|
rHandler.retChanges(call, res, null);
|
|
1094
1110
|
return;
|
|
1095
1111
|
} catch (Exception e) {
|
|
@@ -1124,9 +1140,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1124
1140
|
return;
|
|
1125
1141
|
}
|
|
1126
1142
|
String syncDate = call.getString("syncdate");
|
|
1143
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
1127
1144
|
if (implementation != null) {
|
|
1128
1145
|
try {
|
|
1129
|
-
implementation.setSyncDate(dbName, syncDate);
|
|
1146
|
+
implementation.setSyncDate(dbName, syncDate, readOnly);
|
|
1130
1147
|
rHandler.retResult(call, null, null);
|
|
1131
1148
|
return;
|
|
1132
1149
|
} catch (Exception e) {
|
|
@@ -1156,9 +1173,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1156
1173
|
return;
|
|
1157
1174
|
}
|
|
1158
1175
|
String dbName = call.getString("database");
|
|
1176
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
1159
1177
|
if (implementation != null) {
|
|
1160
1178
|
try {
|
|
1161
|
-
long syncDate = implementation.getSyncDate(dbName);
|
|
1179
|
+
long syncDate = implementation.getSyncDate(dbName, readOnly);
|
|
1162
1180
|
rHandler.retSyncDate(call, syncDate, null);
|
|
1163
1181
|
return;
|
|
1164
1182
|
} catch (Exception e) {
|
|
@@ -1300,10 +1318,11 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1300
1318
|
rHandler.retJSObject(call, retObj, msg);
|
|
1301
1319
|
return;
|
|
1302
1320
|
}
|
|
1321
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
1303
1322
|
|
|
1304
1323
|
if (implementation != null) {
|
|
1305
1324
|
try {
|
|
1306
|
-
JSObject res = implementation.exportToJson(dbName, expMode);
|
|
1325
|
+
JSObject res = implementation.exportToJson(dbName, expMode, readOnly);
|
|
1307
1326
|
rHandler.retJSObject(call, res, null);
|
|
1308
1327
|
return;
|
|
1309
1328
|
} catch (Exception e) {
|
|
@@ -1327,9 +1346,10 @@ public class CapacitorSQLitePlugin extends Plugin {
|
|
|
1327
1346
|
return;
|
|
1328
1347
|
}
|
|
1329
1348
|
String dbName = call.getString("database");
|
|
1349
|
+
Boolean readOnly = call.getBoolean("readonly", false);
|
|
1330
1350
|
if (implementation != null) {
|
|
1331
1351
|
try {
|
|
1332
|
-
implementation.deleteExportedRows(dbName);
|
|
1352
|
+
implementation.deleteExportedRows(dbName, readOnly);
|
|
1333
1353
|
rHandler.retResult(call, null, null);
|
|
1334
1354
|
return;
|
|
1335
1355
|
} catch (Exception e) {
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java
CHANGED
|
@@ -8,21 +8,16 @@ import static android.database.Cursor.FIELD_TYPE_STRING;
|
|
|
8
8
|
|
|
9
9
|
import android.content.Context;
|
|
10
10
|
import android.content.SharedPreferences;
|
|
11
|
-
import android.text.TextUtils;
|
|
12
11
|
import android.util.Log;
|
|
13
12
|
import androidx.sqlite.db.SimpleSQLiteQuery;
|
|
14
13
|
import androidx.sqlite.db.SupportSQLiteDatabase;
|
|
15
14
|
import androidx.sqlite.db.SupportSQLiteStatement;
|
|
16
15
|
import com.getcapacitor.JSArray;
|
|
17
16
|
import com.getcapacitor.JSObject;
|
|
18
|
-
import com.getcapacitor.community.database.sqlite.SQLite.GlobalSQLite;
|
|
19
17
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.ExportToJson;
|
|
20
18
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.ImportFromJson;
|
|
21
|
-
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonIndex;
|
|
22
19
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonSQLite;
|
|
23
20
|
import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.UtilsJson;
|
|
24
|
-
import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLCipher;
|
|
25
|
-
import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
|
|
26
21
|
import java.io.File;
|
|
27
22
|
import java.text.SimpleDateFormat;
|
|
28
23
|
import java.util.ArrayList;
|
|
@@ -31,7 +26,6 @@ import java.util.Collections;
|
|
|
31
26
|
import java.util.Date;
|
|
32
27
|
import java.util.Dictionary;
|
|
33
28
|
import java.util.Hashtable;
|
|
34
|
-
import java.util.Iterator;
|
|
35
29
|
import java.util.List;
|
|
36
30
|
import net.sqlcipher.Cursor;
|
|
37
31
|
import net.sqlcipher.database.SQLiteDatabase;
|
|
@@ -44,27 +38,28 @@ public class Database {
|
|
|
44
38
|
|
|
45
39
|
private static final String TAG = Database.class.getName();
|
|
46
40
|
private Boolean _isOpen = false;
|
|
47
|
-
private String _dbName;
|
|
48
|
-
private Context _context;
|
|
49
|
-
private String _mode;
|
|
41
|
+
private final String _dbName;
|
|
42
|
+
private final Context _context;
|
|
43
|
+
private final String _mode;
|
|
50
44
|
private String _secret;
|
|
51
|
-
private Boolean _encrypted;
|
|
52
|
-
private Boolean _isEncryption;
|
|
53
|
-
private SharedPreferences _sharedPreferences;
|
|
54
|
-
private
|
|
55
|
-
private
|
|
56
|
-
private
|
|
45
|
+
private final Boolean _encrypted;
|
|
46
|
+
private final Boolean _isEncryption;
|
|
47
|
+
private final SharedPreferences _sharedPreferences;
|
|
48
|
+
private final Boolean _readOnly;
|
|
49
|
+
private final File _file;
|
|
50
|
+
private final int _version;
|
|
51
|
+
private final GlobalSQLite _globVar;
|
|
57
52
|
private SupportSQLiteDatabase _db = null;
|
|
58
|
-
private UtilsSQLite _uSqlite;
|
|
59
|
-
private UtilsSQLCipher _uCipher;
|
|
60
|
-
private UtilsFile _uFile;
|
|
61
|
-
private UtilsJson _uJson;
|
|
62
|
-
private UtilsUpgrade _uUpg;
|
|
63
|
-
private UtilsDrop _uDrop;
|
|
64
|
-
private UtilsSecret _uSecret;
|
|
53
|
+
private final UtilsSQLite _uSqlite;
|
|
54
|
+
private final UtilsSQLCipher _uCipher;
|
|
55
|
+
private final UtilsFile _uFile;
|
|
56
|
+
private final UtilsJson _uJson;
|
|
57
|
+
private final UtilsUpgrade _uUpg;
|
|
58
|
+
private final UtilsDrop _uDrop;
|
|
59
|
+
private final UtilsSecret _uSecret;
|
|
65
60
|
private Dictionary<Integer, JSONObject> _vUpgObject = new Hashtable<>();
|
|
66
|
-
private ImportFromJson fromJson = new ImportFromJson();
|
|
67
|
-
private ExportToJson toJson = new ExportToJson();
|
|
61
|
+
private final ImportFromJson fromJson = new ImportFromJson();
|
|
62
|
+
private final ExportToJson toJson = new ExportToJson();
|
|
68
63
|
private Boolean ncDB = false;
|
|
69
64
|
|
|
70
65
|
public Database(
|
|
@@ -75,7 +70,8 @@ public class Database {
|
|
|
75
70
|
int version,
|
|
76
71
|
Boolean isEncryption,
|
|
77
72
|
Dictionary<Integer, JSONObject> vUpgObject,
|
|
78
|
-
SharedPreferences sharedPreferences
|
|
73
|
+
SharedPreferences sharedPreferences,
|
|
74
|
+
Boolean readonly
|
|
79
75
|
) {
|
|
80
76
|
this._context = context;
|
|
81
77
|
this._dbName = dbName;
|
|
@@ -85,6 +81,7 @@ public class Database {
|
|
|
85
81
|
this._version = version;
|
|
86
82
|
this._vUpgObject = vUpgObject;
|
|
87
83
|
this._sharedPreferences = sharedPreferences;
|
|
84
|
+
this._readOnly = readonly;
|
|
88
85
|
if (dbName.contains("/") && dbName.endsWith("SQLite.db")) {
|
|
89
86
|
this.ncDB = true;
|
|
90
87
|
this._file = new File(dbName);
|
|
@@ -171,7 +168,7 @@ public class Database {
|
|
|
171
168
|
}
|
|
172
169
|
}
|
|
173
170
|
try {
|
|
174
|
-
if (!isNCDB()) {
|
|
171
|
+
if (!isNCDB() && !this._readOnly) {
|
|
175
172
|
_db = SQLiteDatabase.openOrCreateDatabase(_file, password, null);
|
|
176
173
|
} else {
|
|
177
174
|
_db = SQLiteDatabase.openDatabase(String.valueOf(_file), "", null, SQLiteDatabase.OPEN_READONLY);
|
|
@@ -188,64 +185,54 @@ public class Database {
|
|
|
188
185
|
_db = null;
|
|
189
186
|
throw new Exception(msg);
|
|
190
187
|
}
|
|
191
|
-
if (
|
|
188
|
+
if (isNCDB() || this._readOnly) {
|
|
189
|
+
_isOpen = true;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
try {
|
|
193
|
+
curVersion = _db.getVersion(); // default 0
|
|
194
|
+
} catch (IllegalStateException e) {
|
|
195
|
+
String msg = "Failed in get/setVersion " + e.getMessage();
|
|
196
|
+
Log.v(TAG, msg);
|
|
197
|
+
close();
|
|
198
|
+
_db = null;
|
|
199
|
+
throw new Exception(msg);
|
|
200
|
+
} catch (SQLiteException e) {
|
|
201
|
+
String msg = "Failed in setVersion " + e.getMessage();
|
|
202
|
+
Log.v(TAG, msg);
|
|
203
|
+
close();
|
|
204
|
+
_db = null;
|
|
205
|
+
throw new Exception(msg);
|
|
206
|
+
}
|
|
207
|
+
if (_version > curVersion && _vUpgObject != null && _vUpgObject.size() > 0) {
|
|
208
|
+
// if (_vUpgObject != null && _vUpgObject.size() > 0) {
|
|
192
209
|
try {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
Log.v(TAG, msg);
|
|
201
|
-
close();
|
|
202
|
-
_db = null;
|
|
203
|
-
throw new Exception(msg);
|
|
204
|
-
} catch (SQLiteException e) {
|
|
205
|
-
String msg = "Failed in setVersion " + e.getMessage();
|
|
206
|
-
Log.v(TAG, msg);
|
|
207
|
-
close();
|
|
208
|
-
_db = null;
|
|
209
|
-
throw new Exception(msg);
|
|
210
|
-
}
|
|
211
|
-
if (_version > curVersion && _vUpgObject != null && _vUpgObject.size() > 0) {
|
|
212
|
-
// if (_vUpgObject != null && _vUpgObject.size() > 0) {
|
|
213
|
-
try {
|
|
214
|
-
_uUpg.onUpgrade(this, _context, _dbName, _vUpgObject, curVersion, _version);
|
|
215
|
-
boolean ret = _uFile.deleteBackupDB(_context, _dbName);
|
|
216
|
-
if (!ret) {
|
|
217
|
-
String msg = "Failed in deleteBackupDB backup-\" + _dbName";
|
|
218
|
-
Log.v(TAG, msg);
|
|
219
|
-
close();
|
|
220
|
-
_db = null;
|
|
221
|
-
throw new Exception(msg);
|
|
222
|
-
}
|
|
223
|
-
} catch (Exception e) {
|
|
224
|
-
// restore DB
|
|
225
|
-
boolean ret = _uFile.restoreDatabase(_context, _dbName);
|
|
226
|
-
String msg = e.getMessage();
|
|
227
|
-
if (!ret) msg += "Failed in restoreDatabase " + _dbName;
|
|
210
|
+
this._uFile.copyFile(_context, _dbName, "backup-" + _dbName);
|
|
211
|
+
|
|
212
|
+
_uUpg.onUpgrade(this, _vUpgObject, curVersion, _version);
|
|
213
|
+
|
|
214
|
+
boolean ret = _uFile.deleteBackupDB(_context, _dbName);
|
|
215
|
+
if (!ret) {
|
|
216
|
+
String msg = "Failed in deleteBackupDB backup-\" + _dbName";
|
|
228
217
|
Log.v(TAG, msg);
|
|
229
218
|
close();
|
|
230
219
|
_db = null;
|
|
231
220
|
throw new Exception(msg);
|
|
232
221
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
}
|
|
243
|
-
*/
|
|
222
|
+
} catch (Exception e) {
|
|
223
|
+
// restore DB
|
|
224
|
+
boolean ret = _uFile.restoreDatabase(_context, _dbName);
|
|
225
|
+
String msg = e.getMessage();
|
|
226
|
+
if (!ret) msg += "Failed in restoreDatabase " + _dbName;
|
|
227
|
+
Log.v(TAG, msg);
|
|
228
|
+
close();
|
|
229
|
+
_db = null;
|
|
230
|
+
throw new Exception(msg);
|
|
244
231
|
}
|
|
245
|
-
_isOpen = true;
|
|
246
|
-
return;
|
|
247
232
|
}
|
|
248
|
-
|
|
233
|
+
_isOpen = true;
|
|
234
|
+
return;
|
|
235
|
+
} else {
|
|
249
236
|
_isOpen = false;
|
|
250
237
|
_db = null;
|
|
251
238
|
throw new Exception("Database not opened");
|
|
@@ -306,11 +293,7 @@ public class Database {
|
|
|
306
293
|
* @return the existence of the database on folder
|
|
307
294
|
*/
|
|
308
295
|
public boolean isDBExists() {
|
|
309
|
-
|
|
310
|
-
return true;
|
|
311
|
-
} else {
|
|
312
|
-
return false;
|
|
313
|
-
}
|
|
296
|
+
return _file.exists();
|
|
314
297
|
}
|
|
315
298
|
|
|
316
299
|
/**
|
|
@@ -524,7 +507,7 @@ public class Database {
|
|
|
524
507
|
// Replace DELETE by UPDATE and set sql_deleted to 1
|
|
525
508
|
Integer wIdx = statement.toUpperCase().indexOf("WHERE");
|
|
526
509
|
String preStmt = statement.substring(0, wIdx - 1);
|
|
527
|
-
String clauseStmt = statement.substring(wIdx
|
|
510
|
+
String clauseStmt = statement.substring(wIdx);
|
|
528
511
|
String tableName = preStmt.substring(("DELETE FROM").length()).trim();
|
|
529
512
|
sqlStmt = "UPDATE " + tableName + " SET sql_deleted = 1 " + clauseStmt;
|
|
530
513
|
// Find REFERENCES if any and update the sql_deleted column
|
|
@@ -738,6 +721,7 @@ public class Database {
|
|
|
738
721
|
"sql LIKE('%" +
|
|
739
722
|
tableName +
|
|
740
723
|
"%') AND sql LIKE('%ON DELETE%');";
|
|
724
|
+
|
|
741
725
|
try {
|
|
742
726
|
JSArray references = mDB.selectSQL(sqlStmt, new ArrayList<Object>());
|
|
743
727
|
ArrayList<String> retRefs = new ArrayList<String>();
|
|
@@ -794,19 +778,20 @@ public class Database {
|
|
|
794
778
|
JSObject row = new JSObject();
|
|
795
779
|
for (int i = 0; i < c.getColumnCount(); i++) {
|
|
796
780
|
String colName = c.getColumnName(i);
|
|
781
|
+
int index = c.getColumnIndex(colName);
|
|
797
782
|
int type = c.getType(i);
|
|
798
783
|
switch (type) {
|
|
799
784
|
case FIELD_TYPE_STRING:
|
|
800
|
-
row.put(colName, c.getString(
|
|
785
|
+
row.put(colName, c.getString(index));
|
|
801
786
|
break;
|
|
802
787
|
case FIELD_TYPE_INTEGER:
|
|
803
|
-
row.put(colName, c.getLong(
|
|
788
|
+
row.put(colName, c.getLong(index));
|
|
804
789
|
break;
|
|
805
790
|
case FIELD_TYPE_FLOAT:
|
|
806
|
-
row.put(colName, c.getDouble(
|
|
791
|
+
row.put(colName, c.getDouble(index));
|
|
807
792
|
break;
|
|
808
793
|
case FIELD_TYPE_BLOB:
|
|
809
|
-
row.put(colName, c.getBlob(
|
|
794
|
+
row.put(colName, c.getBlob(index));
|
|
810
795
|
break;
|
|
811
796
|
case FIELD_TYPE_NULL:
|
|
812
797
|
row.put(colName, JSONObject.NULL);
|
|
@@ -913,6 +898,27 @@ public class Database {
|
|
|
913
898
|
}
|
|
914
899
|
}
|
|
915
900
|
|
|
901
|
+
/**
|
|
902
|
+
* GetSyncDate method
|
|
903
|
+
* get the synchronization date
|
|
904
|
+
*
|
|
905
|
+
* @return
|
|
906
|
+
* @throws Exception
|
|
907
|
+
*/
|
|
908
|
+
public Long getSyncDate() throws Exception {
|
|
909
|
+
long syncDate = 0;
|
|
910
|
+
try {
|
|
911
|
+
boolean isSyncTable = _uJson.isTableExists(this, "sync_table");
|
|
912
|
+
if (!isSyncTable) {
|
|
913
|
+
throw new Exception("No sync_table available");
|
|
914
|
+
}
|
|
915
|
+
syncDate = toJson.getSyncDate(this);
|
|
916
|
+
return syncDate;
|
|
917
|
+
} catch (Exception e) {
|
|
918
|
+
throw new Exception(e.getMessage());
|
|
919
|
+
}
|
|
920
|
+
}
|
|
921
|
+
|
|
916
922
|
/**
|
|
917
923
|
* SetSyncDate Method
|
|
918
924
|
* Set the synchronization date
|
|
@@ -942,27 +948,6 @@ public class Database {
|
|
|
942
948
|
}
|
|
943
949
|
}
|
|
944
950
|
|
|
945
|
-
/**
|
|
946
|
-
* GetSyncDate method
|
|
947
|
-
* get the synchronization date
|
|
948
|
-
*
|
|
949
|
-
* @return
|
|
950
|
-
* @throws Exception
|
|
951
|
-
*/
|
|
952
|
-
public Long getSyncDate() throws Exception {
|
|
953
|
-
long syncDate = 0;
|
|
954
|
-
try {
|
|
955
|
-
boolean isSyncTable = _uJson.isTableExists(this, "sync_table");
|
|
956
|
-
if (!isSyncTable) {
|
|
957
|
-
throw new Exception("No sync_table available");
|
|
958
|
-
}
|
|
959
|
-
syncDate = toJson.getSyncDate(this);
|
|
960
|
-
return syncDate;
|
|
961
|
-
} catch (Exception e) {
|
|
962
|
-
throw new Exception(e.getMessage());
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
|
|
966
951
|
/**
|
|
967
952
|
* Import from Json object
|
|
968
953
|
*
|