@unvired/cordova-plugin-unvired-electron-db 0.0.40 → 0.0.42
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/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/browser/DbPluginProxy.js +59 -37
- package/src/electron/package.json +1 -1
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
2
|
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
|
3
3
|
id="@unvired/cordova-plugin-unvired-electron-db"
|
|
4
|
-
version="0.0.
|
|
4
|
+
version="0.0.42"
|
|
5
5
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
6
6
|
<name>Unvired DB</name>
|
|
7
7
|
<description>Unvired DB Native Support for Cordova</description>
|
|
@@ -18,6 +18,7 @@ module.exports.create = async function (sucessCallback, errorCallback, options)
|
|
|
18
18
|
sucessCallback(dbCreationResponse);
|
|
19
19
|
}
|
|
20
20
|
catch (err) {
|
|
21
|
+
console.error("Error creating DB:", err);
|
|
21
22
|
errorCallback(err);
|
|
22
23
|
}
|
|
23
24
|
};
|
|
@@ -29,7 +30,11 @@ module.exports.execute = async function (sucessCallback, errorCallback, options)
|
|
|
29
30
|
try {
|
|
30
31
|
const db = dbType == DBType.FrameworkDb ? webDb.fwDb : webDb.appDb;
|
|
31
32
|
|
|
32
|
-
if
|
|
33
|
+
// Check if query is a SELECT statement (starts with SELECT or WITH for CTEs)
|
|
34
|
+
// Using regex to handle leading whitespace and ensure it's the start of the command
|
|
35
|
+
const isSelect = /^\s*\(?\s*(SELECT|WITH|PRAGMA|VALUES|EXPLAIN)\b/i.test(query);
|
|
36
|
+
|
|
37
|
+
if (isSelect) {
|
|
33
38
|
let rows = [];
|
|
34
39
|
var stmt = db.prepare(query);
|
|
35
40
|
while (stmt.step()) {
|
|
@@ -53,6 +58,7 @@ module.exports.execute = async function (sucessCallback, errorCallback, options)
|
|
|
53
58
|
}
|
|
54
59
|
}
|
|
55
60
|
catch (err) {
|
|
61
|
+
console.error("Error executing query: " + query, err);
|
|
56
62
|
errorCallback(err);
|
|
57
63
|
}
|
|
58
64
|
};
|
|
@@ -65,6 +71,7 @@ module.exports.close = async function (sucessCallback, errorCallback, options) {
|
|
|
65
71
|
sucessCallback(true);
|
|
66
72
|
}
|
|
67
73
|
catch (err) {
|
|
74
|
+
console.error("Error closing DB:", err);
|
|
68
75
|
errorCallback(err);
|
|
69
76
|
}
|
|
70
77
|
};
|
|
@@ -154,56 +161,66 @@ var webDb = /** @class */ (function () {
|
|
|
154
161
|
|
|
155
162
|
webDb.initialize = async function (userId) {
|
|
156
163
|
var initSqlJs = window.initSqlJs;
|
|
157
|
-
config = {
|
|
158
|
-
locateFile: filename => "assets/js/sql-wasm.wasm"
|
|
164
|
+
var config = {
|
|
165
|
+
locateFile: filename => "assets/js/sql-wasm.wasm",
|
|
166
|
+
// INITIAL_MEMORY: 268435456 // 256MB
|
|
159
167
|
};
|
|
160
168
|
try {
|
|
161
169
|
let SQL = await initSqlJs(config);
|
|
162
170
|
if (webDb.fwDb == null) {
|
|
163
|
-
|
|
171
|
+
let data = await webDb.getDataFromIndexedDB(userId + "_fw_db", "fwData");
|
|
172
|
+
if (data) {
|
|
173
|
+
console.log("Initializing fwDb with data size: " + (data.byteLength || data.length));
|
|
174
|
+
webDb.fwDb = new SQL.Database(data);
|
|
175
|
+
} else {
|
|
176
|
+
webDb.fwDb = new SQL.Database();
|
|
177
|
+
}
|
|
164
178
|
// Set PRAGMA for framework database
|
|
165
179
|
webDb.fwDb.run("PRAGMA journal_mode = WAL;");
|
|
166
180
|
webDb.fwDb.run("PRAGMA read_uncommitted = 1;");
|
|
167
|
-
await webDb.populateWebDb(SQL, true, userId);
|
|
168
181
|
}
|
|
169
182
|
if (webDb.appDb == null) {
|
|
170
|
-
|
|
183
|
+
let data = await webDb.getDataFromIndexedDB(userId + "_app_db", "appData");
|
|
184
|
+
if (data) {
|
|
185
|
+
console.log("Initializing appDb with data size: " + (data.byteLength || data.length));
|
|
186
|
+
webDb.appDb = new SQL.Database(data);
|
|
187
|
+
} else {
|
|
188
|
+
webDb.appDb = new SQL.Database();
|
|
189
|
+
}
|
|
171
190
|
// Set PRAGMA for app database
|
|
172
191
|
webDb.appDb.run("PRAGMA journal_mode = WAL;");
|
|
173
192
|
webDb.appDb.run("PRAGMA read_uncommitted = 1;");
|
|
174
193
|
webDb.appDb.run("PRAGMA foreign_keys = ON;");
|
|
175
|
-
await webDb.populateWebDb(SQL, false, userId);
|
|
176
194
|
}
|
|
177
195
|
return "DB Created Successfully";
|
|
178
196
|
}
|
|
179
197
|
catch (err) {
|
|
198
|
+
console.error("Error initializing DB:", err);
|
|
180
199
|
throw err;
|
|
181
200
|
}
|
|
182
201
|
};
|
|
183
202
|
|
|
184
|
-
webDb.
|
|
203
|
+
webDb.getDataFromIndexedDB = function (dbName, storeName) {
|
|
185
204
|
return new Promise((resolve, reject) => {
|
|
186
205
|
var db;
|
|
187
|
-
var request =
|
|
188
|
-
var storeName = isFwDb ? "fwData" : "appData";
|
|
206
|
+
var request = window.indexedDB.open(dbName);
|
|
189
207
|
request.onupgradeneeded = function (event) {
|
|
190
208
|
db = event.target.result;
|
|
191
209
|
db.createObjectStore(storeName, { keyPath: "id" });
|
|
192
|
-
resolve();
|
|
193
210
|
};
|
|
194
211
|
request.onerror = function (event) {
|
|
195
212
|
console.log("The database failed to open: " + event);
|
|
196
|
-
resolve();
|
|
213
|
+
resolve(null);
|
|
197
214
|
};
|
|
198
215
|
request.onsuccess = function (event) {
|
|
199
216
|
db = request.result;
|
|
200
217
|
if (!db.objectStoreNames.contains(storeName)) {
|
|
201
|
-
resolve();
|
|
218
|
+
resolve(null);
|
|
202
219
|
return;
|
|
203
220
|
}
|
|
204
221
|
|
|
205
222
|
db.onversionchange = function() {
|
|
206
|
-
console.log('Unvired Plugin Proxy: Received version change event
|
|
223
|
+
console.log('Unvired Plugin Proxy: Received version change event. Closing the database connection.')
|
|
207
224
|
db.close()
|
|
208
225
|
}
|
|
209
226
|
|
|
@@ -213,19 +230,15 @@ var webDb = /** @class */ (function () {
|
|
|
213
230
|
|
|
214
231
|
dataRequest.onerror = function (event) {
|
|
215
232
|
console.log("Unable to read " + storeName + " index DB table");
|
|
216
|
-
resolve();
|
|
233
|
+
resolve(null);
|
|
217
234
|
};
|
|
218
235
|
dataRequest.onsuccess = function (event) {
|
|
219
|
-
if (dataRequest.result) {
|
|
220
|
-
|
|
221
|
-
webDb.fwDb = new SQL.Database(dataRequest.result.data);
|
|
222
|
-
} else {
|
|
223
|
-
webDb.appDb = new SQL.Database(dataRequest.result.data);
|
|
224
|
-
}
|
|
236
|
+
if (dataRequest.result && dataRequest.result.data) {
|
|
237
|
+
resolve(dataRequest.result.data);
|
|
225
238
|
} else {
|
|
226
|
-
console.log("
|
|
239
|
+
console.log("No data found in " + storeName);
|
|
240
|
+
resolve(null);
|
|
227
241
|
}
|
|
228
|
-
resolve();
|
|
229
242
|
};
|
|
230
243
|
};
|
|
231
244
|
});
|
|
@@ -294,23 +307,27 @@ var webDb = /** @class */ (function () {
|
|
|
294
307
|
if (ch === "'") {
|
|
295
308
|
// start of quoted string; find the closing quote handling escaped ''
|
|
296
309
|
let j = i + 1;
|
|
297
|
-
let inner = '';
|
|
298
310
|
let closed = false;
|
|
311
|
+
|
|
299
312
|
while (j < len) {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
continue;
|
|
307
|
-
} else {
|
|
308
|
-
closed = true;
|
|
309
|
-
break; // closing quote at j
|
|
313
|
+
if (query.charAt(j) !== "'") {
|
|
314
|
+
// Optimize: Skip to the next single quote
|
|
315
|
+
const nextQuote = query.indexOf("'", j);
|
|
316
|
+
if (nextQuote === -1) {
|
|
317
|
+
j = len; // Not found
|
|
318
|
+
break;
|
|
310
319
|
}
|
|
320
|
+
j = nextQuote;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// We found a quote at index j
|
|
324
|
+
if (j + 1 < len && query.charAt(j + 1) === "'") {
|
|
325
|
+
// It is an escaped quote (''), skip both characters
|
|
326
|
+
j += 2;
|
|
311
327
|
} else {
|
|
312
|
-
|
|
313
|
-
|
|
328
|
+
// It is a closing quote
|
|
329
|
+
closed = true;
|
|
330
|
+
break;
|
|
314
331
|
}
|
|
315
332
|
}
|
|
316
333
|
|
|
@@ -319,10 +336,15 @@ var webDb = /** @class */ (function () {
|
|
|
319
336
|
return { isPrepared: false, query: query, values: [] };
|
|
320
337
|
}
|
|
321
338
|
|
|
339
|
+
// Extract content and handle escaped quotes
|
|
340
|
+
const rawContent = query.slice(i + 1, j);
|
|
341
|
+
const inner = rawContent.replace(/''/g, "'");
|
|
342
|
+
|
|
322
343
|
// Append text before this literal
|
|
323
344
|
preparedQuery += query.slice(lastIndex, i);
|
|
324
345
|
|
|
325
|
-
|
|
346
|
+
// Optimize: Check length first to avoid toUpperCase() on large strings
|
|
347
|
+
if (inner.length === 4 && inner.toUpperCase() === 'NULL') {
|
|
326
348
|
// keep quoted NULL as-is
|
|
327
349
|
preparedQuery += query.slice(i, j + 1);
|
|
328
350
|
} else {
|