@capacitor-community/sqlite 4.1.0-6 → 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.
@@ -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
- boolean encrypted = call.getBoolean("encrypted", false);
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) {
@@ -9,26 +9,15 @@ import static android.database.Cursor.FIELD_TYPE_STRING;
9
9
  import android.content.Context;
10
10
  import android.content.SharedPreferences;
11
11
  import android.util.Log;
12
-
13
12
  import androidx.sqlite.db.SimpleSQLiteQuery;
14
13
  import androidx.sqlite.db.SupportSQLiteDatabase;
15
14
  import androidx.sqlite.db.SupportSQLiteStatement;
16
-
17
15
  import com.getcapacitor.JSArray;
18
16
  import com.getcapacitor.JSObject;
19
17
  import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.ExportToJson;
20
18
  import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.ImportFromJson;
21
19
  import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.JsonSQLite;
22
20
  import com.getcapacitor.community.database.sqlite.SQLite.ImportExportJson.UtilsJson;
23
-
24
- import net.sqlcipher.Cursor;
25
- import net.sqlcipher.database.SQLiteDatabase;
26
- import net.sqlcipher.database.SQLiteException;
27
-
28
- import org.json.JSONArray;
29
- import org.json.JSONException;
30
- import org.json.JSONObject;
31
-
32
21
  import java.io.File;
33
22
  import java.text.SimpleDateFormat;
34
23
  import java.util.ArrayList;
@@ -38,6 +27,12 @@ import java.util.Date;
38
27
  import java.util.Dictionary;
39
28
  import java.util.Hashtable;
40
29
  import java.util.List;
30
+ import net.sqlcipher.Cursor;
31
+ import net.sqlcipher.database.SQLiteDatabase;
32
+ import net.sqlcipher.database.SQLiteException;
33
+ import org.json.JSONArray;
34
+ import org.json.JSONException;
35
+ import org.json.JSONObject;
41
36
 
42
37
  public class Database {
43
38
 
@@ -50,6 +45,7 @@ public class Database {
50
45
  private final Boolean _encrypted;
51
46
  private final Boolean _isEncryption;
52
47
  private final SharedPreferences _sharedPreferences;
48
+ private final Boolean _readOnly;
53
49
  private final File _file;
54
50
  private final int _version;
55
51
  private final GlobalSQLite _globVar;
@@ -67,14 +63,15 @@ public class Database {
67
63
  private Boolean ncDB = false;
68
64
 
69
65
  public Database(
70
- Context context,
71
- String dbName,
72
- Boolean encrypted,
73
- String mode,
74
- int version,
75
- Boolean isEncryption,
76
- Dictionary<Integer, JSONObject> vUpgObject,
77
- SharedPreferences sharedPreferences
66
+ Context context,
67
+ String dbName,
68
+ Boolean encrypted,
69
+ String mode,
70
+ int version,
71
+ Boolean isEncryption,
72
+ Dictionary<Integer, JSONObject> vUpgObject,
73
+ SharedPreferences sharedPreferences,
74
+ Boolean readonly
78
75
  ) {
79
76
  this._context = context;
80
77
  this._dbName = dbName;
@@ -84,6 +81,7 @@ public class Database {
84
81
  this._version = version;
85
82
  this._vUpgObject = vUpgObject;
86
83
  this._sharedPreferences = sharedPreferences;
84
+ this._readOnly = readonly;
87
85
  if (dbName.contains("/") && dbName.endsWith("SQLite.db")) {
88
86
  this.ncDB = true;
89
87
  this._file = new File(dbName);
@@ -154,8 +152,8 @@ public class Database {
154
152
  int curVersion;
155
153
 
156
154
  String password = _uSecret != null && _encrypted && (_mode.equals("secret") || _mode.equals("encryption"))
157
- ? _uSecret.getPassphrase()
158
- : "";
155
+ ? _uSecret.getPassphrase()
156
+ : "";
159
157
  if (_mode.equals("encryption")) {
160
158
  if (_isEncryption) {
161
159
  try {
@@ -170,7 +168,7 @@ public class Database {
170
168
  }
171
169
  }
172
170
  try {
173
- if (!isNCDB()) {
171
+ if (!isNCDB() && !this._readOnly) {
174
172
  _db = SQLiteDatabase.openOrCreateDatabase(_file, password, null);
175
173
  } else {
176
174
  _db = SQLiteDatabase.openDatabase(String.valueOf(_file), "", null, SQLiteDatabase.OPEN_READONLY);
@@ -187,52 +185,54 @@ public class Database {
187
185
  _db = null;
188
186
  throw new Exception(msg);
189
187
  }
190
- if (!isNCDB()) {
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) {
191
209
  try {
192
- curVersion = _db.getVersion(); // default 0
193
- } catch (IllegalStateException e) {
194
- String msg = "Failed in get/setVersion " + e.getMessage();
195
- Log.v(TAG, msg);
196
- close();
197
- _db = null;
198
- throw new Exception(msg);
199
- } catch (SQLiteException e) {
200
- String msg = "Failed in setVersion " + e.getMessage();
201
- Log.v(TAG, msg);
202
- close();
203
- _db = null;
204
- throw new Exception(msg);
205
- }
206
- if (_version > curVersion && _vUpgObject != null && _vUpgObject.size() > 0) {
207
- // if (_vUpgObject != null && _vUpgObject.size() > 0) {
208
- try {
209
- this._uFile.copyFile(_context, _dbName, "backup-" + _dbName);
210
+ this._uFile.copyFile(_context, _dbName, "backup-" + _dbName);
210
211
 
211
- _uUpg.onUpgrade(this, _vUpgObject, curVersion, _version);
212
+ _uUpg.onUpgrade(this, _vUpgObject, curVersion, _version);
212
213
 
213
- boolean ret = _uFile.deleteBackupDB(_context, _dbName);
214
- if (!ret) {
215
- String msg = "Failed in deleteBackupDB backup-\" + _dbName";
216
- Log.v(TAG, msg);
217
- close();
218
- _db = null;
219
- throw new Exception(msg);
220
- }
221
- } catch (Exception e) {
222
- // restore DB
223
- boolean ret = _uFile.restoreDatabase(_context, _dbName);
224
- String msg = e.getMessage();
225
- if (!ret) msg += "Failed in restoreDatabase " + _dbName;
214
+ boolean ret = _uFile.deleteBackupDB(_context, _dbName);
215
+ if (!ret) {
216
+ String msg = "Failed in deleteBackupDB backup-\" + _dbName";
226
217
  Log.v(TAG, msg);
227
218
  close();
228
219
  _db = null;
229
220
  throw new Exception(msg);
230
221
  }
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);
231
231
  }
232
- _isOpen = true;
233
- return;
234
232
  }
235
- } else {
233
+ _isOpen = true;
234
+ return;
235
+ } else {
236
236
  _isOpen = false;
237
237
  _db = null;
238
238
  throw new Exception("Database not opened");
@@ -778,19 +778,20 @@ public class Database {
778
778
  JSObject row = new JSObject();
779
779
  for (int i = 0; i < c.getColumnCount(); i++) {
780
780
  String colName = c.getColumnName(i);
781
+ int index = c.getColumnIndex(colName);
781
782
  int type = c.getType(i);
782
783
  switch (type) {
783
784
  case FIELD_TYPE_STRING:
784
- row.put(colName, c.getString(c.getColumnIndex(colName)));
785
+ row.put(colName, c.getString(index));
785
786
  break;
786
787
  case FIELD_TYPE_INTEGER:
787
- row.put(colName, c.getLong(c.getColumnIndex(colName)));
788
+ row.put(colName, c.getLong(index));
788
789
  break;
789
790
  case FIELD_TYPE_FLOAT:
790
- row.put(colName, c.getDouble(c.getColumnIndex(colName)));
791
+ row.put(colName, c.getDouble(index));
791
792
  break;
792
793
  case FIELD_TYPE_BLOB:
793
- row.put(colName, c.getBlob(c.getColumnIndex(colName)));
794
+ row.put(colName, c.getBlob(index));
794
795
  break;
795
796
  case FIELD_TYPE_NULL:
796
797
  row.put(colName, JSONObject.NULL);
@@ -879,8 +880,8 @@ public class Database {
879
880
  Date date = new Date();
880
881
  long syncTime = date.getTime() / 1000L;
881
882
  String[] statements = {
882
- "CREATE TABLE IF NOT EXISTS sync_table (" + "id INTEGER PRIMARY KEY NOT NULL," + "sync_date INTEGER);",
883
- "INSERT INTO sync_table (sync_date) VALUES ('" + syncTime + "');"
883
+ "CREATE TABLE IF NOT EXISTS sync_table (" + "id INTEGER PRIMARY KEY NOT NULL," + "sync_date INTEGER);",
884
+ "INSERT INTO sync_table (sync_date) VALUES ('" + syncTime + "');"
884
885
  };
885
886
  try {
886
887
  retObj = execute(statements);
@@ -935,7 +936,7 @@ public class Database {
935
936
  SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
936
937
  Date date = formatter.parse(syncDate.replaceAll("Z$", "+0000"));
937
938
  long syncTime = date.getTime() / 1000L;
938
- String[] statements = {"UPDATE sync_table SET sync_date = " + syncTime + " WHERE id = 1;"};
939
+ String[] statements = { "UPDATE sync_table SET sync_date = " + syncTime + " WHERE id = 1;" };
939
940
  retObj = execute(statements);
940
941
  if (retObj.getInteger("changes") != Integer.valueOf(-1)) {
941
942
  return;
@@ -1021,8 +1022,7 @@ public class Database {
1021
1022
  } catch (Exception e) {
1022
1023
  Log.e(TAG, "Error: exportToJson " + e.getMessage());
1023
1024
  throw new Exception(e.getMessage());
1024
- } finally {
1025
- }
1025
+ } finally {}
1026
1026
  }
1027
1027
 
1028
1028
  /**
@@ -1,16 +1,13 @@
1
1
  package com.getcapacitor.community.database.sqlite.SQLite;
2
2
 
3
3
  import android.util.Log;
4
-
5
4
  import com.getcapacitor.JSObject;
6
-
7
- import org.json.JSONArray;
8
- import org.json.JSONObject;
9
-
10
5
  import java.util.ArrayList;
11
6
  import java.util.Collections;
12
7
  import java.util.Dictionary;
13
8
  import java.util.List;
9
+ import org.json.JSONArray;
10
+ import org.json.JSONObject;
14
11
 
15
12
  public class UtilsUpgrade {
16
13
 
@@ -26,12 +23,8 @@ public class UtilsUpgrade {
26
23
  * @param targetVersion
27
24
  * @throws Exception
28
25
  */
29
- public void onUpgrade(
30
- Database db,
31
- Dictionary<Integer, JSONObject> upgDict,
32
- Integer curVersion,
33
- Integer targetVersion
34
- ) throws Exception {
26
+ public void onUpgrade(Database db, Dictionary<Integer, JSONObject> upgDict, Integer curVersion, Integer targetVersion)
27
+ throws Exception {
35
28
  Log.i(TAG, "UtilsUpgrade.onUpgrade: " + curVersion + " => " + targetVersion);
36
29
 
37
30
  List<Integer> sortedKeys = Collections.list(upgDict.keys());
@@ -41,9 +34,7 @@ public class UtilsUpgrade {
41
34
  if (versionKey > curVersion && versionKey <= targetVersion) {
42
35
  JSONObject upgrade = upgDict.get(versionKey);
43
36
 
44
- JSONArray statementsJson = upgrade.has("statements")
45
- ? upgrade.getJSONArray("statements")
46
- : new JSONArray();
37
+ JSONArray statementsJson = upgrade.has("statements") ? upgrade.getJSONArray("statements") : new JSONArray();
47
38
 
48
39
  List<String> statements = new ArrayList<String>();
49
40
 
@@ -347,6 +347,10 @@ export interface capConnectionOptions {
347
347
  * ["encryption", "secret", "newsecret"]
348
348
  */
349
349
  mode?: string;
350
+ /**
351
+ * Set to true (database in read-only mode) / false
352
+ */
353
+ readonly?: boolean;
350
354
  }
351
355
  export interface capAllConnectionsOptions {
352
356
  /**
@@ -360,6 +364,10 @@ export interface capSQLiteOptions {
360
364
  * The database name
361
365
  */
362
366
  database?: string;
367
+ /**
368
+ * Set to true (database in read-only mode) / false
369
+ */
370
+ readonly?: boolean;
363
371
  }
364
372
  export interface capNCDatabasePathOptions {
365
373
  /**
@@ -810,24 +818,27 @@ export interface ISQLiteConnection {
810
818
  * @param encrypted
811
819
  * @param mode
812
820
  * @param version
821
+ * @param readonly
813
822
  * @returns Promise<SQLiteDBConnection>
814
823
  * @since 2.9.0 refactor
815
824
  */
816
- createConnection(database: string, encrypted: boolean, mode: string, version: number): Promise<SQLiteDBConnection>;
825
+ createConnection(database: string, encrypted: boolean, mode: string, version: number, readonly: boolean): Promise<SQLiteDBConnection>;
817
826
  /**
818
827
  * Check if a connection exists
819
828
  * @param database
829
+ * @param readonly
820
830
  * @returns Promise<capSQLiteResult>
821
831
  * @since 3.0.0-beta.5
822
832
  */
823
- isConnection(database: string): Promise<capSQLiteResult>;
833
+ isConnection(database: string, readonly: boolean): Promise<capSQLiteResult>;
824
834
  /**
825
835
  * Retrieve an existing database connection
826
836
  * @param database
837
+ * @param readonly
827
838
  * @returns Promise<SQLiteDBConnection>
828
839
  * @since 2.9.0 refactor
829
840
  */
830
- retrieveConnection(database: string): Promise<SQLiteDBConnection>;
841
+ retrieveConnection(database: string, readonly: boolean): Promise<SQLiteDBConnection>;
831
842
  /**
832
843
  * Retrieve all database connections
833
844
  * @returns Promise<Map<string, SQLiteDBConnection>>
@@ -837,10 +848,11 @@ export interface ISQLiteConnection {
837
848
  /**
838
849
  * Close a database connection
839
850
  * @param database
851
+ * @param readonly
840
852
  * @returns Promise<void>
841
853
  * @since 2.9.0 refactor
842
854
  */
843
- closeConnection(database: string): Promise<void>;
855
+ closeConnection(database: string, readonly: boolean): Promise<void>;
844
856
  /**
845
857
  * Close all database connections
846
858
  * @returns Promise<void>
@@ -979,10 +991,10 @@ export declare class SQLiteConnection implements ISQLiteConnection {
979
991
  changeEncryptionSecret(passphrase: string, oldpassphrase: string): Promise<void>;
980
992
  clearEncryptionSecret(): Promise<void>;
981
993
  addUpgradeStatement(database: string, toVersion: number, statements: string[]): Promise<void>;
982
- createConnection(database: string, encrypted: boolean, mode: string, version: number): Promise<SQLiteDBConnection>;
983
- closeConnection(database: string): Promise<void>;
984
- isConnection(database: string): Promise<capSQLiteResult>;
985
- retrieveConnection(database: string): Promise<SQLiteDBConnection>;
994
+ createConnection(database: string, encrypted: boolean, mode: string, version: number, readonly: boolean): Promise<SQLiteDBConnection>;
995
+ closeConnection(database: string, readonly: boolean): Promise<void>;
996
+ isConnection(database: string, readonly: boolean): Promise<capSQLiteResult>;
997
+ retrieveConnection(database: string, readonly: boolean): Promise<SQLiteDBConnection>;
986
998
  getNCDatabasePath(path: string, database: string): Promise<capNCDatabasePathResult>;
987
999
  createNCConnection(databasePath: string, version: number): Promise<SQLiteDBConnection>;
988
1000
  closeNCConnection(databasePath: string): Promise<void>;
@@ -1012,6 +1024,12 @@ export interface ISQLiteDBConnection {
1012
1024
  * @since 2.9.0 refactor
1013
1025
  */
1014
1026
  getConnectionDBName(): string;
1027
+ /**
1028
+ * Get SQLite DB Connection read-only mode
1029
+ * @returns boolean
1030
+ * @since 4.1.0
1031
+ */
1032
+ getConnectionReadOnly(): boolean;
1015
1033
  /**
1016
1034
  * Open a SQLite DB Connection
1017
1035
  * @returns Promise<void>
@@ -1143,9 +1161,11 @@ export interface ISQLiteDBConnection {
1143
1161
  */
1144
1162
  export declare class SQLiteDBConnection implements ISQLiteDBConnection {
1145
1163
  private dbName;
1164
+ private readonly;
1146
1165
  private sqlite;
1147
- constructor(dbName: string, sqlite: any);
1166
+ constructor(dbName: string, readonly: boolean, sqlite: any);
1148
1167
  getConnectionDBName(): string;
1168
+ getConnectionReadOnly(): boolean;
1149
1169
  open(): Promise<void>;
1150
1170
  close(): Promise<void>;
1151
1171
  getUrl(): Promise<capSQLiteUrl>;