Skip to content

Commit 335cb8c

Browse files
committed
last Capacitor 5 release
1 parent 7e6a6dd commit 335cb8c

File tree

8 files changed

+94
-56
lines changed

8 files changed

+94
-56
lines changed

README.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,29 @@
33
<p align="center"><strong><code>@capacitor-community/sqlite</code></strong></p>
44
<br>
55
<p align="center" style="font-size:50px;color:red"><strong>CAPACITOR 5</strong></p><br>
6+
<br>
7+
<!-- Note from the Owner - Start -->
8+
<p align="center" style="font-size:50px;color:red"><strong>Note from the Owner</strong></p>
9+
<!-- Note from the Owner - End -->
10+
<br>
11+
<!-- Message below Note from the Owner - Start -->
12+
<p align="left" style="font-size:47px">Start --></p>
13+
<br>
14+
<p align="left">
15+
I have been dedicated to developing and maintaining this plugin for many years since the inception of Ionic Capacitor. Now, at 73+ years old, and with my MacBook Pro becoming obsolete for running Capacitor 6 for iOS, I have made the decision to cease maintenance of the plugin. If anyone wishes to take ownership of this plugin, they are welcome to do so.
16+
</p>
17+
<br>
18+
<p align="left">
19+
It has been a great honor to be part of this development journey alongside the developer community. I am grateful to see many of you following me on this path and incorporating the plugin into your applications. Your comments and suggestions have motivated me to continuously improve it.
20+
</p>
21+
<br>
22+
<p align="left">
23+
I have made this decision due to several family-related troubles that require my full attention and time. Therefore, I will not be stepping back. Thank you to all of you for your support.
24+
</p>
25+
<br>
26+
<p align="left" style="font-size:47px">End <--</p>
27+
<!-- Message below Note from the Owner - End -->
28+
<br>
629

730
<p align="center">
831
Capacitor community plugin for Native and Electron SQLite Databases.
@@ -18,7 +41,7 @@
1841
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/dw/@capacitor-community/sqlite?style=flat-square" /></a>
1942
<a href="https://www.npmjs.com/package/@capacitor-community/sqlite"><img src="https://img.shields.io/npm/v/@capacitor-community/sqlite?style=flat-square" /></a>
2043
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
21-
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-44-orange?style=flat-square" /></a>
44+
<a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-45-orange?style=flat-square" /></a>
2245
<!-- ALL-CONTRIBUTORS-BADGE:END -->
2346
</p>
2447

@@ -416,6 +439,8 @@ lasher23"><img src="https://avatars.githubusercontent.com/u/24244618?v=4" width=
416439
mirsella"><img src="https://avatars.githubusercontent.com/u/45905567?v=4" width="50" height="50" /></a>
417440
<a href="https://github.com/SaintPepsi" title="
418441
SaintPepsi"><img src="https://avatars.githubusercontent.com/u/16056759?v=4" width="50" height="50" /></a>
442+
<a href="https://github.com/l1ndch" title="
443+
l1ndch"><img src="https://avatars.githubusercontent.com/u/170952278?v=4" width="50" height="50" /></a>
419444
</p>
420445

421446

android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ private ArrayList<JsonColumn> getSchema(String sqlStmt) throws Exception {
345345
String sc = s.replaceAll("\n", "").trim();
346346
String[] row = sc.trim().split(" ", 2);
347347
JsonColumn jsonRow = new JsonColumn();
348+
String uppercasedValue = row[0].toUpperCase(); // Define uppercasedValue
348349
int oPar;
349350
int cPar;
350351
switch (row[0].toUpperCase()) {
@@ -356,11 +357,12 @@ private ArrayList<JsonColumn> getSchema(String sqlStmt) throws Exception {
356357
row[1] = sc.substring(cPar + 2);
357358
jsonRow.setForeignkey(row[0]);
358359
}
359-
case "PRIMARY" -> {
360+
case "PRIMARY", "UNIQUE" -> {
361+
String prefix = uppercasedValue.equals("PRIMARY") ? "CPK_" : "CUN_";
360362
oPar = sc.indexOf("(");
361363
cPar = sc.indexOf(")");
362364
String pk = sc.substring(oPar + 1, cPar);
363-
row[0] = "CPK_" + pk.replaceAll("§", "_");
365+
row[0] = prefix + pk.replaceAll("§", "_");
364366
row[0] = row[0].replaceAll("_ ", "_");
365367
row[1] = sc.substring(0, cPar + 1);
366368
jsonRow.setConstraint(row[0]);

electron/src/electron-utils/ImportExportJson/exportToJson.ts

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -329,35 +329,47 @@ export class ExportToJson {
329329
row[1] = scht.substring(scht.indexOf(' ') + 1);
330330

331331
const jsonRow: JsonColumn = {} as JsonColumn;
332-
if (row[0].toUpperCase() === 'FOREIGN') {
333-
const oPar: number = scht.indexOf('(');
334-
const cPar: number = scht.indexOf(')');
335-
const fk = scht.substring(oPar + 1, cPar);
336-
const fknames: string[] = fk.split('§');
337-
row[0] = fknames.join(',');
338-
row[0] = row[0].replace(/, /g, ',');
339-
row[1] = scht.substring(cPar + 2);
340-
jsonRow['foreignkey'] = row[0];
341-
} else if (row[0].toUpperCase() === 'PRIMARY') {
342-
const oPar: number = scht.indexOf('(');
343-
const cPar: number = scht.indexOf(')');
344-
const pk: string = scht.substring(oPar + 1, cPar);
345-
const pknames: string[] = pk.split('§');
346-
row[0] = 'CPK_' + pknames.join('_');
347-
row[0] = row[0].replace(/_ /g, '_');
348-
row[1] = scht;
349-
jsonRow['constraint'] = row[0];
350-
} else if (row[0].toUpperCase() === 'CONSTRAINT') {
351-
const tRow: string[] = [];
352-
const row1t: string = row[1].trim();
353-
tRow[0] = row1t.substring(0, row1t.indexOf(' '));
354-
tRow[1] = row1t.substring(row1t.indexOf(' ') + 1);
355-
row[0] = tRow[0];
356-
jsonRow['constraint'] = row[0];
357-
row[1] = tRow[1];
358-
} else {
359-
jsonRow['column'] = row[0];
332+
switch (row[0].toUpperCase()) {
333+
case 'FOREIGN': {
334+
const oPar: number = scht.indexOf('(');
335+
const cPar: number = scht.indexOf(')');
336+
const fk = scht.substring(oPar + 1, cPar);
337+
const fknames: string[] = fk.split('§');
338+
row[0] = fknames.join(',');
339+
row[0] = row[0].replace(/, /g, ',');
340+
row[1] = scht.substring(cPar + 2);
341+
jsonRow['foreignkey'] = row[0];
342+
break;
343+
}
344+
case 'PRIMARY':
345+
case 'UNIQUE': {
346+
const prefix = row[0].toUpperCase() === 'PRIMARY' ? 'CPK_' : 'CUN_';
347+
const oPar: number = scht.indexOf('(');
348+
const cPar: number = scht.indexOf(')');
349+
const pk: string = scht.substring(oPar + 1, cPar);
350+
const pknames: string[] = pk.split('§');
351+
row[0] = prefix + pknames.join('_');
352+
row[0] = row[0].replace(/_ /g, '_');
353+
row[1] = scht;
354+
jsonRow['constraint'] = row[0];
355+
break;
356+
}
357+
case 'CONSTRAINT': {
358+
const tRow: string[] = [];
359+
const row1t: string = row[1].trim();
360+
tRow[0] = row1t.substring(0, row1t.indexOf(' '));
361+
tRow[1] = row1t.substring(row1t.indexOf(' ') + 1);
362+
row[0] = tRow[0];
363+
jsonRow['constraint'] = row[0];
364+
row[1] = tRow[1];
365+
break;
366+
}
367+
default: {
368+
jsonRow['column'] = row[0];
369+
break;
370+
}
360371
}
372+
361373
jsonRow['value'] = row[1].replace(/§/g, ',');
362374
schema.push(jsonRow);
363375
}

electron/src/electron-utils/utilsSQLite.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,10 @@ export class UtilsSQLite {
326326
try {
327327
initChanges = this.dbChanges(mDB);
328328
let sqlStmt = sql;
329-
329+
330330
// modify sql to sql92 compatible
331331
sqlStmt = this.statementsToSQL92(mDB, sql, fromJson, isSQL92);
332+
332333
this.execDB(mDB, sqlStmt);
333334
changes = this.dbChanges(mDB) - initChanges;
334335
lastId = this.getLastId(mDB);
@@ -523,13 +524,14 @@ export class UtilsSQLite {
523524
let mVal: any[] = [];
524525
if (mValues.length > 0) {
525526
mVal = this.replaceUndefinedByNull(mValues);
526-
} else {
527+
528+
}/* else {
527529
const findVals = sqlStmt.match(/\?/gi);
528530
const nbValues = findVals ? findVals.length : 0;
529531
for (let i = 0; i < nbValues; i++) {
530532
mVal.push(null);
531533
}
532-
}
534+
}*/
533535
const ret: RunResults = this.runExec(mDB, sqlStmt, mVal, returnMode);
534536
if (ret.values != null) {
535537
result.values = ret.values;

ios/Plugin/ImportExportJson/ExportToJson.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -867,26 +867,28 @@ class ExportToJson {
867867
with: ",")
868868
.replacingOccurrences(of: ", ",
869869
with: ",")
870-
case "PRIMARY":
870+
case "PRIMARY", "UNIQUE":
871+
let prefix = (String(row[0]).uppercased() == "PRIMARY") ? "CPK_" : "CUN_"
872+
871873
guard let oPar = rstr.firstIndex(of: "(")
872874
else {
873875
var msg: String = "Create Schema "
874-
msg.append("PRIMARY KEY no '('")
876+
msg.append("PRIMARY/UNIQUE KEY no '('")
875877
throw ExportToJsonError
876878
.createSchema(message: msg)
877879
}
878880
guard let cPar = rstr.firstIndex(of: ")")
879881
else {
880882
var msg: String = "Create Schema "
881-
msg.append("PRIMARY KEY no ')'")
883+
msg.append("PRIMARY/UNIQUE KEY no ')'")
882884
throw ExportToJsonError
883885
.createSchema(message: msg)
884886
}
885887
row[0] = rstr[rstr.index(
886888
after: oPar)..<cPar]
887889
row[1] = rstr[rstr.index(rstr.startIndex,
888890
offsetBy: 0)..<rstr.endIndex]
889-
columns["constraint"] = "CPK_" + String(row[0])
891+
columns["constraint"] = prefix + String(row[0])
890892
.replacingOccurrences(of: "§",
891893
with: "_")
892894
.replacingOccurrences(of: "_ ",

ios/Plugin/Utils/UtilsDownloadFromHTTP.swift

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,14 @@ class UtilsDownloadFromHTTP {
158158
}
159159

160160
class func extractDBFiles(from zipFile: URL, completion: @escaping ([URL], Error?) -> Void) {
161-
DispatchQueue.global().async(execute: {
161+
DispatchQueue.global().async {
162162
var dbFiles: [URL] = []
163163

164164
do {
165165
let destinationURL = zipFile.deletingLastPathComponent()
166166

167-
guard let archive = Archive(url: zipFile, accessMode: .read) else {
168-
let msg = "Failed in reading Archive"
169-
completion([], UtilsDownloadError.invalidArchive(message: msg))
170-
return
171-
}
167+
// Use the throwing initializer
168+
let archive = try Archive(url: zipFile, accessMode: .read)
172169

173170
for entry in archive where entry.type == .file {
174171
let fileURL = destinationURL.appendingPathComponent(entry.path)
@@ -179,14 +176,15 @@ class UtilsDownloadFromHTTP {
179176
dbFiles.append(fileURL)
180177
}
181178
}
179+
182180
// Delete the zip file
183181
try FileManager.default.removeItem(at: zipFile)
184182

185183
completion(dbFiles, nil)
186184
} catch {
187-
completion([], error)
185+
let msg = "Failed in reading Archive: \(error.localizedDescription)"
186+
completion([], UtilsDownloadError.invalidArchive(message: msg))
188187
}
189-
})
190-
188+
}
191189
}
192190
}

ios/Plugin/Utils/UtilsFile.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -421,15 +421,13 @@ class UtilsFile {
421421

422422
}
423423

424-
class func unzipToDatabase(fromURL: URL, databaseLocation: String, zip: String,
425-
overwrite: Bool) throws {
424+
class func unzipToDatabase(fromURL: URL, databaseLocation: String, zip: String, overwrite: Bool) throws {
426425
do {
427426
let zipAsset: URL = fromURL.appendingPathComponent(zip)
428-
guard let archive = Archive(url: zipAsset, accessMode: .read) else {
429-
let msg = "Error: Read Archive: \(zipAsset) failed"
430-
print("\(msg)")
431-
throw UtilsFileError.unzipToDatabaseFailed(message: msg)
432-
}
427+
428+
// Use the throwing initializer
429+
let archive = try Archive(url: zipAsset, accessMode: .read)
430+
433431
let uDb: URL = try getFolderURL(folderPath: databaseLocation)
434432
for entry in archive {
435433
let dbEntry = setPathSuffix(sDb: entry.path)
@@ -442,7 +440,6 @@ class UtilsFile {
442440
}
443441
_ = try archive.extract(entry, to: zipCopy)
444442
}
445-
446443
} catch {
447444
let msg = "Error: Extracting \(entry.path) from archive failed \(error.localizedDescription)"
448445
print("\(msg)")

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,6 @@
9797
}
9898
},
9999
"dependencies": {
100-
"jeep-sqlite": "^2.7.0"
100+
"jeep-sqlite": "^2.7.2"
101101
}
102102
}

0 commit comments

Comments
 (0)