@capacitor-community/sqlite 5.0.7-1 → 5.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.
Files changed (33) hide show
  1. package/README.md +6 -1
  2. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +123 -1
  3. package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +112 -0
  4. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +140 -78
  5. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +9 -9
  6. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDelete.java +484 -0
  7. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDrop.java +3 -3
  8. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +169 -0
  9. package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +4 -4
  10. package/dist/esm/definitions.d.ts +96 -11
  11. package/dist/esm/definitions.js +99 -50
  12. package/dist/esm/definitions.js.map +1 -1
  13. package/dist/esm/web.d.ts +4 -0
  14. package/dist/esm/web.js +44 -0
  15. package/dist/esm/web.js.map +1 -1
  16. package/dist/plugin.cjs.js +143 -50
  17. package/dist/plugin.cjs.js.map +1 -1
  18. package/dist/plugin.js +143 -50
  19. package/dist/plugin.js.map +1 -1
  20. package/electron/dist/plugin.js +1102 -260
  21. package/electron/dist/plugin.js.map +1 -1
  22. package/ios/Plugin/CapacitorSQLite.swift +119 -0
  23. package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
  24. package/ios/Plugin/CapacitorSQLitePlugin.swift +128 -0
  25. package/ios/Plugin/Database.swift +76 -0
  26. package/ios/Plugin/ImportExportJson/ImportFromJson.swift +13 -2
  27. package/ios/Plugin/Utils/UtilsDelete.swift +116 -114
  28. package/ios/Plugin/Utils/UtilsSQLCipher.swift +10 -3
  29. package/ios/Plugin/Utils/UtilsSQLStatement.swift +84 -84
  30. package/ios/Plugin/Utils/UtilsUpgrade.swift +3 -0
  31. package/package.json +2 -2
  32. package/src/definitions.ts +187 -53
  33. package/src/web.ts +48 -0
@@ -120,6 +120,34 @@ export interface CapacitorSQLitePlugin {
120
120
  * @since 0.0.1
121
121
  */
122
122
  close(options: capSQLiteOptions): Promise<void>;
123
+ /**
124
+ * Begin Database Transaction
125
+ * @param options
126
+ * @returns capSQLiteChanges
127
+ * @since 5.0.7
128
+ */
129
+ beginTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges>;
130
+ /**
131
+ * Commit Database Transaction
132
+ * @param options
133
+ * @returns capSQLiteChanges
134
+ * @since 5.0.7
135
+ */
136
+ commitTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges>;
137
+ /**
138
+ * Rollback Database Transaction
139
+ * @param options
140
+ * @returns capSQLiteChanges
141
+ * @since 5.0.7
142
+ */
143
+ rollbackTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges>;
144
+ /**
145
+ * Is Database Transaction Active
146
+ * @param options
147
+ * @returns capSQLiteResult
148
+ * @since 5.0.7
149
+ */
150
+ isTransactionActive(options: capSQLiteOptions): Promise<capSQLiteResult>;
123
151
  /**
124
152
  * Load a SQlite extension
125
153
  * @param options :capSQLiteExtensionPath
@@ -531,6 +559,14 @@ export interface capSQLiteExecuteOptions {
531
559
  * @since 4.1.0-7
532
560
  */
533
561
  readonly?: boolean;
562
+ /**
563
+ * Compatibility SQL92
564
+ * !!! ELECTRON ONLY
565
+ * default (true)
566
+ * @since 5.0.7
567
+ */
568
+ isSQL92?: boolean;
569
+
534
570
  }
535
571
  export interface capSQLiteSetOptions {
536
572
  /**
@@ -561,6 +597,13 @@ export interface capSQLiteSetOptions {
561
597
  * @since 5.0.5-3
562
598
  */
563
599
  returnMode?: string;
600
+ /**
601
+ * Compatibility SQL92
602
+ * !!! ELECTRON ONLY
603
+ * default (true)
604
+ * @since 5.0.7
605
+ */
606
+ isSQL92?: boolean;
564
607
  }
565
608
  export interface capSQLiteRunOptions {
566
609
  /**
@@ -595,6 +638,13 @@ export interface capSQLiteRunOptions {
595
638
  * @since 5.0.5-3
596
639
  */
597
640
  returnMode?: string;
641
+ /**
642
+ * Compatibility SQL92
643
+ * !!! ELECTRON ONLY
644
+ * default (true)
645
+ * @since 5.0.7
646
+ */
647
+ isSQL92?: boolean;
598
648
  }
599
649
  export interface capSQLiteQueryOptions {
600
650
  /**
@@ -617,6 +667,13 @@ export interface capSQLiteQueryOptions {
617
667
  * @since 4.1.0-7
618
668
  */
619
669
  readonly?: boolean;
670
+ /**
671
+ * Compatibility SQL92
672
+ * !!! ELECTRON ONLY
673
+ * default (true)
674
+ * @since 5.0.7
675
+ */
676
+ isSQL92?: boolean;
620
677
  }
621
678
  export interface capSQLiteImportOptions {
622
679
  /**
@@ -1740,6 +1797,30 @@ export interface ISQLiteDBConnection {
1740
1797
  * @since 2.9.0 refactor
1741
1798
  */
1742
1799
  close(): Promise<void>;
1800
+ /**
1801
+ * Begin Database Transaction
1802
+ * @returns capSQLiteChanges
1803
+ * @since 5.0.7
1804
+ */
1805
+ beginTransaction(): Promise<capSQLiteChanges>;
1806
+ /**
1807
+ * Commit Database Transaction
1808
+ * @returns capSQLiteChanges
1809
+ * @since 5.0.7
1810
+ */
1811
+ commitTransaction(): Promise<capSQLiteChanges>;
1812
+ /**
1813
+ * Rollback Database Transaction
1814
+ * @returns capSQLiteChanges
1815
+ * @since 5.0.7
1816
+ */
1817
+ rollbackTransaction(): Promise<capSQLiteChanges>;
1818
+ /**
1819
+ * Is Database Transaction Active
1820
+ * @returns capSQLiteResult
1821
+ * @since 5.0.7
1822
+ */
1823
+ isTransactionActive(): Promise<capSQLiteResult>;
1743
1824
  /**
1744
1825
  * Get Database Url
1745
1826
  * @returns Promise<capSQLiteUrl>
@@ -1772,7 +1853,7 @@ export interface ISQLiteDBConnection {
1772
1853
  * @returns Promise<capSQLiteChanges>
1773
1854
  * @since 2.9.0 refactor
1774
1855
  */
1775
- execute(statements: string, transaction?: boolean): Promise<capSQLiteChanges>;
1856
+ execute(statements: string, transaction?: boolean, isSQL92?: boolean): Promise<capSQLiteChanges>;
1776
1857
  /**
1777
1858
  * Execute SQLite DB Connection Query
1778
1859
  * @param statement
@@ -1780,7 +1861,7 @@ export interface ISQLiteDBConnection {
1780
1861
  * @returns Promise<Promise<DBSQLiteValues>
1781
1862
  * @since 2.9.0 refactor
1782
1863
  */
1783
- query(statement: string, values?: any[]): Promise<DBSQLiteValues>;
1864
+ query(statement: string, values?: any[], isSQL92?: boolean): Promise<DBSQLiteValues>;
1784
1865
  /**
1785
1866
  * Execute SQLite DB Connection Raw Statement
1786
1867
  * @param statement
@@ -1793,6 +1874,7 @@ export interface ISQLiteDBConnection {
1793
1874
  values?: any[],
1794
1875
  transaction?: boolean,
1795
1876
  returnMode?: string,
1877
+ isSQL92?: boolean
1796
1878
  ): Promise<capSQLiteChanges>;
1797
1879
  /**
1798
1880
  * Execute SQLite DB Connection Set
@@ -1804,6 +1886,7 @@ export interface ISQLiteDBConnection {
1804
1886
  set: capSQLiteSet[],
1805
1887
  transaction?: boolean,
1806
1888
  returnMode?: string,
1889
+ isSQL92?: boolean
1807
1890
  ): Promise<capSQLiteChanges>;
1808
1891
  /**
1809
1892
  * Check if a SQLite DB Connection exists
@@ -1870,12 +1953,14 @@ export interface ISQLiteDBConnection {
1870
1953
  /**
1871
1954
  *
1872
1955
  * @param txn
1873
- * @returns Promise<void>
1956
+ * @param isSQL92
1957
+ * @returns Promise<capSQLiteChanges> since 5.0.7
1874
1958
  * @since 3.4.0
1875
1959
  */
1876
1960
  executeTransaction(
1877
1961
  txn: { statement: string; values?: any[] }[],
1878
- ): Promise<void>;
1962
+ isSQL92: boolean
1963
+ ): Promise<capSQLiteChanges>;
1879
1964
  }
1880
1965
  /**
1881
1966
  * SQLiteDBConnection Class
@@ -1916,39 +2001,64 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
1916
2001
  return Promise.reject(err);
1917
2002
  }
1918
2003
  }
2004
+ async beginTransaction(): Promise<capSQLiteChanges> {
2005
+ try {
2006
+ const changes: capSQLiteChanges = await this.sqlite
2007
+ .beginTransaction({database: this.dbName});
2008
+ return Promise.resolve(changes);
2009
+ } catch (err) {
2010
+ return Promise.reject(err);
2011
+ }
2012
+ }
2013
+ async commitTransaction(): Promise<capSQLiteChanges> {
2014
+ try {
2015
+ const changes: capSQLiteChanges = await this.sqlite
2016
+ .commitTransaction({database: this.dbName});
2017
+ return Promise.resolve(changes);
2018
+ } catch (err) {
2019
+ return Promise.reject(err);
2020
+ }
2021
+ }
2022
+ async rollbackTransaction(): Promise<capSQLiteChanges> {
2023
+ try {
2024
+ const changes: capSQLiteChanges = await this.sqlite
2025
+ .rollbackTransaction({database: this.dbName});
2026
+ return Promise.resolve(changes);
2027
+ } catch (err) {
2028
+ return Promise.reject(err);
2029
+ }
2030
+ }
2031
+ async isTransactionActive(): Promise<capSQLiteResult> {
2032
+ try {
2033
+ const result: capSQLiteResult = await this.sqlite
2034
+ .isTransactionActive({database: this.dbName});
2035
+ return Promise.resolve(result);
2036
+ } catch (err) {
2037
+ return Promise.reject(err);
2038
+ }
2039
+ }
1919
2040
 
1920
2041
  async loadExtension(path: string): Promise<void> {
1921
2042
  try {
1922
- console.log(`database: ${this.dbName}`);
1923
- console.log(`readonly: ${this.readonly}}`);
1924
- console.log(`path: ${path}}`);
1925
2043
  await this.sqlite.loadExtension({
1926
2044
  database: this.dbName,
1927
2045
  path: path,
1928
2046
  readonly: this.readonly,
1929
2047
  });
1930
- console.log(`loadExtension successful`);
1931
2048
  return Promise.resolve();
1932
2049
  } catch (err) {
1933
- console.log(`loadExtension failed `);
1934
2050
  return Promise.reject(err);
1935
2051
  }
1936
2052
  }
1937
2053
  async enableLoadExtension(toggle: boolean): Promise<void> {
1938
2054
  try {
1939
- console.log(`database: ${this.dbName}`);
1940
- console.log(`readonly: ${this.readonly}`);
1941
- console.log(`toggle: ${toggle}`);
1942
2055
  await this.sqlite.enableLoadExtension({
1943
2056
  database: this.dbName,
1944
2057
  toggle: toggle,
1945
2058
  readonly: this.readonly,
1946
2059
  });
1947
- console.log(`enableLoadExtension successful`);
1948
2060
  return Promise.resolve();
1949
2061
  } catch (err) {
1950
- console.log(err);
1951
- console.log(`enableLoadExtension failed `);
1952
2062
  return Promise.reject(err);
1953
2063
  }
1954
2064
  }
@@ -1989,6 +2099,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
1989
2099
  async execute(
1990
2100
  statements: string,
1991
2101
  transaction = true,
2102
+ isSQL92 = true
1992
2103
  ): Promise<capSQLiteChanges> {
1993
2104
  try {
1994
2105
  if (!this.readonly) {
@@ -1997,6 +2108,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
1997
2108
  statements: statements,
1998
2109
  transaction: transaction,
1999
2110
  readonly: false,
2111
+ isSQL92: isSQL92
2000
2112
  });
2001
2113
  return Promise.resolve(res);
2002
2114
  } else {
@@ -2006,7 +2118,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2006
2118
  return Promise.reject(err);
2007
2119
  }
2008
2120
  }
2009
- async query(statement: string, values?: any[]): Promise<DBSQLiteValues> {
2121
+ async query(statement: string, values?: any[], isSQL92 = true): Promise<DBSQLiteValues> {
2010
2122
  let res: any;
2011
2123
  try {
2012
2124
  if (values && values.length > 0) {
@@ -2015,6 +2127,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2015
2127
  statement: statement,
2016
2128
  values: values,
2017
2129
  readonly: this.readonly,
2130
+ isSql92 : true
2018
2131
  });
2019
2132
  } else {
2020
2133
  res = await this.sqlite.query({
@@ -2022,6 +2135,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2022
2135
  statement: statement,
2023
2136
  values: [],
2024
2137
  readonly: this.readonly,
2138
+ isSQL92: isSQL92
2025
2139
  });
2026
2140
  }
2027
2141
 
@@ -2037,6 +2151,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2037
2151
  values?: any[],
2038
2152
  transaction = true,
2039
2153
  returnMode = 'no',
2154
+ isSQL92 = true
2040
2155
  ): Promise<capSQLiteChanges> {
2041
2156
  let res: any;
2042
2157
  try {
@@ -2052,6 +2167,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2052
2167
  transaction: transaction,
2053
2168
  readonly: false,
2054
2169
  returnMode: mRetMode,
2170
+ isSQL92: true
2055
2171
  });
2056
2172
  // }
2057
2173
  } else {
@@ -2065,6 +2181,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2065
2181
  transaction: transaction,
2066
2182
  readonly: false,
2067
2183
  returnMode: mRetMode,
2184
+ isSQL92: isSQL92
2068
2185
  });
2069
2186
  }
2070
2187
  // reorder rows for ios
@@ -2081,6 +2198,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2081
2198
  set: capSQLiteSet[],
2082
2199
  transaction = true,
2083
2200
  returnMode = 'no',
2201
+ isSQL92 = true
2084
2202
  ): Promise<capSQLiteChanges> {
2085
2203
  let res: any;
2086
2204
  try {
@@ -2091,6 +2209,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2091
2209
  transaction: transaction,
2092
2210
  readonly: false,
2093
2211
  returnMode: returnMode,
2212
+ isSQL92: isSQL92
2094
2213
  });
2095
2214
  // }
2096
2215
  // reorder rows for ios
@@ -2226,18 +2345,26 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2226
2345
  }
2227
2346
 
2228
2347
  async executeTransaction(
2229
- txn: { statement: string; values?: any[] }[],
2230
- ): Promise<void> {
2231
- try {
2232
- if (!this.readonly) {
2233
- const ret = await this.sqlite.execute({
2234
- database: this.dbName,
2235
- statements: 'BEGIN TRANSACTION;',
2236
- transaction: false,
2348
+ txn: { statement: string; values?: any[]}[],
2349
+ isSQL92 = true
2350
+ ): Promise<capSQLiteChanges> {
2351
+ let changes = 0;
2352
+ let isActive = false;
2353
+ if (!this.readonly) {
2354
+ try {
2355
+ await this.sqlite.beginTransaction({
2356
+ database: this.dbName
2357
+ });
2358
+ isActive = await this.sqlite.isTransactionActive({
2359
+ database: this.dbName
2237
2360
  });
2238
- if (ret.changes.changes < 0) {
2239
- return Promise.reject('Error in BEGIN TRANSACTION');
2361
+ if(!isActive) {
2362
+ return Promise.reject('After Begin Transaction, no transaction active');
2240
2363
  }
2364
+ } catch (err) {
2365
+ return Promise.reject(err);
2366
+ }
2367
+ try {
2241
2368
  for (const task of txn) {
2242
2369
  if (task.values && task.values.length > 0) {
2243
2370
  const retMode = task.statement.toUpperCase().includes('RETURNING')
@@ -2250,11 +2377,12 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2250
2377
  transaction: false,
2251
2378
  readonly: false,
2252
2379
  returnMode: retMode,
2380
+ isSQL92: isSQL92
2253
2381
  });
2254
- if (ret.changes.lastId === -1) {
2255
- await this.execute('ROLLBACK;', false);
2256
- return Promise.reject('Error in transaction run ');
2382
+ if (ret.changes.changes <= 0) {
2383
+ throw new Error('Error in transaction method run ');
2257
2384
  }
2385
+ changes += ret.changes.changes;
2258
2386
  } else {
2259
2387
  const ret = await this.sqlite.execute({
2260
2388
  database: this.dbName,
@@ -2262,37 +2390,43 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
2262
2390
  transaction: false,
2263
2391
  readonly: false,
2264
2392
  });
2393
+ isActive = await this.sqlite.isTransactionActive({
2394
+ database: this.dbName
2395
+ });
2265
2396
  if (ret.changes.changes < 0) {
2266
- await this.sqlite.execute({
2267
- database: this.dbName,
2268
- statements: 'ROLLBACK;',
2269
- transaction: false,
2270
- readonly: false,
2271
- });
2272
- return Promise.reject('Error in transaction execute ');
2397
+ throw new Error('Error in transaction method execute ');
2273
2398
  }
2399
+ changes += ret.changes.changes;
2274
2400
  }
2275
2401
  }
2276
- await this.sqlite.execute({
2277
- database: this.dbName,
2278
- statements: 'COMMIT;',
2279
- transaction: false,
2280
- readonly: false,
2402
+ isActive = await this.sqlite.isTransactionActive({
2403
+ database: this.dbName
2281
2404
  });
2282
- return Promise.resolve();
2283
- } else {
2284
- return Promise.reject('not allowed in read-only mode');
2405
+ if(isActive) {
2406
+ const retC = await this.sqlite.commitTransaction({
2407
+ database: this.dbName
2408
+ });
2409
+ changes += retC.changes.changes;
2410
+ }
2411
+ const retChanges = {changes:{changes:changes}}
2412
+ return Promise.resolve(retChanges);
2413
+ } catch (err: any) {
2414
+ const msg = err.message ? err.message : err;
2415
+ isActive = await this.sqlite.isTransactionActive({
2416
+ database: this.dbName
2417
+ });
2418
+ if(isActive) {
2419
+ await this.sqlite.rollbackTransaction({
2420
+ database: this.dbName,
2421
+ });
2422
+ }
2423
+ return Promise.reject(msg);
2285
2424
  }
2286
- } catch (err: any) {
2287
- await this.sqlite.execute({
2288
- database: this.dbName,
2289
- statements: 'ROLLBACK;',
2290
- transaction: false,
2291
- readonly: false,
2292
- });
2293
- return Promise.reject(err);
2425
+
2426
+ } else {
2427
+ return Promise.reject('not allowed in read-only mode');
2294
2428
  }
2295
- }
2429
+ }
2296
2430
  private async reorderRows(res: any): Promise<any> {
2297
2431
  const retRes: any = res;
2298
2432
  if (res?.values && typeof res.values[0] === 'object') {
package/src/web.ts CHANGED
@@ -205,6 +205,54 @@ export class CapacitorSQLiteWeb
205
205
  throw new Error(`${err}`);
206
206
  }
207
207
  }
208
+ async beginTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges> {
209
+ this.ensureJeepSqliteIsAvailable();
210
+ this.ensureWebstoreIsOpen();
211
+
212
+ try {
213
+ const changes: capSQLiteChanges =
214
+ await this.jeepSqliteElement.beginTransaction(options);
215
+ return changes;
216
+ } catch (err) {
217
+ throw new Error(`${err}`);
218
+ }
219
+ }
220
+ async commitTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges> {
221
+ this.ensureJeepSqliteIsAvailable();
222
+ this.ensureWebstoreIsOpen();
223
+
224
+ try {
225
+ const changes: capSQLiteChanges =
226
+ await this.jeepSqliteElement.commitTransaction(options);
227
+ return changes;
228
+ } catch (err) {
229
+ throw new Error(`${err}`);
230
+ }
231
+ }
232
+ async rollbackTransaction(options: capSQLiteOptions): Promise<capSQLiteChanges> {
233
+ this.ensureJeepSqliteIsAvailable();
234
+ this.ensureWebstoreIsOpen();
235
+
236
+ try {
237
+ const changes: capSQLiteChanges =
238
+ await this.jeepSqliteElement.rollbackTransaction(options);
239
+ return changes;
240
+ } catch (err) {
241
+ throw new Error(`${err}`);
242
+ }
243
+ }
244
+ async isTransactionActive(options: capSQLiteOptions): Promise<capSQLiteResult> {
245
+ this.ensureJeepSqliteIsAvailable();
246
+ this.ensureWebstoreIsOpen();
247
+
248
+ try {
249
+ const result: capSQLiteResult =
250
+ await this.jeepSqliteElement.isTransactionActive(options);
251
+ return result;
252
+ } catch (err) {
253
+ throw new Error(`${err}`);
254
+ }
255
+ }
208
256
 
209
257
  async getTableList(options: capSQLiteOptions): Promise<capSQLiteValues> {
210
258
  this.ensureJeepSqliteIsAvailable();