@capacitor-community/sqlite 3.4.0 → 3.4.1-3
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 +7 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +134 -89
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +449 -264
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +41 -27
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ExportToJson.java +5 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +24 -15
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/JsonSQLite.java +4 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/UtilsJson.java +23 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/SqliteConfig.java +9 -0
- package/dist/esm/definitions.js +1 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/plugin.cjs.js +1 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1 -1
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +228 -176
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +150 -109
- package/ios/Plugin/CapacitorSQLitePlugin.swift +17 -10
- package/ios/Plugin/Database.swift +50 -20
- package/ios/Plugin/ImportExportJson/ExportToJson.swift +8 -0
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +20 -14
- package/ios/Plugin/SqliteConfig.swift +1 -0
- package/ios/Plugin/Utils/UtilsJson.swift +28 -0
- package/package.json +9 -6
package/electron/dist/plugin.js
CHANGED
|
@@ -435,12 +435,187 @@ utilsSQLite.UtilsSQLite = UtilsSQLite;
|
|
|
435
435
|
|
|
436
436
|
var utilsJson = {};
|
|
437
437
|
|
|
438
|
+
var utilsDrop = {};
|
|
439
|
+
|
|
440
|
+
Object.defineProperty(utilsDrop, "__esModule", { value: true });
|
|
441
|
+
utilsDrop.UtilsDrop = void 0;
|
|
442
|
+
const utilsSQLite_1$5 = utilsSQLite;
|
|
443
|
+
class UtilsDrop {
|
|
444
|
+
constructor() {
|
|
445
|
+
this._uSQLite = new utilsSQLite_1$5.UtilsSQLite();
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* GetTablesNames
|
|
449
|
+
* @param mDb
|
|
450
|
+
*/
|
|
451
|
+
async getTablesNames(mDb) {
|
|
452
|
+
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
453
|
+
sql += "type='table' AND name NOT LIKE 'sync_table' ";
|
|
454
|
+
sql += "AND name NOT LIKE '_temp_%' ";
|
|
455
|
+
sql += "AND name NOT LIKE 'sqlite_%' ";
|
|
456
|
+
sql += 'ORDER BY rootpage DESC;';
|
|
457
|
+
const retArr = [];
|
|
458
|
+
try {
|
|
459
|
+
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
460
|
+
for (const query of retQuery) {
|
|
461
|
+
retArr.push(query.name);
|
|
462
|
+
}
|
|
463
|
+
return Promise.resolve(retArr);
|
|
464
|
+
}
|
|
465
|
+
catch (err) {
|
|
466
|
+
return Promise.reject(`getTablesNames: ${err}`);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* GetViewsNames
|
|
471
|
+
* @param mDb
|
|
472
|
+
*/
|
|
473
|
+
async getViewsNames(mDb) {
|
|
474
|
+
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
475
|
+
sql += "type='view' AND name NOT LIKE 'sqlite_%' ";
|
|
476
|
+
sql += 'ORDER BY rootpage DESC;';
|
|
477
|
+
const retArr = [];
|
|
478
|
+
try {
|
|
479
|
+
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
480
|
+
for (const query of retQuery) {
|
|
481
|
+
retArr.push(query.name);
|
|
482
|
+
}
|
|
483
|
+
return Promise.resolve(retArr);
|
|
484
|
+
}
|
|
485
|
+
catch (err) {
|
|
486
|
+
return Promise.reject(`getViewsNames: ${err}`);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* DropElements
|
|
491
|
+
* @param db
|
|
492
|
+
* @param type ["table","index","trigger"]
|
|
493
|
+
*/
|
|
494
|
+
async dropElements(db, type) {
|
|
495
|
+
let msg = '';
|
|
496
|
+
switch (type) {
|
|
497
|
+
case 'index':
|
|
498
|
+
msg = 'DropIndexes';
|
|
499
|
+
break;
|
|
500
|
+
case 'trigger':
|
|
501
|
+
msg = 'DropTriggers';
|
|
502
|
+
break;
|
|
503
|
+
case 'table':
|
|
504
|
+
msg = 'DropTables';
|
|
505
|
+
break;
|
|
506
|
+
case 'view':
|
|
507
|
+
msg = 'DropViews';
|
|
508
|
+
break;
|
|
509
|
+
default:
|
|
510
|
+
return Promise.reject(`DropElements: ${type} ` + 'not found');
|
|
511
|
+
}
|
|
512
|
+
// get the element's names
|
|
513
|
+
let stmt = 'SELECT name FROM sqlite_master WHERE ';
|
|
514
|
+
stmt += `type = '${type}' AND name NOT LIKE 'sqlite_%';`;
|
|
515
|
+
try {
|
|
516
|
+
const elements = await this._uSQLite.queryAll(db, stmt, []);
|
|
517
|
+
if (elements.length > 0) {
|
|
518
|
+
const upType = type.toUpperCase();
|
|
519
|
+
const statements = [];
|
|
520
|
+
for (const elem of elements) {
|
|
521
|
+
let stmt = `DROP ${upType} IF EXISTS `;
|
|
522
|
+
stmt += `${elem.name};`;
|
|
523
|
+
statements.push(stmt);
|
|
524
|
+
}
|
|
525
|
+
for (const stmt of statements) {
|
|
526
|
+
const lastId = await this._uSQLite.prepareRun(db, stmt, []);
|
|
527
|
+
if (lastId < 0) {
|
|
528
|
+
return Promise.reject(`${msg}: lastId < 0`);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return Promise.resolve();
|
|
533
|
+
}
|
|
534
|
+
catch (err) {
|
|
535
|
+
return Promise.reject(`${msg}: ${err}`);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
/**
|
|
539
|
+
* DropAll
|
|
540
|
+
* Drop all database's elements
|
|
541
|
+
* @param db
|
|
542
|
+
*/
|
|
543
|
+
async dropAll(db) {
|
|
544
|
+
try {
|
|
545
|
+
// drop tables
|
|
546
|
+
await this.dropElements(db, 'table');
|
|
547
|
+
// drop indexes
|
|
548
|
+
await this.dropElements(db, 'index');
|
|
549
|
+
// drop triggers
|
|
550
|
+
await this.dropElements(db, 'trigger');
|
|
551
|
+
// drop views
|
|
552
|
+
await this.dropElements(db, 'view');
|
|
553
|
+
// vacuum the database
|
|
554
|
+
await this._uSQLite.prepareRun(db, 'VACUUM;', []);
|
|
555
|
+
return Promise.resolve();
|
|
556
|
+
}
|
|
557
|
+
catch (err) {
|
|
558
|
+
return Promise.reject(`DropAll: ${err}`);
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* DropTempTables
|
|
563
|
+
* @param db
|
|
564
|
+
* @param alterTables
|
|
565
|
+
*/
|
|
566
|
+
async dropTempTables(db, alterTables) {
|
|
567
|
+
const tempTables = Object.keys(alterTables);
|
|
568
|
+
const statements = [];
|
|
569
|
+
for (const tTable of tempTables) {
|
|
570
|
+
let stmt = 'DROP TABLE IF EXISTS ';
|
|
571
|
+
stmt += `_temp_${tTable};`;
|
|
572
|
+
statements.push(stmt);
|
|
573
|
+
}
|
|
574
|
+
try {
|
|
575
|
+
const changes = await this._uSQLite.execute(db, statements.join('\n'));
|
|
576
|
+
if (changes < 0) {
|
|
577
|
+
return Promise.reject('DropTempTables: changes < 0');
|
|
578
|
+
}
|
|
579
|
+
return Promise.resolve();
|
|
580
|
+
}
|
|
581
|
+
catch (err) {
|
|
582
|
+
return Promise.reject(`DropTempTables: ${err}`);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
utilsDrop.UtilsDrop = UtilsDrop;
|
|
587
|
+
|
|
438
588
|
Object.defineProperty(utilsJson, "__esModule", { value: true });
|
|
439
589
|
utilsJson.UtilsJson = void 0;
|
|
440
|
-
const
|
|
590
|
+
const utilsDrop_1$2 = utilsDrop;
|
|
591
|
+
const utilsSQLite_1$4 = utilsSQLite;
|
|
441
592
|
class UtilsJson {
|
|
442
593
|
constructor() {
|
|
443
|
-
this._uSQLite = new utilsSQLite_1$
|
|
594
|
+
this._uSQLite = new utilsSQLite_1$4.UtilsSQLite();
|
|
595
|
+
this._uDrop = new utilsDrop_1$2.UtilsDrop();
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* isLastModified
|
|
599
|
+
* @param db
|
|
600
|
+
* @param isOpen
|
|
601
|
+
*/
|
|
602
|
+
async isLastModified(db, isOpen) {
|
|
603
|
+
if (!isOpen) {
|
|
604
|
+
return Promise.reject('isLastModified: database not opened');
|
|
605
|
+
}
|
|
606
|
+
try {
|
|
607
|
+
const tableList = await this._uDrop.getTablesNames(db);
|
|
608
|
+
for (const table of tableList) {
|
|
609
|
+
const tableNamesTypes = await this.getTableColumnNamesTypes(db, table);
|
|
610
|
+
const tableColumnNames = tableNamesTypes.names;
|
|
611
|
+
if (tableColumnNames.includes('last_modified')) {
|
|
612
|
+
return Promise.resolve(true);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
catch (err) {
|
|
617
|
+
return Promise.reject(`isLastModified: ${err}`);
|
|
618
|
+
}
|
|
444
619
|
}
|
|
445
620
|
/**
|
|
446
621
|
* IsTableExists
|
|
@@ -554,6 +729,7 @@ class UtilsJson {
|
|
|
554
729
|
*/
|
|
555
730
|
async createSchemaStatement(jsonData) {
|
|
556
731
|
const statements = [];
|
|
732
|
+
let isLastModified = false;
|
|
557
733
|
// Prepare the statement to execute
|
|
558
734
|
try {
|
|
559
735
|
for (const jTable of jsonData.tables) {
|
|
@@ -564,6 +740,9 @@ class UtilsJson {
|
|
|
564
740
|
if (j === jTable.schema.length - 1) {
|
|
565
741
|
if (jTable.schema[j].column) {
|
|
566
742
|
statements.push(`${jTable.schema[j].column} ${jTable.schema[j].value}`);
|
|
743
|
+
if (jTable.schema[j].column === 'last_modified') {
|
|
744
|
+
isLastModified = true;
|
|
745
|
+
}
|
|
567
746
|
}
|
|
568
747
|
else if (jTable.schema[j].foreignkey) {
|
|
569
748
|
statements.push(`FOREIGN KEY (${jTable.schema[j].foreignkey}) ${jTable.schema[j].value}`);
|
|
@@ -575,6 +754,9 @@ class UtilsJson {
|
|
|
575
754
|
else {
|
|
576
755
|
if (jTable.schema[j].column) {
|
|
577
756
|
statements.push(`${jTable.schema[j].column} ${jTable.schema[j].value},`);
|
|
757
|
+
if (jTable.schema[j].column === 'last_modified') {
|
|
758
|
+
isLastModified = true;
|
|
759
|
+
}
|
|
578
760
|
}
|
|
579
761
|
else if (jTable.schema[j].foreignkey) {
|
|
580
762
|
statements.push(`FOREIGN KEY (${jTable.schema[j].foreignkey}) ${jTable.schema[j].value},`);
|
|
@@ -585,17 +767,19 @@ class UtilsJson {
|
|
|
585
767
|
}
|
|
586
768
|
}
|
|
587
769
|
statements.push(');');
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
770
|
+
if (isLastModified) {
|
|
771
|
+
// create trigger last_modified associated with the table
|
|
772
|
+
let trig = 'CREATE TRIGGER IF NOT EXISTS ';
|
|
773
|
+
trig += `${jTable.name}`;
|
|
774
|
+
trig += `_trigger_last_modified `;
|
|
775
|
+
trig += `AFTER UPDATE ON ${jTable.name} `;
|
|
776
|
+
trig += 'FOR EACH ROW WHEN NEW.last_modified <= ';
|
|
777
|
+
trig += 'OLD.last_modified BEGIN UPDATE ';
|
|
778
|
+
trig += `${jTable.name} `;
|
|
779
|
+
trig += `SET last_modified = `;
|
|
780
|
+
trig += "(strftime('%s','now')) WHERE id=OLD.id; END;";
|
|
781
|
+
statements.push(trig);
|
|
782
|
+
}
|
|
599
783
|
}
|
|
600
784
|
if (jTable.indexes != null && jTable.indexes.length >= 1) {
|
|
601
785
|
for (const jIndex of jTable.indexes) {
|
|
@@ -1165,11 +1349,11 @@ utilsJson.UtilsJson = UtilsJson;
|
|
|
1165
1349
|
|
|
1166
1350
|
Object.defineProperty(exportToJson, "__esModule", { value: true });
|
|
1167
1351
|
exportToJson.ExportToJson = void 0;
|
|
1168
|
-
const utilsSQLite_1$
|
|
1352
|
+
const utilsSQLite_1$3 = utilsSQLite;
|
|
1169
1353
|
const utilsJson_1$4 = utilsJson;
|
|
1170
1354
|
class ExportToJson {
|
|
1171
1355
|
constructor() {
|
|
1172
|
-
this._uSQLite = new utilsSQLite_1$
|
|
1356
|
+
this._uSQLite = new utilsSQLite_1$3.UtilsSQLite();
|
|
1173
1357
|
this._uJson = new utilsJson_1$4.UtilsJson();
|
|
1174
1358
|
}
|
|
1175
1359
|
/**
|
|
@@ -1191,6 +1375,10 @@ class ExportToJson {
|
|
|
1191
1375
|
return Promise.reject("createExportObject: table's names failed");
|
|
1192
1376
|
}
|
|
1193
1377
|
else {
|
|
1378
|
+
const isTable = await this._uJson.isTableExists(mDB, true, 'sync_table');
|
|
1379
|
+
if (!isTable && sqlObj.mode === 'partial') {
|
|
1380
|
+
return Promise.reject('No sync_table available');
|
|
1381
|
+
}
|
|
1194
1382
|
switch (sqlObj.mode) {
|
|
1195
1383
|
case 'partial': {
|
|
1196
1384
|
tables = await this.getTablesPartial(mDB, resTables);
|
|
@@ -1807,156 +1995,6 @@ exportToJson.ExportToJson = ExportToJson;
|
|
|
1807
1995
|
|
|
1808
1996
|
var importFromJson = {};
|
|
1809
1997
|
|
|
1810
|
-
var utilsDrop = {};
|
|
1811
|
-
|
|
1812
|
-
Object.defineProperty(utilsDrop, "__esModule", { value: true });
|
|
1813
|
-
utilsDrop.UtilsDrop = void 0;
|
|
1814
|
-
const utilsSQLite_1$3 = utilsSQLite;
|
|
1815
|
-
class UtilsDrop {
|
|
1816
|
-
constructor() {
|
|
1817
|
-
this._uSQLite = new utilsSQLite_1$3.UtilsSQLite();
|
|
1818
|
-
}
|
|
1819
|
-
/**
|
|
1820
|
-
* GetTablesNames
|
|
1821
|
-
* @param mDb
|
|
1822
|
-
*/
|
|
1823
|
-
async getTablesNames(mDb) {
|
|
1824
|
-
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
1825
|
-
sql += "type='table' AND name NOT LIKE 'sync_table' ";
|
|
1826
|
-
sql += "AND name NOT LIKE '_temp_%' ";
|
|
1827
|
-
sql += "AND name NOT LIKE 'sqlite_%' ";
|
|
1828
|
-
sql += 'ORDER BY rootpage DESC;';
|
|
1829
|
-
const retArr = [];
|
|
1830
|
-
try {
|
|
1831
|
-
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
1832
|
-
for (const query of retQuery) {
|
|
1833
|
-
retArr.push(query.name);
|
|
1834
|
-
}
|
|
1835
|
-
return Promise.resolve(retArr);
|
|
1836
|
-
}
|
|
1837
|
-
catch (err) {
|
|
1838
|
-
return Promise.reject(`getTablesNames: ${err}`);
|
|
1839
|
-
}
|
|
1840
|
-
}
|
|
1841
|
-
/**
|
|
1842
|
-
* GetViewsNames
|
|
1843
|
-
* @param mDb
|
|
1844
|
-
*/
|
|
1845
|
-
async getViewsNames(mDb) {
|
|
1846
|
-
let sql = 'SELECT name FROM sqlite_master WHERE ';
|
|
1847
|
-
sql += "type='view' AND name NOT LIKE 'sqlite_%' ";
|
|
1848
|
-
sql += 'ORDER BY rootpage DESC;';
|
|
1849
|
-
const retArr = [];
|
|
1850
|
-
try {
|
|
1851
|
-
const retQuery = await this._uSQLite.queryAll(mDb, sql, []);
|
|
1852
|
-
for (const query of retQuery) {
|
|
1853
|
-
retArr.push(query.name);
|
|
1854
|
-
}
|
|
1855
|
-
return Promise.resolve(retArr);
|
|
1856
|
-
}
|
|
1857
|
-
catch (err) {
|
|
1858
|
-
return Promise.reject(`getViewsNames: ${err}`);
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
/**
|
|
1862
|
-
* DropElements
|
|
1863
|
-
* @param db
|
|
1864
|
-
* @param type ["table","index","trigger"]
|
|
1865
|
-
*/
|
|
1866
|
-
async dropElements(db, type) {
|
|
1867
|
-
let msg = '';
|
|
1868
|
-
switch (type) {
|
|
1869
|
-
case 'index':
|
|
1870
|
-
msg = 'DropIndexes';
|
|
1871
|
-
break;
|
|
1872
|
-
case 'trigger':
|
|
1873
|
-
msg = 'DropTriggers';
|
|
1874
|
-
break;
|
|
1875
|
-
case 'table':
|
|
1876
|
-
msg = 'DropTables';
|
|
1877
|
-
break;
|
|
1878
|
-
case 'view':
|
|
1879
|
-
msg = 'DropViews';
|
|
1880
|
-
break;
|
|
1881
|
-
default:
|
|
1882
|
-
return Promise.reject(`DropElements: ${type} ` + 'not found');
|
|
1883
|
-
}
|
|
1884
|
-
// get the element's names
|
|
1885
|
-
let stmt = 'SELECT name FROM sqlite_master WHERE ';
|
|
1886
|
-
stmt += `type = '${type}' AND name NOT LIKE 'sqlite_%';`;
|
|
1887
|
-
try {
|
|
1888
|
-
const elements = await this._uSQLite.queryAll(db, stmt, []);
|
|
1889
|
-
if (elements.length > 0) {
|
|
1890
|
-
const upType = type.toUpperCase();
|
|
1891
|
-
const statements = [];
|
|
1892
|
-
for (const elem of elements) {
|
|
1893
|
-
let stmt = `DROP ${upType} IF EXISTS `;
|
|
1894
|
-
stmt += `${elem.name};`;
|
|
1895
|
-
statements.push(stmt);
|
|
1896
|
-
}
|
|
1897
|
-
for (const stmt of statements) {
|
|
1898
|
-
const lastId = await this._uSQLite.prepareRun(db, stmt, []);
|
|
1899
|
-
if (lastId < 0) {
|
|
1900
|
-
return Promise.reject(`${msg}: lastId < 0`);
|
|
1901
|
-
}
|
|
1902
|
-
}
|
|
1903
|
-
}
|
|
1904
|
-
return Promise.resolve();
|
|
1905
|
-
}
|
|
1906
|
-
catch (err) {
|
|
1907
|
-
return Promise.reject(`${msg}: ${err}`);
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
/**
|
|
1911
|
-
* DropAll
|
|
1912
|
-
* Drop all database's elements
|
|
1913
|
-
* @param db
|
|
1914
|
-
*/
|
|
1915
|
-
async dropAll(db) {
|
|
1916
|
-
try {
|
|
1917
|
-
// drop tables
|
|
1918
|
-
await this.dropElements(db, 'table');
|
|
1919
|
-
// drop indexes
|
|
1920
|
-
await this.dropElements(db, 'index');
|
|
1921
|
-
// drop triggers
|
|
1922
|
-
await this.dropElements(db, 'trigger');
|
|
1923
|
-
// drop views
|
|
1924
|
-
await this.dropElements(db, 'view');
|
|
1925
|
-
// vacuum the database
|
|
1926
|
-
await this._uSQLite.prepareRun(db, 'VACUUM;', []);
|
|
1927
|
-
return Promise.resolve();
|
|
1928
|
-
}
|
|
1929
|
-
catch (err) {
|
|
1930
|
-
return Promise.reject(`DropAll: ${err}`);
|
|
1931
|
-
}
|
|
1932
|
-
}
|
|
1933
|
-
/**
|
|
1934
|
-
* DropTempTables
|
|
1935
|
-
* @param db
|
|
1936
|
-
* @param alterTables
|
|
1937
|
-
*/
|
|
1938
|
-
async dropTempTables(db, alterTables) {
|
|
1939
|
-
const tempTables = Object.keys(alterTables);
|
|
1940
|
-
const statements = [];
|
|
1941
|
-
for (const tTable of tempTables) {
|
|
1942
|
-
let stmt = 'DROP TABLE IF EXISTS ';
|
|
1943
|
-
stmt += `_temp_${tTable};`;
|
|
1944
|
-
statements.push(stmt);
|
|
1945
|
-
}
|
|
1946
|
-
try {
|
|
1947
|
-
const changes = await this._uSQLite.execute(db, statements.join('\n'));
|
|
1948
|
-
if (changes < 0) {
|
|
1949
|
-
return Promise.reject('DropTempTables: changes < 0');
|
|
1950
|
-
}
|
|
1951
|
-
return Promise.resolve();
|
|
1952
|
-
}
|
|
1953
|
-
catch (err) {
|
|
1954
|
-
return Promise.reject(`DropTempTables: ${err}`);
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
}
|
|
1958
|
-
utilsDrop.UtilsDrop = UtilsDrop;
|
|
1959
|
-
|
|
1960
1998
|
Object.defineProperty(importFromJson, "__esModule", { value: true });
|
|
1961
1999
|
importFromJson.ImportFromJson = void 0;
|
|
1962
2000
|
const utilsDrop_1$1 = utilsDrop;
|
|
@@ -3069,17 +3107,23 @@ class Database {
|
|
|
3069
3107
|
try {
|
|
3070
3108
|
const retB = await this._uJson.isTableExists(this._mDB, isOpen, 'sync_table');
|
|
3071
3109
|
if (!retB) {
|
|
3072
|
-
const
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3110
|
+
const isLastModified = await this._uJson.isLastModified(this._mDB, isOpen);
|
|
3111
|
+
if (isLastModified) {
|
|
3112
|
+
const date = Math.round(new Date().getTime() / 1000);
|
|
3113
|
+
let stmts = `
|
|
3114
|
+
CREATE TABLE IF NOT EXISTS sync_table (
|
|
3115
|
+
id INTEGER PRIMARY KEY NOT NULL,
|
|
3116
|
+
sync_date INTEGER
|
|
3117
|
+
);`;
|
|
3118
|
+
stmts += `INSERT INTO sync_table (sync_date) VALUES (
|
|
3119
|
+
"${date}");`;
|
|
3120
|
+
changes = await this._uSQLite.execute(this._mDB, stmts);
|
|
3121
|
+
if (changes < 0) {
|
|
3122
|
+
return Promise.reject(`CreateSyncTable: failed changes < 0`);
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
else {
|
|
3126
|
+
return Promise.reject('No last_modified column in tables');
|
|
3083
3127
|
}
|
|
3084
3128
|
}
|
|
3085
3129
|
return Promise.resolve(changes);
|
|
@@ -3101,6 +3145,10 @@ class Database {
|
|
|
3101
3145
|
return { result: false, message: msg };
|
|
3102
3146
|
}
|
|
3103
3147
|
try {
|
|
3148
|
+
const isTable = await this._uJson.isTableExists(this._mDB, this._isDBOpen, 'sync_table');
|
|
3149
|
+
if (!isTable) {
|
|
3150
|
+
return Promise.reject('No sync_table available');
|
|
3151
|
+
}
|
|
3104
3152
|
const sDate = Math.round(new Date(syncDate).getTime() / 1000);
|
|
3105
3153
|
let stmt = `UPDATE sync_table SET sync_date = `;
|
|
3106
3154
|
stmt += `${sDate} WHERE id = 1;`;
|
|
@@ -3128,6 +3176,10 @@ class Database {
|
|
|
3128
3176
|
return { syncDate: 0, message: msg };
|
|
3129
3177
|
}
|
|
3130
3178
|
try {
|
|
3179
|
+
const isTable = await this._uJson.isTableExists(this._mDB, this._isDBOpen, 'sync_table');
|
|
3180
|
+
if (!isTable) {
|
|
3181
|
+
return Promise.reject('No sync_table available');
|
|
3182
|
+
}
|
|
3131
3183
|
const syncDate = await this._eTJson.getSyncDate(this._mDB);
|
|
3132
3184
|
if (syncDate > 0) {
|
|
3133
3185
|
return { syncDate: syncDate };
|