@capacitor-community/sqlite 5.0.7-2 → 5.0.8
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 +17 -2
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLite.java +126 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/CapacitorSQLitePlugin.java +115 -1
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/Database.java +142 -80
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/ImportExportJson/ImportFromJson.java +9 -9
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDelete.java +484 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsDrop.java +3 -3
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsSQLStatement.java +169 -0
- package/android/src/main/java/com/getcapacitor/community/database/sqlite/SQLite/UtilsUpgrade.java +4 -4
- package/dist/esm/definitions.d.ts +117 -13
- package/dist/esm/definitions.js +103 -51
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -0
- package/dist/esm/web.js +44 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +147 -51
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +147 -51
- package/dist/plugin.js.map +1 -1
- package/electron/dist/plugin.js +605 -181
- package/electron/dist/plugin.js.map +1 -1
- package/ios/Plugin/CapacitorSQLite.swift +123 -2
- package/ios/Plugin/CapacitorSQLitePlugin.m +4 -0
- package/ios/Plugin/CapacitorSQLitePlugin.swift +131 -1
- package/ios/Plugin/Database.swift +79 -2
- package/ios/Plugin/ImportExportJson/ImportFromJson.swift +13 -2
- package/ios/Plugin/Utils/UtilsDelete.swift +119 -117
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +13 -5
- package/ios/Plugin/Utils/UtilsSQLStatement.swift +84 -84
- package/ios/Plugin/Utils/UtilsUpgrade.swift +3 -0
- package/package.json +5 -2
- package/src/definitions.ts +214 -57
- package/src/web.ts +48 -0
package/src/definitions.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -642,6 +699,15 @@ export interface capSQLiteExportOptions {
|
|
|
642
699
|
* @since 4.1.0-7
|
|
643
700
|
*/
|
|
644
701
|
readonly?: boolean;
|
|
702
|
+
/**
|
|
703
|
+
* Encrypted
|
|
704
|
+
* When your database is encrypted
|
|
705
|
+
* Choose the export Json Object
|
|
706
|
+
* Encrypted (true) / Unencrypted (false)
|
|
707
|
+
* default false
|
|
708
|
+
* @since 5.0.8
|
|
709
|
+
*/
|
|
710
|
+
encrypted?: boolean
|
|
645
711
|
}
|
|
646
712
|
export interface capSQLiteFromAssetsOptions {
|
|
647
713
|
/**
|
|
@@ -1553,8 +1619,8 @@ export class SQLiteConnection implements ISQLiteConnection {
|
|
|
1553
1619
|
async checkConnectionsConsistency(): Promise<capSQLiteResult> {
|
|
1554
1620
|
try {
|
|
1555
1621
|
const keys = [...this._connectionDict.keys()];
|
|
1556
|
-
const openModes = [];
|
|
1557
|
-
const dbNames = [];
|
|
1622
|
+
const openModes: string[] = [];
|
|
1623
|
+
const dbNames: string[] = [];
|
|
1558
1624
|
for (const key of keys) {
|
|
1559
1625
|
openModes.push(key.substring(0, 2));
|
|
1560
1626
|
dbNames.push(key.substring(3));
|
|
@@ -1740,6 +1806,30 @@ export interface ISQLiteDBConnection {
|
|
|
1740
1806
|
* @since 2.9.0 refactor
|
|
1741
1807
|
*/
|
|
1742
1808
|
close(): Promise<void>;
|
|
1809
|
+
/**
|
|
1810
|
+
* Begin Database Transaction
|
|
1811
|
+
* @returns capSQLiteChanges
|
|
1812
|
+
* @since 5.0.7
|
|
1813
|
+
*/
|
|
1814
|
+
beginTransaction(): Promise<capSQLiteChanges>;
|
|
1815
|
+
/**
|
|
1816
|
+
* Commit Database Transaction
|
|
1817
|
+
* @returns capSQLiteChanges
|
|
1818
|
+
* @since 5.0.7
|
|
1819
|
+
*/
|
|
1820
|
+
commitTransaction(): Promise<capSQLiteChanges>;
|
|
1821
|
+
/**
|
|
1822
|
+
* Rollback Database Transaction
|
|
1823
|
+
* @returns capSQLiteChanges
|
|
1824
|
+
* @since 5.0.7
|
|
1825
|
+
*/
|
|
1826
|
+
rollbackTransaction(): Promise<capSQLiteChanges>;
|
|
1827
|
+
/**
|
|
1828
|
+
* Is Database Transaction Active
|
|
1829
|
+
* @returns capSQLiteResult
|
|
1830
|
+
* @since 5.0.7
|
|
1831
|
+
*/
|
|
1832
|
+
isTransactionActive(): Promise<capSQLiteResult>;
|
|
1743
1833
|
/**
|
|
1744
1834
|
* Get Database Url
|
|
1745
1835
|
* @returns Promise<capSQLiteUrl>
|
|
@@ -1769,22 +1859,28 @@ export interface ISQLiteDBConnection {
|
|
|
1769
1859
|
/**
|
|
1770
1860
|
* Execute SQLite DB Connection Statements
|
|
1771
1861
|
* @param statements
|
|
1862
|
+
* @param transaction (optional)
|
|
1863
|
+
* @param isSQL92 (optional)
|
|
1772
1864
|
* @returns Promise<capSQLiteChanges>
|
|
1773
1865
|
* @since 2.9.0 refactor
|
|
1774
1866
|
*/
|
|
1775
|
-
execute(statements: string, transaction?: boolean): Promise<capSQLiteChanges>;
|
|
1867
|
+
execute(statements: string, transaction?: boolean, isSQL92?: boolean): Promise<capSQLiteChanges>;
|
|
1776
1868
|
/**
|
|
1777
1869
|
* Execute SQLite DB Connection Query
|
|
1778
1870
|
* @param statement
|
|
1779
1871
|
* @param values (optional)
|
|
1872
|
+
* @param isSQL92 (optional)
|
|
1780
1873
|
* @returns Promise<Promise<DBSQLiteValues>
|
|
1781
1874
|
* @since 2.9.0 refactor
|
|
1782
1875
|
*/
|
|
1783
|
-
query(statement: string, values?: any[]): Promise<DBSQLiteValues>;
|
|
1876
|
+
query(statement: string, values?: any[], isSQL92?: boolean): Promise<DBSQLiteValues>;
|
|
1784
1877
|
/**
|
|
1785
1878
|
* Execute SQLite DB Connection Raw Statement
|
|
1786
1879
|
* @param statement
|
|
1787
1880
|
* @param values (optional)
|
|
1881
|
+
* @param transaction (optional)
|
|
1882
|
+
* @param returnMode (optional)
|
|
1883
|
+
* @param isSQL92 (optional)
|
|
1788
1884
|
* @returns Promise<capSQLiteChanges>
|
|
1789
1885
|
* @since 2.9.0 refactor
|
|
1790
1886
|
*/
|
|
@@ -1793,10 +1889,14 @@ export interface ISQLiteDBConnection {
|
|
|
1793
1889
|
values?: any[],
|
|
1794
1890
|
transaction?: boolean,
|
|
1795
1891
|
returnMode?: string,
|
|
1892
|
+
isSQL92?: boolean
|
|
1796
1893
|
): Promise<capSQLiteChanges>;
|
|
1797
1894
|
/**
|
|
1798
1895
|
* Execute SQLite DB Connection Set
|
|
1799
1896
|
* @param set
|
|
1897
|
+
* @param transaction (optional)
|
|
1898
|
+
* @param returnMode (optional)
|
|
1899
|
+
* @param isSQL92 (optional)
|
|
1800
1900
|
* @returns Promise<capSQLiteChanges>
|
|
1801
1901
|
* @since 2.9.0 refactor
|
|
1802
1902
|
*/
|
|
@@ -1804,6 +1904,7 @@ export interface ISQLiteDBConnection {
|
|
|
1804
1904
|
set: capSQLiteSet[],
|
|
1805
1905
|
transaction?: boolean,
|
|
1806
1906
|
returnMode?: string,
|
|
1907
|
+
isSQL92?: boolean
|
|
1807
1908
|
): Promise<capSQLiteChanges>;
|
|
1808
1909
|
/**
|
|
1809
1910
|
* Check if a SQLite DB Connection exists
|
|
@@ -1856,10 +1957,11 @@ export interface ISQLiteDBConnection {
|
|
|
1856
1957
|
/**
|
|
1857
1958
|
* Export the given database to a JSON Object
|
|
1858
1959
|
* @param mode
|
|
1960
|
+
* @param encrypted (optional) since 5.0.8 not for Web platform
|
|
1859
1961
|
* @returns Promise<capSQLiteJson>
|
|
1860
1962
|
* @since 2.9.0 refactor
|
|
1861
1963
|
*/
|
|
1862
|
-
exportToJson(mode: string): Promise<capSQLiteJson>;
|
|
1964
|
+
exportToJson(mode: string, encrypted?: boolean): Promise<capSQLiteJson>;
|
|
1863
1965
|
/**
|
|
1864
1966
|
* Remove rows with sql_deleted = 1 after an export
|
|
1865
1967
|
* @returns Promise<void>
|
|
@@ -1870,12 +1972,14 @@ export interface ISQLiteDBConnection {
|
|
|
1870
1972
|
/**
|
|
1871
1973
|
*
|
|
1872
1974
|
* @param txn
|
|
1873
|
-
* @
|
|
1975
|
+
* @param isSQL92
|
|
1976
|
+
* @returns Promise<capSQLiteChanges> since 5.0.7
|
|
1874
1977
|
* @since 3.4.0
|
|
1875
1978
|
*/
|
|
1876
1979
|
executeTransaction(
|
|
1877
1980
|
txn: { statement: string; values?: any[] }[],
|
|
1878
|
-
|
|
1981
|
+
isSQL92: boolean
|
|
1982
|
+
): Promise<capSQLiteChanges>;
|
|
1879
1983
|
}
|
|
1880
1984
|
/**
|
|
1881
1985
|
* SQLiteDBConnection Class
|
|
@@ -1895,6 +1999,9 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
1895
1999
|
}
|
|
1896
2000
|
|
|
1897
2001
|
async open(): Promise<void> {
|
|
2002
|
+
const jeepSQlEL = document.querySelector("jeep-sqlite")
|
|
2003
|
+
console.log(`in definition open jeepSQlEL: `,jeepSQlEL )
|
|
2004
|
+
|
|
1898
2005
|
try {
|
|
1899
2006
|
await this.sqlite.open({
|
|
1900
2007
|
database: this.dbName,
|
|
@@ -1916,39 +2023,64 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
1916
2023
|
return Promise.reject(err);
|
|
1917
2024
|
}
|
|
1918
2025
|
}
|
|
2026
|
+
async beginTransaction(): Promise<capSQLiteChanges> {
|
|
2027
|
+
try {
|
|
2028
|
+
const changes: capSQLiteChanges = await this.sqlite
|
|
2029
|
+
.beginTransaction({database: this.dbName});
|
|
2030
|
+
return Promise.resolve(changes);
|
|
2031
|
+
} catch (err) {
|
|
2032
|
+
return Promise.reject(err);
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
async commitTransaction(): Promise<capSQLiteChanges> {
|
|
2036
|
+
try {
|
|
2037
|
+
const changes: capSQLiteChanges = await this.sqlite
|
|
2038
|
+
.commitTransaction({database: this.dbName});
|
|
2039
|
+
return Promise.resolve(changes);
|
|
2040
|
+
} catch (err) {
|
|
2041
|
+
return Promise.reject(err);
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2044
|
+
async rollbackTransaction(): Promise<capSQLiteChanges> {
|
|
2045
|
+
try {
|
|
2046
|
+
const changes: capSQLiteChanges = await this.sqlite
|
|
2047
|
+
.rollbackTransaction({database: this.dbName});
|
|
2048
|
+
return Promise.resolve(changes);
|
|
2049
|
+
} catch (err) {
|
|
2050
|
+
return Promise.reject(err);
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
async isTransactionActive(): Promise<capSQLiteResult> {
|
|
2054
|
+
try {
|
|
2055
|
+
const result: capSQLiteResult = await this.sqlite
|
|
2056
|
+
.isTransactionActive({database: this.dbName});
|
|
2057
|
+
return Promise.resolve(result);
|
|
2058
|
+
} catch (err) {
|
|
2059
|
+
return Promise.reject(err);
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
1919
2062
|
|
|
1920
2063
|
async loadExtension(path: string): Promise<void> {
|
|
1921
2064
|
try {
|
|
1922
|
-
console.log(`database: ${this.dbName}`);
|
|
1923
|
-
console.log(`readonly: ${this.readonly}}`);
|
|
1924
|
-
console.log(`path: ${path}}`);
|
|
1925
2065
|
await this.sqlite.loadExtension({
|
|
1926
2066
|
database: this.dbName,
|
|
1927
2067
|
path: path,
|
|
1928
2068
|
readonly: this.readonly,
|
|
1929
2069
|
});
|
|
1930
|
-
console.log(`loadExtension successful`);
|
|
1931
2070
|
return Promise.resolve();
|
|
1932
2071
|
} catch (err) {
|
|
1933
|
-
console.log(`loadExtension failed `);
|
|
1934
2072
|
return Promise.reject(err);
|
|
1935
2073
|
}
|
|
1936
2074
|
}
|
|
1937
2075
|
async enableLoadExtension(toggle: boolean): Promise<void> {
|
|
1938
2076
|
try {
|
|
1939
|
-
console.log(`database: ${this.dbName}`);
|
|
1940
|
-
console.log(`readonly: ${this.readonly}`);
|
|
1941
|
-
console.log(`toggle: ${toggle}`);
|
|
1942
2077
|
await this.sqlite.enableLoadExtension({
|
|
1943
2078
|
database: this.dbName,
|
|
1944
2079
|
toggle: toggle,
|
|
1945
2080
|
readonly: this.readonly,
|
|
1946
2081
|
});
|
|
1947
|
-
console.log(`enableLoadExtension successful`);
|
|
1948
2082
|
return Promise.resolve();
|
|
1949
2083
|
} catch (err) {
|
|
1950
|
-
console.log(err);
|
|
1951
|
-
console.log(`enableLoadExtension failed `);
|
|
1952
2084
|
return Promise.reject(err);
|
|
1953
2085
|
}
|
|
1954
2086
|
}
|
|
@@ -1989,6 +2121,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
1989
2121
|
async execute(
|
|
1990
2122
|
statements: string,
|
|
1991
2123
|
transaction = true,
|
|
2124
|
+
isSQL92 = true
|
|
1992
2125
|
): Promise<capSQLiteChanges> {
|
|
1993
2126
|
try {
|
|
1994
2127
|
if (!this.readonly) {
|
|
@@ -1997,6 +2130,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
1997
2130
|
statements: statements,
|
|
1998
2131
|
transaction: transaction,
|
|
1999
2132
|
readonly: false,
|
|
2133
|
+
isSQL92: isSQL92
|
|
2000
2134
|
});
|
|
2001
2135
|
return Promise.resolve(res);
|
|
2002
2136
|
} else {
|
|
@@ -2006,7 +2140,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2006
2140
|
return Promise.reject(err);
|
|
2007
2141
|
}
|
|
2008
2142
|
}
|
|
2009
|
-
async query(statement: string, values?: any[]): Promise<DBSQLiteValues> {
|
|
2143
|
+
async query(statement: string, values?: any[], isSQL92 = true): Promise<DBSQLiteValues> {
|
|
2010
2144
|
let res: any;
|
|
2011
2145
|
try {
|
|
2012
2146
|
if (values && values.length > 0) {
|
|
@@ -2015,6 +2149,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2015
2149
|
statement: statement,
|
|
2016
2150
|
values: values,
|
|
2017
2151
|
readonly: this.readonly,
|
|
2152
|
+
isSql92 : true
|
|
2018
2153
|
});
|
|
2019
2154
|
} else {
|
|
2020
2155
|
res = await this.sqlite.query({
|
|
@@ -2022,6 +2157,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2022
2157
|
statement: statement,
|
|
2023
2158
|
values: [],
|
|
2024
2159
|
readonly: this.readonly,
|
|
2160
|
+
isSQL92: isSQL92
|
|
2025
2161
|
});
|
|
2026
2162
|
}
|
|
2027
2163
|
|
|
@@ -2037,6 +2173,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2037
2173
|
values?: any[],
|
|
2038
2174
|
transaction = true,
|
|
2039
2175
|
returnMode = 'no',
|
|
2176
|
+
isSQL92 = true
|
|
2040
2177
|
): Promise<capSQLiteChanges> {
|
|
2041
2178
|
let res: any;
|
|
2042
2179
|
try {
|
|
@@ -2052,6 +2189,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2052
2189
|
transaction: transaction,
|
|
2053
2190
|
readonly: false,
|
|
2054
2191
|
returnMode: mRetMode,
|
|
2192
|
+
isSQL92: true
|
|
2055
2193
|
});
|
|
2056
2194
|
// }
|
|
2057
2195
|
} else {
|
|
@@ -2065,6 +2203,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2065
2203
|
transaction: transaction,
|
|
2066
2204
|
readonly: false,
|
|
2067
2205
|
returnMode: mRetMode,
|
|
2206
|
+
isSQL92: isSQL92
|
|
2068
2207
|
});
|
|
2069
2208
|
}
|
|
2070
2209
|
// reorder rows for ios
|
|
@@ -2081,6 +2220,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2081
2220
|
set: capSQLiteSet[],
|
|
2082
2221
|
transaction = true,
|
|
2083
2222
|
returnMode = 'no',
|
|
2223
|
+
isSQL92 = true
|
|
2084
2224
|
): Promise<capSQLiteChanges> {
|
|
2085
2225
|
let res: any;
|
|
2086
2226
|
try {
|
|
@@ -2091,6 +2231,7 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2091
2231
|
transaction: transaction,
|
|
2092
2232
|
readonly: false,
|
|
2093
2233
|
returnMode: returnMode,
|
|
2234
|
+
isSQL92: isSQL92
|
|
2094
2235
|
});
|
|
2095
2236
|
// }
|
|
2096
2237
|
// reorder rows for ios
|
|
@@ -2197,12 +2338,13 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2197
2338
|
return Promise.reject(err);
|
|
2198
2339
|
}
|
|
2199
2340
|
}
|
|
2200
|
-
async exportToJson(mode: string): Promise<capSQLiteJson> {
|
|
2341
|
+
async exportToJson(mode: string, encrypted = false): Promise<capSQLiteJson> {
|
|
2201
2342
|
try {
|
|
2202
2343
|
const res: any = await this.sqlite.exportToJson({
|
|
2203
2344
|
database: this.dbName,
|
|
2204
2345
|
jsonexportmode: mode,
|
|
2205
2346
|
readonly: this.readonly,
|
|
2347
|
+
encrypted: encrypted,
|
|
2206
2348
|
});
|
|
2207
2349
|
return Promise.resolve(res);
|
|
2208
2350
|
} catch (err) {
|
|
@@ -2226,18 +2368,26 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2226
2368
|
}
|
|
2227
2369
|
|
|
2228
2370
|
async executeTransaction(
|
|
2229
|
-
txn: { statement: string; values?: any[]
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2371
|
+
txn: { statement: string; values?: any[]}[],
|
|
2372
|
+
isSQL92 = true
|
|
2373
|
+
): Promise<capSQLiteChanges> {
|
|
2374
|
+
let changes = 0;
|
|
2375
|
+
let isActive = false;
|
|
2376
|
+
if (!this.readonly) {
|
|
2377
|
+
try {
|
|
2378
|
+
await this.sqlite.beginTransaction({
|
|
2379
|
+
database: this.dbName
|
|
2237
2380
|
});
|
|
2238
|
-
|
|
2239
|
-
|
|
2381
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
2382
|
+
database: this.dbName
|
|
2383
|
+
});
|
|
2384
|
+
if(!isActive) {
|
|
2385
|
+
return Promise.reject('After Begin Transaction, no transaction active');
|
|
2240
2386
|
}
|
|
2387
|
+
} catch (err) {
|
|
2388
|
+
return Promise.reject(err);
|
|
2389
|
+
}
|
|
2390
|
+
try {
|
|
2241
2391
|
for (const task of txn) {
|
|
2242
2392
|
if (task.values && task.values.length > 0) {
|
|
2243
2393
|
const retMode = task.statement.toUpperCase().includes('RETURNING')
|
|
@@ -2250,11 +2400,12 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2250
2400
|
transaction: false,
|
|
2251
2401
|
readonly: false,
|
|
2252
2402
|
returnMode: retMode,
|
|
2403
|
+
isSQL92: isSQL92
|
|
2253
2404
|
});
|
|
2254
|
-
if (ret.changes.
|
|
2255
|
-
|
|
2256
|
-
return Promise.reject('Error in transaction run ');
|
|
2405
|
+
if (ret.changes.changes <= 0) {
|
|
2406
|
+
throw new Error('Error in transaction method run ');
|
|
2257
2407
|
}
|
|
2408
|
+
changes += ret.changes.changes;
|
|
2258
2409
|
} else {
|
|
2259
2410
|
const ret = await this.sqlite.execute({
|
|
2260
2411
|
database: this.dbName,
|
|
@@ -2262,37 +2413,43 @@ export class SQLiteDBConnection implements ISQLiteDBConnection {
|
|
|
2262
2413
|
transaction: false,
|
|
2263
2414
|
readonly: false,
|
|
2264
2415
|
});
|
|
2416
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
2417
|
+
database: this.dbName
|
|
2418
|
+
});
|
|
2265
2419
|
if (ret.changes.changes < 0) {
|
|
2266
|
-
|
|
2267
|
-
database: this.dbName,
|
|
2268
|
-
statements: 'ROLLBACK;',
|
|
2269
|
-
transaction: false,
|
|
2270
|
-
readonly: false,
|
|
2271
|
-
});
|
|
2272
|
-
return Promise.reject('Error in transaction execute ');
|
|
2420
|
+
throw new Error('Error in transaction method execute ');
|
|
2273
2421
|
}
|
|
2422
|
+
changes += ret.changes.changes;
|
|
2274
2423
|
}
|
|
2275
2424
|
}
|
|
2276
|
-
await this.sqlite.
|
|
2277
|
-
database: this.dbName
|
|
2278
|
-
statements: 'COMMIT;',
|
|
2279
|
-
transaction: false,
|
|
2280
|
-
readonly: false,
|
|
2425
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
2426
|
+
database: this.dbName
|
|
2281
2427
|
});
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2428
|
+
if(isActive) {
|
|
2429
|
+
const retC = await this.sqlite.commitTransaction({
|
|
2430
|
+
database: this.dbName
|
|
2431
|
+
});
|
|
2432
|
+
changes += retC.changes.changes;
|
|
2433
|
+
}
|
|
2434
|
+
const retChanges = {changes:{changes:changes}}
|
|
2435
|
+
return Promise.resolve(retChanges);
|
|
2436
|
+
} catch (err: any) {
|
|
2437
|
+
const msg = err.message ? err.message : err;
|
|
2438
|
+
isActive = await this.sqlite.isTransactionActive({
|
|
2439
|
+
database: this.dbName
|
|
2440
|
+
});
|
|
2441
|
+
if(isActive) {
|
|
2442
|
+
await this.sqlite.rollbackTransaction({
|
|
2443
|
+
database: this.dbName,
|
|
2444
|
+
});
|
|
2445
|
+
}
|
|
2446
|
+
return Promise.reject(msg);
|
|
2285
2447
|
}
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
statements: 'ROLLBACK;',
|
|
2290
|
-
transaction: false,
|
|
2291
|
-
readonly: false,
|
|
2292
|
-
});
|
|
2293
|
-
return Promise.reject(err);
|
|
2448
|
+
|
|
2449
|
+
} else {
|
|
2450
|
+
return Promise.reject('not allowed in read-only mode');
|
|
2294
2451
|
}
|
|
2295
|
-
|
|
2452
|
+
}
|
|
2296
2453
|
private async reorderRows(res: any): Promise<any> {
|
|
2297
2454
|
const retRes: any = res;
|
|
2298
2455
|
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();
|