@capgo/capacitor-data-storage-sqlite 6.0.0
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/CapacitorDataStorageSqlite.podspec +18 -0
- package/LICENSE +21 -0
- package/android/build.gradle +63 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlite.java +387 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/CapacitorDataStorageSqlitePlugin.java +447 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/RetHandler.java +117 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Data.java +8 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/Global.java +7 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonStore.java +131 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonTable.java +110 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonValue.java +89 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/StorageDatabaseHelper.java +691 -0
- package/android/src/main/java/com/jeep/plugin/capacitor/capacitordatastoragesqlite/cdssUtils/UtilsSQLCipher.java +162 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +995 -0
- package/dist/esm/definitions.d.ts +296 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web-utils/Data.d.ts +5 -0
- package/dist/esm/web-utils/Data.js +3 -0
- package/dist/esm/web-utils/Data.js.map +1 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.d.ts +23 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js +247 -0
- package/dist/esm/web-utils/StorageDatabaseHelper.js.map +1 -0
- package/dist/esm/web-utils/json-utils.d.ts +15 -0
- package/dist/esm/web-utils/json-utils.js +76 -0
- package/dist/esm/web-utils/json-utils.js.map +1 -0
- package/dist/esm/web.d.ts +27 -0
- package/dist/esm/web.js +295 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +633 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +635 -0
- package/dist/plugin.js.map +1 -0
- package/electron/dist/plugin.js +1044 -0
- package/electron/dist/plugin.js.map +1 -0
- package/electron/rollup.config.mjs +17 -0
- package/electron/tsconfig.json +19 -0
- package/ios/Plugin/CapacitorDataStorageSqlite.swift +550 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.h +10 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.m +29 -0
- package/ios/Plugin/CapacitorDataStorageSqlitePlugin.swift +550 -0
- package/ios/Plugin/Data.swift +16 -0
- package/ios/Plugin/Global.swift +13 -0
- package/ios/Plugin/ImportExportJson/JsonStore.swift +47 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/ReturnHandler.swift +85 -0
- package/ios/Plugin/StorageDatabaseHelper.swift +603 -0
- package/ios/Plugin/Utils/Blob.swift +41 -0
- package/ios/Plugin/Utils/UtilsBinding.swift +73 -0
- package/ios/Plugin/Utils/UtilsEncryption.swift +79 -0
- package/ios/Plugin/Utils/UtilsFile.swift +244 -0
- package/ios/Plugin/Utils/UtilsSQLCipher.swift +605 -0
- package/package.json +96 -0
- package/readme.md +203 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'CapacitorDataStorageSqlite'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '13.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.dependency 'SQLite.swift/SQLCipher'
|
|
17
|
+
s.swift_version = '5.1'
|
|
18
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Capacitor Data Storage Sqlite
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.6.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.5'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.5.1'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.2.1'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.jeep.plugin.capacitor.capacitordatastoragesqlite"
|
|
22
|
+
compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 34
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 34
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
mavenCentral()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
dependencies {
|
|
53
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
54
|
+
implementation project(':capacitor-android')
|
|
55
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
56
|
+
testImplementation "junit:junit:$junitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
58
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
59
|
+
implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0"
|
|
60
|
+
implementation 'net.zetetic:android-database-sqlcipher:4.4.3@aar'
|
|
61
|
+
implementation "androidx.sqlite:sqlite:2.1.0"
|
|
62
|
+
|
|
63
|
+
}
|
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
package com.jeep.plugin.capacitor.capacitordatastoragesqlite;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import com.jeep.plugin.capacitor.capacitordatastoragesqlite.cdssUtils.Data;
|
|
6
|
+
import com.jeep.plugin.capacitor.capacitordatastoragesqlite.cdssUtils.ImportExportJson.JsonStore;
|
|
7
|
+
import com.jeep.plugin.capacitor.capacitordatastoragesqlite.cdssUtils.ImportExportJson.JsonTable;
|
|
8
|
+
import com.jeep.plugin.capacitor.capacitordatastoragesqlite.cdssUtils.StorageDatabaseHelper;
|
|
9
|
+
import java.io.File;
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.List;
|
|
12
|
+
|
|
13
|
+
public class CapacitorDataStorageSqlite {
|
|
14
|
+
|
|
15
|
+
private StorageDatabaseHelper mDb;
|
|
16
|
+
private Context context;
|
|
17
|
+
|
|
18
|
+
public CapacitorDataStorageSqlite(Context context) {
|
|
19
|
+
this.context = context;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Echo
|
|
24
|
+
*
|
|
25
|
+
* @param value
|
|
26
|
+
* @return String
|
|
27
|
+
*/
|
|
28
|
+
public String echo(String value) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public void openStore(
|
|
33
|
+
String dbName,
|
|
34
|
+
String tableName,
|
|
35
|
+
Boolean encrypted,
|
|
36
|
+
String inMode,
|
|
37
|
+
int version
|
|
38
|
+
) throws Exception {
|
|
39
|
+
try {
|
|
40
|
+
mDb = new StorageDatabaseHelper(
|
|
41
|
+
context,
|
|
42
|
+
dbName + "SQLite.db",
|
|
43
|
+
tableName,
|
|
44
|
+
encrypted,
|
|
45
|
+
inMode,
|
|
46
|
+
version
|
|
47
|
+
);
|
|
48
|
+
if (mDb != null) {
|
|
49
|
+
mDb.open();
|
|
50
|
+
if (mDb.isOpen) {
|
|
51
|
+
return;
|
|
52
|
+
} else {
|
|
53
|
+
throw new Exception("mDb is not opened");
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
throw new Exception("mDb is null");
|
|
57
|
+
}
|
|
58
|
+
} catch (Exception e) {
|
|
59
|
+
throw new Exception(e.getMessage());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public void closeStore(String dbName) throws Exception {
|
|
64
|
+
String database = dbName + "SQLite.db";
|
|
65
|
+
if (mDb != null && mDb.isOpen && mDb.getStoreName().equals(database)) {
|
|
66
|
+
try {
|
|
67
|
+
mDb.close();
|
|
68
|
+
return;
|
|
69
|
+
} catch (Exception e) {
|
|
70
|
+
throw new Exception(e.getMessage());
|
|
71
|
+
}
|
|
72
|
+
} else {
|
|
73
|
+
throw new Exception("mDb " + dbName + " is not opened or null");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public boolean isStoreOpen(String dbName) throws Exception {
|
|
78
|
+
String database = dbName + "SQLite.db";
|
|
79
|
+
if (mDb != null && mDb.getStoreName().equals(database)) {
|
|
80
|
+
return mDb.isOpen;
|
|
81
|
+
} else {
|
|
82
|
+
throw new Exception("mDb " + dbName + " is not the current one or null");
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
public void set(String key, String value) throws Exception {
|
|
87
|
+
if (mDb != null && mDb.isOpen) {
|
|
88
|
+
try {
|
|
89
|
+
Data data = new Data();
|
|
90
|
+
data.name = key;
|
|
91
|
+
data.value = value;
|
|
92
|
+
mDb.set(data);
|
|
93
|
+
return;
|
|
94
|
+
} catch (Exception e) {
|
|
95
|
+
throw new Exception(e.getMessage());
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
throw new Exception("mDb is not opened or null");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public String get(String key) throws Exception {
|
|
103
|
+
if (mDb != null && mDb.isOpen) {
|
|
104
|
+
try {
|
|
105
|
+
Data data = mDb.get(key);
|
|
106
|
+
if (data.id == null) {
|
|
107
|
+
return "";
|
|
108
|
+
} else {
|
|
109
|
+
return data.value;
|
|
110
|
+
}
|
|
111
|
+
} catch (Exception e) {
|
|
112
|
+
throw new Exception(e.getMessage());
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
throw new Exception("mDb is not opened or null");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
public void remove(String name) throws Exception {
|
|
120
|
+
if (mDb != null && mDb.isOpen) {
|
|
121
|
+
try {
|
|
122
|
+
mDb.remove(name);
|
|
123
|
+
return;
|
|
124
|
+
} catch (Exception e) {
|
|
125
|
+
throw new Exception(e.getMessage());
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
throw new Exception("mDb is not opened or null");
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public void clear() throws Exception {
|
|
133
|
+
if (mDb != null && mDb.isOpen) {
|
|
134
|
+
try {
|
|
135
|
+
mDb.clear();
|
|
136
|
+
return;
|
|
137
|
+
} catch (Exception e) {
|
|
138
|
+
throw new Exception(e.getMessage());
|
|
139
|
+
}
|
|
140
|
+
} else {
|
|
141
|
+
throw new Exception("mDb is not opened or null");
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
public boolean iskey(String name) throws Exception {
|
|
146
|
+
boolean ret = false;
|
|
147
|
+
if (mDb != null && mDb.isOpen) {
|
|
148
|
+
try {
|
|
149
|
+
ret = mDb.iskey(name);
|
|
150
|
+
return ret;
|
|
151
|
+
} catch (Exception e) {
|
|
152
|
+
throw new Exception(e.getMessage());
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
throw new Exception("mDb is not opened or null");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
public String[] keys() throws Exception {
|
|
160
|
+
if (mDb != null && mDb.isOpen) {
|
|
161
|
+
try {
|
|
162
|
+
List<String> resKeys = mDb.keys();
|
|
163
|
+
String[] keyArray = resKeys.toArray(new String[resKeys.size()]);
|
|
164
|
+
return keyArray;
|
|
165
|
+
} catch (Exception e) {
|
|
166
|
+
throw new Exception(e.getMessage());
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
throw new Exception("mDb is not opened or null");
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
public String[] values() throws Exception {
|
|
174
|
+
if (mDb != null && mDb.isOpen) {
|
|
175
|
+
try {
|
|
176
|
+
List<String> resValues = mDb.values();
|
|
177
|
+
String[] valueArray = resValues.toArray(new String[resValues.size()]);
|
|
178
|
+
return valueArray;
|
|
179
|
+
} catch (Exception e) {
|
|
180
|
+
throw new Exception(e.getMessage());
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
throw new Exception("mDb is not opened or null");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public String[] filtervalues(String filter) throws Exception {
|
|
188
|
+
if (mDb != null && mDb.isOpen) {
|
|
189
|
+
try {
|
|
190
|
+
List<String> resValues = mDb.filtervalues(filter);
|
|
191
|
+
String[] valueArray = resValues.toArray(new String[resValues.size()]);
|
|
192
|
+
return valueArray;
|
|
193
|
+
} catch (Exception e) {
|
|
194
|
+
throw new Exception(e.getMessage());
|
|
195
|
+
}
|
|
196
|
+
} else {
|
|
197
|
+
throw new Exception("mDb is not opened or null");
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
public JSObject[] keysvalues() throws Exception {
|
|
202
|
+
if (mDb != null && mDb.isOpen) {
|
|
203
|
+
try {
|
|
204
|
+
List<Data> resKeysValues = mDb.keysvalues();
|
|
205
|
+
JSObject[] jsObjArray = new JSObject[resKeysValues.size()];
|
|
206
|
+
|
|
207
|
+
for (int i = 0; i < resKeysValues.size(); i++) {
|
|
208
|
+
JSObject res = new JSObject();
|
|
209
|
+
res.put("key", resKeysValues.get(i).name);
|
|
210
|
+
res.put("value", resKeysValues.get(i).value);
|
|
211
|
+
jsObjArray[i] = res;
|
|
212
|
+
}
|
|
213
|
+
return jsObjArray;
|
|
214
|
+
} catch (Exception e) {
|
|
215
|
+
throw new Exception(e.getMessage());
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
throw new Exception("mDb is not opened or null");
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
public void setTable(String table) throws Exception {
|
|
223
|
+
if (mDb != null && mDb.isOpen) {
|
|
224
|
+
try {
|
|
225
|
+
mDb.setTable(table, true);
|
|
226
|
+
return;
|
|
227
|
+
} catch (Exception e) {
|
|
228
|
+
throw new Exception(e.getMessage());
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
throw new Exception("mDb is not opened or null");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
public boolean isTable(String table) throws Exception {
|
|
236
|
+
boolean ret = false;
|
|
237
|
+
if (mDb != null && mDb.isOpen) {
|
|
238
|
+
try {
|
|
239
|
+
ret = mDb.isTable(table);
|
|
240
|
+
return ret;
|
|
241
|
+
} catch (Exception e) {
|
|
242
|
+
throw new Exception(e.getMessage());
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
throw new Exception("mDb is not opened or null");
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
public String[] tables() throws Exception {
|
|
250
|
+
if (mDb != null && mDb.isOpen) {
|
|
251
|
+
try {
|
|
252
|
+
List<String> resTables = mDb.tables();
|
|
253
|
+
String[] tableArray = resTables.toArray(new String[resTables.size()]);
|
|
254
|
+
return tableArray;
|
|
255
|
+
} catch (Exception e) {
|
|
256
|
+
throw new Exception(e.getMessage());
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
throw new Exception("mDb is not opened or null");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
public void deleteTable(String table) throws Exception {
|
|
264
|
+
if (mDb != null && mDb.isOpen) {
|
|
265
|
+
try {
|
|
266
|
+
mDb.deleteTable(table);
|
|
267
|
+
return;
|
|
268
|
+
} catch (Exception e) {
|
|
269
|
+
throw new Exception(e.getMessage());
|
|
270
|
+
}
|
|
271
|
+
} else {
|
|
272
|
+
throw new Exception("mDb is not opened or null");
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
public void deleteStore(String dbName) throws Exception {
|
|
277
|
+
try {
|
|
278
|
+
context.deleteDatabase(dbName + "SQLite.db");
|
|
279
|
+
context.deleteFile(dbName + "SQLite.db");
|
|
280
|
+
File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
|
|
281
|
+
if (databaseFile.exists()) {
|
|
282
|
+
throw new Exception("failed to delete the store");
|
|
283
|
+
} else {
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
} catch (Exception e) {
|
|
287
|
+
throw new Exception(e.getMessage());
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
public boolean isStoreExists(String dbName) throws Exception {
|
|
292
|
+
boolean ret = false;
|
|
293
|
+
try {
|
|
294
|
+
File databaseFile = context.getDatabasePath(dbName + "SQLite.db");
|
|
295
|
+
if (databaseFile.exists()) ret = true;
|
|
296
|
+
return ret;
|
|
297
|
+
} catch (Exception e) {
|
|
298
|
+
throw new Exception(e.getMessage());
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
public Boolean isJsonValid(String parsingData) throws Exception {
|
|
303
|
+
try {
|
|
304
|
+
JSObject jsonObject = new JSObject(parsingData);
|
|
305
|
+
JsonStore jsonSQL = new JsonStore();
|
|
306
|
+
Boolean isValid = jsonSQL.isJsonStore(jsonObject);
|
|
307
|
+
return isValid;
|
|
308
|
+
} catch (Exception e) {
|
|
309
|
+
throw new Exception(e.getMessage());
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public JSObject importFromJson(String parsingData) throws Exception {
|
|
314
|
+
try {
|
|
315
|
+
JSObject retObj = new JSObject();
|
|
316
|
+
JSObject jsonObject = new JSObject(parsingData);
|
|
317
|
+
JsonStore jsonSQL = new JsonStore();
|
|
318
|
+
Boolean isValid = jsonSQL.isJsonStore(jsonObject);
|
|
319
|
+
if (!isValid) {
|
|
320
|
+
String msg = "Stringify Json Object not Valid";
|
|
321
|
+
throw new Exception(msg);
|
|
322
|
+
}
|
|
323
|
+
int totalChanges = 0;
|
|
324
|
+
String dbName = jsonSQL.getDatabase();
|
|
325
|
+
Boolean encrypted = jsonSQL.getEncrypted();
|
|
326
|
+
String inMode = "";
|
|
327
|
+
if (encrypted) {
|
|
328
|
+
inMode = "secret";
|
|
329
|
+
}
|
|
330
|
+
ArrayList<JsonTable> tables = jsonSQL.getTables();
|
|
331
|
+
for (JsonTable table : tables) {
|
|
332
|
+
// open the database
|
|
333
|
+
mDb = new StorageDatabaseHelper(
|
|
334
|
+
context,
|
|
335
|
+
dbName + "SQLite.db",
|
|
336
|
+
table.getName(),
|
|
337
|
+
encrypted,
|
|
338
|
+
inMode,
|
|
339
|
+
1
|
|
340
|
+
);
|
|
341
|
+
if (mDb != null) {
|
|
342
|
+
mDb.open();
|
|
343
|
+
if (mDb.isOpen) {
|
|
344
|
+
int changes = mDb.importFromJson(table.getValues());
|
|
345
|
+
mDb.close();
|
|
346
|
+
if (changes < 1) {
|
|
347
|
+
throw new Exception("changes < 1");
|
|
348
|
+
} else {
|
|
349
|
+
totalChanges += changes;
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
throw new Exception("mDb is not opened");
|
|
353
|
+
}
|
|
354
|
+
} else {
|
|
355
|
+
throw new Exception("mDb is null");
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
retObj.put("changes", totalChanges);
|
|
359
|
+
return retObj;
|
|
360
|
+
} catch (Exception e) {
|
|
361
|
+
String msg = "importFromJson : " + e.getMessage();
|
|
362
|
+
throw new Exception(msg);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
public JSObject exportToJson() throws Exception {
|
|
367
|
+
if (mDb != null && mDb.isOpen) {
|
|
368
|
+
try {
|
|
369
|
+
JSObject ret = mDb.exportToJson();
|
|
370
|
+
JsonStore jsonSQL = new JsonStore();
|
|
371
|
+
Boolean isValid = jsonSQL.isJsonStore(ret);
|
|
372
|
+
if (isValid) {
|
|
373
|
+
return ret;
|
|
374
|
+
} else {
|
|
375
|
+
String msg = "ExportToJson: return Obj is not a JsonStore Obj";
|
|
376
|
+
throw new Exception(msg);
|
|
377
|
+
}
|
|
378
|
+
} catch (Exception e) {
|
|
379
|
+
String msg = "ExportToJson " + e.getMessage();
|
|
380
|
+
throw new Exception(msg);
|
|
381
|
+
}
|
|
382
|
+
} else {
|
|
383
|
+
String msg = "mDb is not opened or null ";
|
|
384
|
+
throw new Exception(msg);
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|