@capacitor-community/sqlite 6.0.1 → 6.0.2-dev.ecc62b3.1738008093
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/CapacitorCommunitySqlite.podspec +1 -1
- package/README.md +71 -91
- package/android/build.gradle +9 -9
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +11 -13
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +15 -22
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +2 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +5 -6
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +117 -117
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsBiometric.java +27 -31
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDownloadFromHTTP.java +13 -12
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java +2 -1
- package/dist/esm/definitions.js +1 -3
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +2 -6
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2 -6
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +6197 -6164
- package/electron/dist/plugin.js.map +1 -1
- package/electron/{rollup.config.js → rollup.config.mjs} +1 -3
- package/ios/Plugin/CapacitorSQLite.swift +5 -5
- package/ios/Plugin/Database.swift +1 -1
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +7 -7
- package/ios/Plugin/Models/KeychainServices.swift +1 -1
- package/ios/Plugin/Utils/UtilsBinding.swift +2 -2
- package/ios/Plugin/Utils/UtilsDelete.swift +4 -4
- package/ios/Plugin/Utils/UtilsDownloadFromHTTP.swift +2 -2
- package/ios/Plugin/Utils/UtilsDrop.swift +1 -1
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +17 -17
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +120 -121
- package/package.json +27 -25
- package/src/definitions.ts +37 -117
- package/src/index.ts +4 -8
- package/src/web.ts +59 -131
|
@@ -12,7 +12,6 @@ import com.getcapacitor.community.database.sqlite.SQLite.UtilsSQLite;
|
|
|
12
12
|
import java.util.ArrayList;
|
|
13
13
|
import java.util.HashMap;
|
|
14
14
|
import java.util.Map;
|
|
15
|
-
|
|
16
15
|
import org.json.JSONArray;
|
|
17
16
|
import org.json.JSONException;
|
|
18
17
|
import org.json.JSONObject;
|
|
@@ -166,8 +165,11 @@ public class ImportFromJson {
|
|
|
166
165
|
for (int j = 0; j < mSchema.size(); j++) {
|
|
167
166
|
if (j == mSchema.size() - 1) {
|
|
168
167
|
if (mSchema.get(j).getColumn() != null) {
|
|
169
|
-
stmt =
|
|
170
|
-
|
|
168
|
+
stmt = new StringBuilder(stmt)
|
|
169
|
+
.append(mSchema.get(j).getColumn())
|
|
170
|
+
.append(" ")
|
|
171
|
+
.append(mSchema.get(j).getValue())
|
|
172
|
+
.toString();
|
|
171
173
|
if (mSchema.get(j).getColumn().equals("last_modified")) {
|
|
172
174
|
isLastModified = true;
|
|
173
175
|
}
|
|
@@ -175,31 +177,28 @@ public class ImportFromJson {
|
|
|
175
177
|
isSqlDeleted = true;
|
|
176
178
|
}
|
|
177
179
|
} else if (mSchema.get(j).getForeignkey() != null) {
|
|
178
|
-
stmt =
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
.toString();
|
|
180
|
+
stmt = new StringBuilder(stmt)
|
|
181
|
+
.append("FOREIGN KEY (")
|
|
182
|
+
.append(mSchema.get(j).getForeignkey())
|
|
183
|
+
.append(") ")
|
|
184
|
+
.append(mSchema.get(j).getValue())
|
|
185
|
+
.toString();
|
|
185
186
|
} else if (mSchema.get(j).getConstraint() != null) {
|
|
186
|
-
stmt =
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
.toString();
|
|
187
|
+
stmt = new StringBuilder(stmt)
|
|
188
|
+
.append("CONSTRAINT ")
|
|
189
|
+
.append(mSchema.get(j).getConstraint())
|
|
190
|
+
.append(" ")
|
|
191
|
+
.append(mSchema.get(j).getValue())
|
|
192
|
+
.toString();
|
|
193
193
|
}
|
|
194
194
|
} else {
|
|
195
195
|
if (mSchema.get(j).getColumn() != null) {
|
|
196
|
-
stmt =
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
.toString();
|
|
196
|
+
stmt = new StringBuilder(stmt)
|
|
197
|
+
.append(mSchema.get(j).getColumn())
|
|
198
|
+
.append(" ")
|
|
199
|
+
.append(mSchema.get(j).getValue())
|
|
200
|
+
.append(",")
|
|
201
|
+
.toString();
|
|
203
202
|
if (mSchema.get(j).getColumn().equals("last_modified")) {
|
|
204
203
|
isLastModified = true;
|
|
205
204
|
}
|
|
@@ -207,23 +206,21 @@ public class ImportFromJson {
|
|
|
207
206
|
isSqlDeleted = true;
|
|
208
207
|
}
|
|
209
208
|
} else if (mSchema.get(j).getForeignkey() != null) {
|
|
210
|
-
stmt =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
.toString();
|
|
209
|
+
stmt = new StringBuilder(stmt)
|
|
210
|
+
.append("FOREIGN KEY (")
|
|
211
|
+
.append(mSchema.get(j).getForeignkey())
|
|
212
|
+
.append(") ")
|
|
213
|
+
.append(mSchema.get(j).getValue())
|
|
214
|
+
.append(",")
|
|
215
|
+
.toString();
|
|
218
216
|
} else if (mSchema.get(j).getConstraint() != null) {
|
|
219
|
-
stmt =
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
.toString();
|
|
217
|
+
stmt = new StringBuilder(stmt)
|
|
218
|
+
.append("CONSTRAINT ")
|
|
219
|
+
.append(mSchema.get(j).getConstraint())
|
|
220
|
+
.append(" ")
|
|
221
|
+
.append(mSchema.get(j).getValue())
|
|
222
|
+
.append(",")
|
|
223
|
+
.toString();
|
|
227
224
|
}
|
|
228
225
|
}
|
|
229
226
|
}
|
|
@@ -397,10 +394,10 @@ public class ImportFromJson {
|
|
|
397
394
|
}
|
|
398
395
|
if (isBlob(tColTypes)) {
|
|
399
396
|
// Old process flow
|
|
400
|
-
oldProcessFow(mDb, values, tableName,tColNames, tColTypes, mode);
|
|
397
|
+
oldProcessFow(mDb, values, tableName, tColNames, tColTypes, mode);
|
|
401
398
|
} else {
|
|
402
399
|
// New process flow
|
|
403
|
-
newProcessFlow(mDb, values, tableName,tColNames);
|
|
400
|
+
newProcessFlow(mDb, values, tableName, tColNames);
|
|
404
401
|
}
|
|
405
402
|
} catch (JSONException e) {
|
|
406
403
|
throw new Exception("CreateTableData: " + e.getMessage());
|
|
@@ -420,13 +417,17 @@ public class ImportFromJson {
|
|
|
420
417
|
* @param mode
|
|
421
418
|
* @throws Exception
|
|
422
419
|
*/
|
|
423
|
-
private void oldProcessFow(
|
|
424
|
-
|
|
425
|
-
|
|
420
|
+
private void oldProcessFow(
|
|
421
|
+
Database mDb,
|
|
422
|
+
ArrayList<ArrayList<Object>> values,
|
|
423
|
+
String tableName,
|
|
424
|
+
ArrayList<String> tColNames,
|
|
425
|
+
ArrayList<String> tColTypes,
|
|
426
|
+
String mode
|
|
427
|
+
) throws Exception {
|
|
426
428
|
try {
|
|
427
429
|
// Loop on table's value
|
|
428
430
|
for (int j = 0; j < values.size(); j++) {
|
|
429
|
-
|
|
430
431
|
// Check the row number of columns
|
|
431
432
|
ArrayList<Object> row = createRowValues(values.get(j));
|
|
432
433
|
//
|
|
@@ -452,8 +453,8 @@ public class ImportFromJson {
|
|
|
452
453
|
throw new Exception("oldProcessFlow: " + e.getMessage());
|
|
453
454
|
}
|
|
454
455
|
}
|
|
455
|
-
|
|
456
|
-
|
|
456
|
+
|
|
457
|
+
private ArrayList<Object> createRowValues(ArrayList<Object> row) throws Exception {
|
|
457
458
|
try {
|
|
458
459
|
// Iterate over the ArrayList and check for JSONArray objects
|
|
459
460
|
for (int i = 0; i < row.size(); i++) {
|
|
@@ -472,6 +473,7 @@ public class ImportFromJson {
|
|
|
472
473
|
throw new Exception("createRowValues: " + e.getMessage());
|
|
473
474
|
}
|
|
474
475
|
}
|
|
476
|
+
|
|
475
477
|
private byte[] jsonArrayToByteArray(JSONArray jsonArray) throws JSONException {
|
|
476
478
|
byte[] byteArray = new byte[jsonArray.length()];
|
|
477
479
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
@@ -488,21 +490,21 @@ public class ImportFromJson {
|
|
|
488
490
|
* @param tColNames
|
|
489
491
|
* @throws Exception
|
|
490
492
|
*/
|
|
491
|
-
private void newProcessFlow(Database mDb, ArrayList<ArrayList<Object>> values,
|
|
492
|
-
|
|
493
|
+
private void newProcessFlow(Database mDb, ArrayList<ArrayList<Object>> values, String tableName, ArrayList<String> tColNames)
|
|
494
|
+
throws Exception {
|
|
493
495
|
try {
|
|
494
496
|
JSONObject retObjStrs = generateInsertAndDeletedStrings(tColNames, values);
|
|
495
497
|
// Create the statement for INSERT
|
|
496
498
|
String namesString = _uJson.convertToString(tColNames, ',');
|
|
497
499
|
if (retObjStrs.has("insert")) {
|
|
498
500
|
String stmtInsert = new StringBuilder("INSERT OR REPLACE INTO ")
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
501
|
+
.append(tableName)
|
|
502
|
+
.append("(")
|
|
503
|
+
.append(namesString)
|
|
504
|
+
.append(") ")
|
|
505
|
+
.append(retObjStrs.get("insert"))
|
|
506
|
+
.append(";")
|
|
507
|
+
.toString();
|
|
506
508
|
JSObject retObj = mDb.prepareSQL(stmtInsert, new ArrayList<>(), true, "no");
|
|
507
509
|
long lastId = retObj.getLong("lastId");
|
|
508
510
|
if (lastId < 0) {
|
|
@@ -511,13 +513,13 @@ public class ImportFromJson {
|
|
|
511
513
|
}
|
|
512
514
|
if (retObjStrs.has("delete")) {
|
|
513
515
|
String stmtDelete = new StringBuilder("DELETE FROM ")
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
516
|
+
.append(tableName)
|
|
517
|
+
.append(" WHERE ")
|
|
518
|
+
.append(tColNames.get(0))
|
|
519
|
+
.append(" ")
|
|
520
|
+
.append(retObjStrs.get("delete"))
|
|
521
|
+
.append(";")
|
|
522
|
+
.toString();
|
|
521
523
|
JSObject retObj = mDb.prepareSQL(stmtDelete, new ArrayList<>(), true, "no");
|
|
522
524
|
long lastId = retObj.getLong("lastId");
|
|
523
525
|
if (lastId < 0) {
|
|
@@ -546,6 +548,7 @@ public class ImportFromJson {
|
|
|
546
548
|
}
|
|
547
549
|
return containsBlob;
|
|
548
550
|
}
|
|
551
|
+
|
|
549
552
|
/**
|
|
550
553
|
* Create the Row Statement to load the data
|
|
551
554
|
* @param mDb
|
|
@@ -558,13 +561,13 @@ public class ImportFromJson {
|
|
|
558
561
|
* @return
|
|
559
562
|
*/
|
|
560
563
|
private String createRowStatement(
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
564
|
+
Database mDb,
|
|
565
|
+
ArrayList<String> tColNames,
|
|
566
|
+
ArrayList<String> tColTypes,
|
|
567
|
+
ArrayList<Object> row,
|
|
568
|
+
int j,
|
|
569
|
+
String tableName,
|
|
570
|
+
String mode
|
|
568
571
|
) throws Exception {
|
|
569
572
|
String msg = "CreateRowStatement: ";
|
|
570
573
|
msg += "Table" + tableName + " values row";
|
|
@@ -582,16 +585,15 @@ public class ImportFromJson {
|
|
|
582
585
|
if (questionMarkString.length() == 0) {
|
|
583
586
|
throw new Exception(msg + j + "questionMarkString is empty");
|
|
584
587
|
}
|
|
585
|
-
stmt =
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
.toString();
|
|
588
|
+
stmt = new StringBuilder("INSERT INTO ")
|
|
589
|
+
.append(tableName)
|
|
590
|
+
.append("(")
|
|
591
|
+
.append(namesString)
|
|
592
|
+
.append(")")
|
|
593
|
+
.append(" VALUES (")
|
|
594
|
+
.append(questionMarkString)
|
|
595
|
+
.append(");")
|
|
596
|
+
.toString();
|
|
595
597
|
} else {
|
|
596
598
|
Boolean isUpdate = true;
|
|
597
599
|
Integer idxDelete = tColNames.indexOf("sql_deleted");
|
|
@@ -601,10 +603,10 @@ public class ImportFromJson {
|
|
|
601
603
|
isUpdate = false;
|
|
602
604
|
Object key = tColNames.get(0);
|
|
603
605
|
StringBuilder sbQuery = new StringBuilder("DELETE FROM ")
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
606
|
+
.append(tableName)
|
|
607
|
+
.append(" WHERE ")
|
|
608
|
+
.append(tColNames.get(0))
|
|
609
|
+
.append(" = ");
|
|
608
610
|
|
|
609
611
|
if (key instanceof Integer) sbQuery.append(row.get(0)).append(";");
|
|
610
612
|
if (key instanceof String) sbQuery.append("'").append(row.get(0)).append("';");
|
|
@@ -619,12 +621,12 @@ public class ImportFromJson {
|
|
|
619
621
|
}
|
|
620
622
|
Object key = tColNames.get(0);
|
|
621
623
|
StringBuilder sbQuery = new StringBuilder("UPDATE ")
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
624
|
+
.append(tableName)
|
|
625
|
+
.append(" SET ")
|
|
626
|
+
.append(setString)
|
|
627
|
+
.append(" WHERE ")
|
|
628
|
+
.append(tColNames.get(0))
|
|
629
|
+
.append(" = ");
|
|
628
630
|
|
|
629
631
|
if (key instanceof Integer) sbQuery.append(row.get(0)).append(";");
|
|
630
632
|
if (key instanceof String) sbQuery.append("'").append(row.get(0)).append("';");
|
|
@@ -646,12 +648,12 @@ public class ImportFromJson {
|
|
|
646
648
|
* @throws Exception
|
|
647
649
|
*/
|
|
648
650
|
private Boolean checkUpdate(
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
651
|
+
Database mDb,
|
|
652
|
+
String stmt,
|
|
653
|
+
ArrayList<Object> values,
|
|
654
|
+
String tableName,
|
|
655
|
+
ArrayList<String> tColNames,
|
|
656
|
+
ArrayList<String> tColTypes
|
|
655
657
|
) throws Exception {
|
|
656
658
|
Boolean isRun = true;
|
|
657
659
|
if (stmt.substring(0, 6).equals("UPDATE")) {
|
|
@@ -677,6 +679,7 @@ public class ImportFromJson {
|
|
|
677
679
|
}
|
|
678
680
|
return isRun;
|
|
679
681
|
}
|
|
682
|
+
|
|
680
683
|
/**
|
|
681
684
|
* Check Values
|
|
682
685
|
* @param values
|
|
@@ -735,27 +738,24 @@ public class ImportFromJson {
|
|
|
735
738
|
if (colIndex == -1 || (int) rowIndex.get(colIndex) == 0) {
|
|
736
739
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) {
|
|
737
740
|
String formattedRow = null;
|
|
738
|
-
formattedRow =
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
if (val.contains("'")) {
|
|
749
|
-
rVal = val.replace("'", "''");
|
|
750
|
-
}
|
|
751
|
-
return "'" + rVal + "'";
|
|
752
|
-
} else {
|
|
753
|
-
return item.toString();
|
|
754
|
-
}
|
|
741
|
+
formattedRow = String.join(
|
|
742
|
+
", ",
|
|
743
|
+
rowIndex
|
|
744
|
+
.stream()
|
|
745
|
+
.map(item -> {
|
|
746
|
+
if (item instanceof String) {
|
|
747
|
+
String val = (String) item;
|
|
748
|
+
String rVal = val;
|
|
749
|
+
if (val.contains("'")) {
|
|
750
|
+
rVal = val.replace("'", "''");
|
|
755
751
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
752
|
+
return "'" + rVal + "'";
|
|
753
|
+
} else {
|
|
754
|
+
return item.toString();
|
|
755
|
+
}
|
|
756
|
+
})
|
|
757
|
+
.toArray(String[]::new)
|
|
758
|
+
);
|
|
759
759
|
insertValues.append("(").append(formattedRow).append("), ");
|
|
760
760
|
} else {
|
|
761
761
|
StringBuilder formattedRow = new StringBuilder();
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsBiometric.java
CHANGED
|
@@ -79,41 +79,37 @@ public class UtilsBiometric {
|
|
|
79
79
|
*/
|
|
80
80
|
private void setupBiometricPrompt(String biometricTitle, String biometricSubTitle) {
|
|
81
81
|
executor = ContextCompat.getMainExecutor(context);
|
|
82
|
-
biometricPrompt =
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
82
|
+
biometricPrompt = new BiometricPrompt(
|
|
83
|
+
(FragmentActivity) context,
|
|
84
|
+
executor,
|
|
85
|
+
new BiometricPrompt.AuthenticationCallback() {
|
|
86
|
+
@Override
|
|
87
|
+
public void onAuthenticationError(int errorCode, @NonNull CharSequence errString) {
|
|
88
|
+
super.onAuthenticationError(errorCode, errString);
|
|
89
|
+
Toast.makeText(context, "Authentication error: " + errString, Toast.LENGTH_SHORT).show();
|
|
90
|
+
listener.onFailed();
|
|
91
|
+
}
|
|
93
92
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
93
|
+
@Override
|
|
94
|
+
public void onAuthenticationSucceeded(@NonNull BiometricPrompt.AuthenticationResult result) {
|
|
95
|
+
super.onAuthenticationSucceeded(result);
|
|
96
|
+
listener.onSuccess(result);
|
|
97
|
+
}
|
|
99
98
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
99
|
+
@Override
|
|
100
|
+
public void onAuthenticationFailed() {
|
|
101
|
+
super.onAuthenticationFailed();
|
|
102
|
+
Toast.makeText(context, "Authentication failed", Toast.LENGTH_SHORT).show();
|
|
103
|
+
listener.onFailed();
|
|
106
104
|
}
|
|
107
|
-
|
|
105
|
+
}
|
|
106
|
+
);
|
|
108
107
|
|
|
109
108
|
// Create prompt dialog
|
|
110
|
-
promptInfo =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
BiometricManager.Authenticators.BIOMETRIC_STRONG | BiometricManager.Authenticators.DEVICE_CREDENTIAL
|
|
116
|
-
)
|
|
117
|
-
.build();
|
|
109
|
+
promptInfo = new BiometricPrompt.PromptInfo.Builder()
|
|
110
|
+
.setTitle(biometricTitle)
|
|
111
|
+
.setSubtitle(biometricSubTitle)
|
|
112
|
+
.setAllowedAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG | BiometricManager.Authenticators.DEVICE_CREDENTIAL)
|
|
113
|
+
.build();
|
|
118
114
|
}
|
|
119
115
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
package com.getcapacitor.community.database.sqlite.SQLite;
|
|
2
2
|
|
|
3
|
-
import java.net.MalformedURLException;
|
|
4
3
|
import android.content.Context;
|
|
5
4
|
import java.io.File;
|
|
6
5
|
import java.io.FileOutputStream;
|
|
7
6
|
import java.io.IOException;
|
|
8
7
|
import java.io.InputStream;
|
|
9
8
|
import java.net.HttpURLConnection;
|
|
9
|
+
import java.net.MalformedURLException;
|
|
10
10
|
import java.net.URL;
|
|
11
|
-
import java.util.regex.Matcher;
|
|
12
|
-
import java.util.regex.Pattern;
|
|
13
11
|
import java.net.URLDecoder;
|
|
14
12
|
import java.nio.charset.StandardCharsets;
|
|
13
|
+
import java.util.regex.Matcher;
|
|
14
|
+
import java.util.regex.Pattern;
|
|
15
15
|
|
|
16
16
|
public class UtilsDownloadFromHTTP {
|
|
17
17
|
|
|
@@ -20,14 +20,14 @@ public class UtilsDownloadFromHTTP {
|
|
|
20
20
|
private final UtilsFile _uFile = new UtilsFile();
|
|
21
21
|
|
|
22
22
|
public void download(Context context, String fileUrl) throws Exception {
|
|
23
|
-
|
|
23
|
+
Boolean isZip = false;
|
|
24
24
|
String fileName = "";
|
|
25
25
|
try {
|
|
26
26
|
String[] fileDetails = getFileDetails(fileUrl);
|
|
27
27
|
fileName = fileDetails[0];
|
|
28
28
|
String extension = fileDetails[1];
|
|
29
29
|
if (!fileName.contains("SQLite.db")) {
|
|
30
|
-
switch(extension) {
|
|
30
|
+
switch (extension) {
|
|
31
31
|
case "db":
|
|
32
32
|
fileName = fileName.substring(0, fileName.length() - 3) + "SQLite.db";
|
|
33
33
|
break;
|
|
@@ -38,12 +38,10 @@ public class UtilsDownloadFromHTTP {
|
|
|
38
38
|
throw new Exception("Unknown file type. Filename: " + fileName);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
|
|
42
41
|
} catch (Exception e) {
|
|
43
42
|
throw new Exception(e.getMessage());
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
|
|
47
45
|
File cacheDir = context.getCacheDir();
|
|
48
46
|
String cachePath = cacheDir.getAbsolutePath();
|
|
49
47
|
String tmpFilePath = cachePath + File.separator + fileName;
|
|
@@ -75,15 +73,16 @@ public class UtilsDownloadFromHTTP {
|
|
|
75
73
|
String decodedPath = URLDecoder.decode(path, StandardCharsets.UTF_8.toString()); // Decode URL-encoded path
|
|
76
74
|
String filename = decodedPath.substring(decodedPath.lastIndexOf('/') + 1); // Extract filename from decoded path
|
|
77
75
|
String extension = getFileExtension(filename);
|
|
78
|
-
if(extension == null) {
|
|
76
|
+
if (extension == null) {
|
|
79
77
|
throw new Exception("extension db or zip not found");
|
|
80
78
|
}
|
|
81
|
-
return new String[]{filename, extension};
|
|
79
|
+
return new String[] { filename, extension };
|
|
82
80
|
} catch (MalformedURLException e) {
|
|
83
81
|
e.printStackTrace();
|
|
84
82
|
throw new Exception(e.getMessage());
|
|
85
83
|
}
|
|
86
84
|
}
|
|
85
|
+
|
|
87
86
|
public static String getFileExtension(String filename) {
|
|
88
87
|
Pattern pattern = Pattern.compile("\\.([a-zA-Z0-9]+)(?:[\\?#]|$)");
|
|
89
88
|
Matcher matcher = pattern.matcher(filename);
|
|
@@ -94,6 +93,7 @@ public class UtilsDownloadFromHTTP {
|
|
|
94
93
|
|
|
95
94
|
return null; // no extension found
|
|
96
95
|
}
|
|
96
|
+
|
|
97
97
|
public static void downloadFileToCache(String fileURL, String fileName, String cacheDir) throws Exception {
|
|
98
98
|
HttpURLConnection httpConn = null;
|
|
99
99
|
try {
|
|
@@ -113,9 +113,10 @@ public class UtilsDownloadFromHTTP {
|
|
|
113
113
|
// create temporary file path
|
|
114
114
|
String tmpFilePath = cacheDir + File.separator + dbName;
|
|
115
115
|
// opens input stream from the HTTP connection
|
|
116
|
-
try (
|
|
117
|
-
|
|
118
|
-
|
|
116
|
+
try (
|
|
117
|
+
InputStream inputStream = httpConn.getInputStream();
|
|
118
|
+
FileOutputStream outputStream = new FileOutputStream(tmpFilePath)
|
|
119
|
+
) {
|
|
119
120
|
byte[] buffer = new byte[1024];
|
|
120
121
|
int bytesRead;
|
|
121
122
|
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsFile.java
CHANGED
|
@@ -261,7 +261,8 @@ public class UtilsFile {
|
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
public String getFileExtension(String name) {
|
|
264
|
-
if (name.lastIndexOf(".") != -1 && name.lastIndexOf(".") != 0) return name.substring(name.lastIndexOf(".") + 1);
|
|
264
|
+
if (name.lastIndexOf(".") != -1 && name.lastIndexOf(".") != 0) return name.substring(name.lastIndexOf(".") + 1);
|
|
265
|
+
else return "";
|
|
265
266
|
}
|
|
266
267
|
|
|
267
268
|
public Boolean restoreDatabase(Context context, String databaseName) {
|
package/dist/esm/definitions.js
CHANGED
|
@@ -850,9 +850,7 @@ export class SQLiteDBConnection {
|
|
|
850
850
|
throw new Error('Error a task.statement must be provided');
|
|
851
851
|
}
|
|
852
852
|
if ('values' in task && task.values && task.values.length > 0) {
|
|
853
|
-
const retMode = task.statement.toUpperCase().includes('RETURNING')
|
|
854
|
-
? 'all'
|
|
855
|
-
: 'no';
|
|
853
|
+
const retMode = task.statement.toUpperCase().includes('RETURNING') ? 'all' : 'no';
|
|
856
854
|
const ret = await this.sqlite.run({
|
|
857
855
|
database: this.dbName,
|
|
858
856
|
statement: task.statement,
|