@capgo/capacitor-data-storage-sqlite 6.0.59 → 7.1.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/CapgoCapacitorDataStorageSqlite.podspec +2 -2
- package/Package.swift +30 -0
- package/README.md +724 -0
- package/android/build.gradle +11 -11
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/CapgoCapacitorDataStorageSqlite.java +290 -320
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/CapgoCapacitorDataStorageSqlitePlugin.java +373 -388
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/RetHandler.java +97 -97
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/Data.java +3 -3
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/Global.java +2 -2
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonStore.java +108 -110
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonTable.java +78 -80
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/ImportExportJson/JsonValue.java +62 -64
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/StorageDatabaseHelper.java +557 -624
- package/android/src/main/java/com/jeep/plugin/capacitor/capgocapacitordatastoragesqlite/cdssUtils/UtilsSQLCipher.java +103 -144
- package/dist/docs.json +0 -64
- package/dist/esm/definitions.d.ts +0 -19
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +5 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/web-utils/StorageDatabaseHelper.d.ts +2 -2
- package/dist/esm/web-utils/StorageDatabaseHelper.js +8 -8
- package/dist/esm/web-utils/StorageDatabaseHelper.js.map +1 -1
- package/dist/esm/web-utils/json-utils.js +15 -18
- package/dist/esm/web-utils/json-utils.js.map +1 -1
- package/dist/esm/web.d.ts +2 -3
- package/dist/esm/web.js +37 -44
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +56 -67
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +56 -67
- package/dist/plugin.js.map +1 -1
- package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/CapgoCapacitorDataStorageSqlitePlugin.swift +27 -10
- package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/StorageDatabaseHelper.swift +1 -1
- package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsFile.swift +1 -1
- package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsSQLCipher.swift +3 -3
- package/ios/Tests/CapgoCapacitorDataStorageSqlitePluginTests/CapacitorDataStorageSqlitePluginTests.swift +13 -0
- package/package.json +34 -38
- package/electron/dist/plugin.js +0 -1044
- package/electron/dist/plugin.js.map +0 -1
- package/ios/Plugin/CapgoCapacitorDataStorageSqlitePlugin.h +0 -10
- package/ios/Plugin/CapgoCapacitorDataStorageSqlitePlugin.m +0 -29
- package/ios/Plugin/Info.plist +0 -24
- package/readme.md +0 -210
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/CapgoCapacitorDataStorageSqlite.swift +0 -0
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Data.swift +0 -0
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Global.swift +0 -0
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/ImportExportJson/JsonStore.swift +0 -0
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/ReturnHandler.swift +0 -0
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/Blob.swift +0 -0
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsBinding.swift +0 -0
- /package/ios/{Plugin → Sources/CapgoCapacitorDataStorageSqlitePlugin}/Utils/UtilsEncryption.swift +0 -0
|
@@ -18,674 +18,607 @@ import net.sqlcipher.database.SQLiteDatabase;
|
|
|
18
18
|
|
|
19
19
|
public class StorageDatabaseHelper {
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this._uCipher = new UtilsSQLCipher();
|
|
59
|
-
|
|
60
|
-
this.InitializeSQLCipher();
|
|
61
|
-
if (!this._file.getParentFile().exists()) {
|
|
62
|
-
this._file.getParentFile().mkdirs();
|
|
21
|
+
public Boolean isOpen = false;
|
|
22
|
+
private static final String TAG = "StorageDatabaseHelper";
|
|
23
|
+
private Context _context;
|
|
24
|
+
private String _tableName;
|
|
25
|
+
private String _dbName;
|
|
26
|
+
private Boolean _encrypted;
|
|
27
|
+
private String _mode;
|
|
28
|
+
private String _secret;
|
|
29
|
+
private String _newsecret;
|
|
30
|
+
private int _dbVersion;
|
|
31
|
+
private File _file;
|
|
32
|
+
private Global _globVar;
|
|
33
|
+
private UtilsSQLCipher _uCipher;
|
|
34
|
+
private SupportSQLiteDatabase _db = null;
|
|
35
|
+
|
|
36
|
+
// Storage Table Columns
|
|
37
|
+
private static final String COL_ID = "id";
|
|
38
|
+
private static final String COL_NAME = "name";
|
|
39
|
+
private static final String COL_VALUE = "value";
|
|
40
|
+
private static final String IDX_COL_NAME = "name";
|
|
41
|
+
|
|
42
|
+
public StorageDatabaseHelper(Context context, String dbName, String tableName, Boolean encrypted, String mode, int vNumber) {
|
|
43
|
+
this._context = context;
|
|
44
|
+
this._dbName = dbName;
|
|
45
|
+
this._tableName = tableName;
|
|
46
|
+
this._dbVersion = vNumber;
|
|
47
|
+
this._encrypted = encrypted;
|
|
48
|
+
this._mode = mode;
|
|
49
|
+
this._file = context.getDatabasePath(dbName);
|
|
50
|
+
this._globVar = new Global();
|
|
51
|
+
this._uCipher = new UtilsSQLCipher();
|
|
52
|
+
|
|
53
|
+
this.InitializeSQLCipher();
|
|
54
|
+
if (!this._file.getParentFile().exists()) {
|
|
55
|
+
this._file.getParentFile().mkdirs();
|
|
56
|
+
}
|
|
57
|
+
Log.v(TAG, "&&& file path " + this._file.getAbsolutePath());
|
|
63
58
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Log.d(TAG, " in InitializeSQLCipher: ");
|
|
73
|
-
SQLiteDatabase.loadLibs(_context);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* GetStoreName
|
|
78
|
-
* Return the current store name
|
|
79
|
-
* @return
|
|
80
|
-
*/
|
|
81
|
-
public String getStoreName() {
|
|
82
|
-
return this._dbName;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Open Method
|
|
87
|
-
* Open the store
|
|
88
|
-
*/
|
|
89
|
-
public void open() throws Exception {
|
|
90
|
-
int curVersion;
|
|
91
|
-
|
|
92
|
-
String password = _encrypted &&
|
|
93
|
-
(_mode.equals("secret") || _mode.equals("encryption"))
|
|
94
|
-
? _globVar.secret
|
|
95
|
-
: "";
|
|
96
|
-
if (_mode.equals("newsecret")) {
|
|
97
|
-
try {
|
|
98
|
-
_uCipher.changePassword(
|
|
99
|
-
_context,
|
|
100
|
-
_file,
|
|
101
|
-
_globVar.secret,
|
|
102
|
-
_globVar.newsecret
|
|
103
|
-
);
|
|
104
|
-
password = _globVar.newsecret;
|
|
105
|
-
} catch (Exception e) {
|
|
106
|
-
String msg = "Failed in change password" + e.getMessage();
|
|
107
|
-
Log.v(TAG, msg);
|
|
108
|
-
throw new Exception(msg);
|
|
109
|
-
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* InitializeSQLCipher Method
|
|
62
|
+
* Initialize the SQLCipher Libraries
|
|
63
|
+
*/
|
|
64
|
+
private void InitializeSQLCipher() {
|
|
65
|
+
Log.d(TAG, " in InitializeSQLCipher: ");
|
|
66
|
+
SQLiteDatabase.loadLibs(_context);
|
|
110
67
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
String msg = "Failed in encryption " + e.getMessage();
|
|
120
|
-
Log.v(TAG, msg);
|
|
121
|
-
throw new Exception(msg);
|
|
122
|
-
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* GetStoreName
|
|
71
|
+
* Return the current store name
|
|
72
|
+
* @return
|
|
73
|
+
*/
|
|
74
|
+
public String getStoreName() {
|
|
75
|
+
return this._dbName;
|
|
123
76
|
}
|
|
124
77
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Open Method
|
|
80
|
+
* Open the store
|
|
81
|
+
*/
|
|
82
|
+
public void open() throws Exception {
|
|
83
|
+
int curVersion;
|
|
84
|
+
|
|
85
|
+
String password = _encrypted && (_mode.equals("secret") || _mode.equals("encryption")) ? _globVar.secret : "";
|
|
86
|
+
if (_mode.equals("newsecret")) {
|
|
87
|
+
try {
|
|
88
|
+
_uCipher.changePassword(_context, _file, _globVar.secret, _globVar.newsecret);
|
|
89
|
+
password = _globVar.newsecret;
|
|
90
|
+
} catch (Exception e) {
|
|
91
|
+
String msg = "Failed in change password" + e.getMessage();
|
|
92
|
+
Log.v(TAG, msg);
|
|
93
|
+
throw new Exception(msg);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
if (_mode.equals("encryption")) {
|
|
97
|
+
try {
|
|
98
|
+
_uCipher.encrypt(_context, _file, SQLiteDatabase.getBytes(password.toCharArray()));
|
|
99
|
+
} catch (Exception e) {
|
|
100
|
+
String msg = "Failed in encryption " + e.getMessage();
|
|
101
|
+
Log.v(TAG, msg);
|
|
102
|
+
throw new Exception(msg);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
_db = SQLiteDatabase.openOrCreateDatabase(_file, password, null);
|
|
107
|
+
if (_db != null) {
|
|
108
|
+
if (_db.isOpen()) {
|
|
109
|
+
try {
|
|
110
|
+
setTable(_tableName, true);
|
|
111
|
+
isOpen = true;
|
|
112
|
+
return;
|
|
113
|
+
} catch (Exception e) {
|
|
114
|
+
isOpen = false;
|
|
115
|
+
_db = null;
|
|
116
|
+
throw new Exception("Store not opened " + e.getMessage());
|
|
117
|
+
}
|
|
118
|
+
} else {
|
|
119
|
+
isOpen = false;
|
|
120
|
+
_db = null;
|
|
121
|
+
throw new Exception("Store not opened");
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
isOpen = false;
|
|
125
|
+
throw new Exception("No store returned");
|
|
136
126
|
}
|
|
137
|
-
} else {
|
|
138
|
-
isOpen = false;
|
|
139
|
-
_db = null;
|
|
140
|
-
throw new Exception("Store not opened");
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
isOpen = false;
|
|
144
|
-
throw new Exception("No store returned");
|
|
145
127
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Close Method
|
|
131
|
+
* Close the store
|
|
132
|
+
*/
|
|
133
|
+
public void close() throws Exception {
|
|
134
|
+
if (_db.isOpen()) {
|
|
135
|
+
try {
|
|
136
|
+
_db.close();
|
|
137
|
+
isOpen = false;
|
|
138
|
+
return;
|
|
139
|
+
} catch (Exception e) {
|
|
140
|
+
String msg = "Failed in closing the store" + e.getMessage();
|
|
141
|
+
Log.v(TAG, msg);
|
|
142
|
+
throw new Exception(msg);
|
|
143
|
+
}
|
|
144
|
+
} else {
|
|
145
|
+
throw new Exception("Store not opened");
|
|
146
|
+
}
|
|
165
147
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (!this._tableName.equals(name)) this._tableName = name;
|
|
206
|
-
return;
|
|
207
|
-
} catch (Exception e) {
|
|
208
|
-
String msg = "Failed in creating table " + name + " " + e.getMessage();
|
|
209
|
-
Log.v(TAG, msg);
|
|
210
|
-
throw new Exception(msg);
|
|
211
|
-
}
|
|
212
|
-
} else {
|
|
213
|
-
throw new Exception("Store not opened");
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* SetTable Method
|
|
151
|
+
* Set a table and associated index
|
|
152
|
+
* @param name
|
|
153
|
+
* @param ifNotExists
|
|
154
|
+
* @throws Exception
|
|
155
|
+
*/
|
|
156
|
+
public void setTable(String name, Boolean ifNotExists) throws Exception {
|
|
157
|
+
String exist = ifNotExists ? "IF NOT EXISTS" : "";
|
|
158
|
+
if (_db.isOpen()) {
|
|
159
|
+
try {
|
|
160
|
+
String CREATE_STORAGE_TABLE =
|
|
161
|
+
"CREATE TABLE " +
|
|
162
|
+
exist +
|
|
163
|
+
" " +
|
|
164
|
+
name +
|
|
165
|
+
"(" +
|
|
166
|
+
COL_ID +
|
|
167
|
+
" INTEGER PRIMARY KEY AUTOINCREMENT," +
|
|
168
|
+
COL_NAME +
|
|
169
|
+
" TEXT," +
|
|
170
|
+
COL_VALUE +
|
|
171
|
+
" TEXT" +
|
|
172
|
+
");";
|
|
173
|
+
_db.execSQL(CREATE_STORAGE_TABLE);
|
|
174
|
+
String idx = "index_" + name + "_on_" + IDX_COL_NAME;
|
|
175
|
+
String CREATE_INDEX_NAME = "CREATE INDEX " + exist + " " + idx + " ON " + name + " (" + IDX_COL_NAME + ");";
|
|
176
|
+
_db.execSQL(CREATE_INDEX_NAME);
|
|
177
|
+
if (!this._tableName.equals(name)) this._tableName = name;
|
|
178
|
+
return;
|
|
179
|
+
} catch (Exception e) {
|
|
180
|
+
String msg = "Failed in creating table " + name + " " + e.getMessage();
|
|
181
|
+
Log.v(TAG, msg);
|
|
182
|
+
throw new Exception(msg);
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
throw new Exception("Store not opened");
|
|
186
|
+
}
|
|
214
187
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Get Method
|
|
191
|
+
* Get a value from a given key
|
|
192
|
+
* @param name
|
|
193
|
+
* @return
|
|
194
|
+
* @throws Exception
|
|
195
|
+
*/
|
|
196
|
+
public Data get(String name) throws Exception {
|
|
197
|
+
Cursor c = null;
|
|
198
|
+
Data data = null;
|
|
199
|
+
if (_db.isOpen()) {
|
|
200
|
+
try {
|
|
201
|
+
String DATA_SELECT_QUERY = "SELECT * FROM " + this._tableName + " WHERE " + COL_NAME + " = '" + name + "';";
|
|
202
|
+
|
|
203
|
+
c = (Cursor) _db.query(DATA_SELECT_QUERY);
|
|
204
|
+
if (c.getCount() > 0) {
|
|
205
|
+
c.moveToFirst();
|
|
206
|
+
data = new Data();
|
|
207
|
+
data.id = c.getLong(c.getColumnIndex(COL_ID));
|
|
208
|
+
data.name = c.getString(c.getColumnIndex(COL_NAME));
|
|
209
|
+
data.value = c.getString(c.getColumnIndex(COL_VALUE));
|
|
210
|
+
} else {
|
|
211
|
+
data = new Data();
|
|
212
|
+
data.id = null;
|
|
213
|
+
}
|
|
214
|
+
return data;
|
|
215
|
+
} catch (Exception e) {
|
|
216
|
+
String msg = "Failed in get" + e.getMessage();
|
|
217
|
+
Log.v(TAG, msg);
|
|
218
|
+
throw new Exception(msg);
|
|
219
|
+
} finally {
|
|
220
|
+
if (c != null) c.close();
|
|
221
|
+
}
|
|
245
222
|
} else {
|
|
246
|
-
|
|
247
|
-
data.id = null;
|
|
223
|
+
throw new Exception("Store not opened");
|
|
248
224
|
}
|
|
249
|
-
return data;
|
|
250
|
-
} catch (Exception e) {
|
|
251
|
-
String msg = "Failed in get" + e.getMessage();
|
|
252
|
-
Log.v(TAG, msg);
|
|
253
|
-
throw new Exception(msg);
|
|
254
|
-
} finally {
|
|
255
|
-
if (c != null) c.close();
|
|
256
|
-
}
|
|
257
|
-
} else {
|
|
258
|
-
throw new Exception("Store not opened");
|
|
259
225
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
stmt = _db.compileStatement(statement);
|
|
289
|
-
Object[] valObj = new Object[2];
|
|
290
|
-
valObj[0] = value;
|
|
291
|
-
valObj[1] = name;
|
|
292
|
-
SimpleSQLiteQuery.bind(stmt, valObj);
|
|
293
|
-
stmt.executeUpdateDelete();
|
|
294
|
-
/* stmt =
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Set Method
|
|
229
|
+
* Set the value for a given key
|
|
230
|
+
* @param data
|
|
231
|
+
* @throws Exception
|
|
232
|
+
*/
|
|
233
|
+
public void set(Data data) throws Exception {
|
|
234
|
+
String name = data.name;
|
|
235
|
+
String value = data.value;
|
|
236
|
+
if (_db.isOpen()) {
|
|
237
|
+
try {
|
|
238
|
+
boolean ret = iskey(name);
|
|
239
|
+
String statement = "";
|
|
240
|
+
SupportSQLiteStatement stmt = null;
|
|
241
|
+
|
|
242
|
+
if (ret) {
|
|
243
|
+
// update
|
|
244
|
+
statement = statement.concat("UPDATE ").concat(this._tableName).concat(" SET ");
|
|
245
|
+
statement = statement.concat(COL_VALUE).concat(" = ? ");
|
|
246
|
+
statement = statement.concat(" WHERE ").concat(COL_NAME).concat(" = ?;");
|
|
247
|
+
stmt = _db.compileStatement(statement);
|
|
248
|
+
Object[] valObj = new Object[2];
|
|
249
|
+
valObj[0] = value;
|
|
250
|
+
valObj[1] = name;
|
|
251
|
+
SimpleSQLiteQuery.bind(stmt, valObj);
|
|
252
|
+
stmt.executeUpdateDelete();
|
|
253
|
+
/* stmt =
|
|
295
254
|
"UPDATE " + this._tableName + " SET " + COL_VALUE + " = '" + value + "' WHERE " + COL_NAME + " = '" + name + "';";
|
|
296
255
|
*/
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
256
|
+
} else {
|
|
257
|
+
// insert
|
|
258
|
+
|
|
259
|
+
statement = statement.concat("INSERT INTO ").concat(this._tableName);
|
|
260
|
+
statement = statement.concat(" (").concat(COL_NAME).concat(",");
|
|
261
|
+
statement = statement.concat(COL_VALUE).concat(") VALUES(?,?);");
|
|
262
|
+
stmt = _db.compileStatement(statement);
|
|
263
|
+
Object[] valObj = new Object[2];
|
|
264
|
+
valObj[0] = name;
|
|
265
|
+
valObj[1] = value;
|
|
266
|
+
SimpleSQLiteQuery.bind(stmt, valObj);
|
|
267
|
+
stmt.executeInsert();
|
|
268
|
+
/*
|
|
310
269
|
stmt =
|
|
311
270
|
"INSERT INTO " + _tableName + " (" + COL_NAME + "," + COL_VALUE + ") " + "VALUES('" + name + "','" + value + "');";
|
|
312
271
|
*/
|
|
272
|
+
}
|
|
273
|
+
// _db.execSQL(stmt);
|
|
274
|
+
} catch (IllegalStateException e) {
|
|
275
|
+
String msg = "Failed in set" + e.getMessage();
|
|
276
|
+
Log.v(TAG, msg);
|
|
277
|
+
throw new Exception(msg);
|
|
278
|
+
} catch (IllegalArgumentException e) {
|
|
279
|
+
String msg = "Failed in set" + e.getMessage();
|
|
280
|
+
Log.v(TAG, msg);
|
|
281
|
+
throw new Exception(msg);
|
|
282
|
+
} catch (Exception e) {
|
|
283
|
+
String msg = "Failed in set" + e.getMessage();
|
|
284
|
+
Log.v(TAG, msg);
|
|
285
|
+
throw new Exception(msg);
|
|
286
|
+
}
|
|
287
|
+
} else {
|
|
288
|
+
throw new Exception("Store not opened");
|
|
313
289
|
}
|
|
314
|
-
// _db.execSQL(stmt);
|
|
315
|
-
} catch (IllegalStateException e) {
|
|
316
|
-
String msg = "Failed in set" + e.getMessage();
|
|
317
|
-
Log.v(TAG, msg);
|
|
318
|
-
throw new Exception(msg);
|
|
319
|
-
} catch (IllegalArgumentException e) {
|
|
320
|
-
String msg = "Failed in set" + e.getMessage();
|
|
321
|
-
Log.v(TAG, msg);
|
|
322
|
-
throw new Exception(msg);
|
|
323
|
-
} catch (Exception e) {
|
|
324
|
-
String msg = "Failed in set" + e.getMessage();
|
|
325
|
-
Log.v(TAG, msg);
|
|
326
|
-
throw new Exception(msg);
|
|
327
|
-
}
|
|
328
|
-
} else {
|
|
329
|
-
throw new Exception("Store not opened");
|
|
330
290
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
public void clear() throws Exception {
|
|
358
|
-
if (_db.isOpen()) {
|
|
359
|
-
try {
|
|
360
|
-
_db.execSQL("DELETE FROM " + this._tableName);
|
|
361
|
-
return;
|
|
362
|
-
} catch (Exception e) {
|
|
363
|
-
String msg = "Failed in clear" + e.getMessage();
|
|
364
|
-
throw new Exception(msg);
|
|
365
|
-
}
|
|
366
|
-
} else {
|
|
367
|
-
throw new Exception("Store not opened");
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Iskey
|
|
294
|
+
* Check if a key is existing in the store
|
|
295
|
+
* @param name
|
|
296
|
+
* @return
|
|
297
|
+
* @throws Exception
|
|
298
|
+
*/
|
|
299
|
+
public boolean iskey(String name) throws Exception {
|
|
300
|
+
boolean ret = false;
|
|
301
|
+
if (_db.isOpen()) {
|
|
302
|
+
try {
|
|
303
|
+
Data data = get(name);
|
|
304
|
+
if (data.id != null) ret = true;
|
|
305
|
+
return ret;
|
|
306
|
+
} catch (Exception e) {
|
|
307
|
+
String msg = "Failed in iskey" + e.getMessage();
|
|
308
|
+
Log.v(TAG, msg);
|
|
309
|
+
throw new Exception(msg);
|
|
310
|
+
}
|
|
311
|
+
} else {
|
|
312
|
+
throw new Exception("Store not opened");
|
|
313
|
+
}
|
|
368
314
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
);
|
|
383
|
-
return;
|
|
384
|
-
} catch (Exception e) {
|
|
385
|
-
String msg = "Failed in remove" + e.getMessage();
|
|
386
|
-
throw new Exception(msg);
|
|
387
|
-
}
|
|
388
|
-
} else {
|
|
389
|
-
throw new Exception("Store not opened");
|
|
315
|
+
|
|
316
|
+
public void clear() throws Exception {
|
|
317
|
+
if (_db.isOpen()) {
|
|
318
|
+
try {
|
|
319
|
+
_db.execSQL("DELETE FROM " + this._tableName);
|
|
320
|
+
return;
|
|
321
|
+
} catch (Exception e) {
|
|
322
|
+
String msg = "Failed in clear" + e.getMessage();
|
|
323
|
+
throw new Exception(msg);
|
|
324
|
+
}
|
|
325
|
+
} else {
|
|
326
|
+
throw new Exception("Store not opened");
|
|
327
|
+
}
|
|
390
328
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
" FROM " +
|
|
402
|
-
this._tableName +
|
|
403
|
-
" ORDER BY " +
|
|
404
|
-
COL_NAME +
|
|
405
|
-
";";
|
|
406
|
-
|
|
407
|
-
c = (Cursor) _db.query(DATA_SELECT_QUERY);
|
|
408
|
-
if (c.getCount() > 0) {
|
|
409
|
-
if (c.moveToFirst()) {
|
|
410
|
-
do {
|
|
411
|
-
String key = c.getString(c.getColumnIndex(COL_NAME));
|
|
412
|
-
data.add(key);
|
|
413
|
-
} while (c.moveToNext());
|
|
414
|
-
}
|
|
329
|
+
|
|
330
|
+
public void remove(String name) throws Exception {
|
|
331
|
+
if (_db.isOpen()) {
|
|
332
|
+
try {
|
|
333
|
+
_db.execSQL("DELETE FROM " + this._tableName + " WHERE " + COL_NAME + " = '" + name + "';");
|
|
334
|
+
return;
|
|
335
|
+
} catch (Exception e) {
|
|
336
|
+
String msg = "Failed in remove" + e.getMessage();
|
|
337
|
+
throw new Exception(msg);
|
|
338
|
+
}
|
|
415
339
|
} else {
|
|
416
|
-
|
|
340
|
+
throw new Exception("Store not opened");
|
|
417
341
|
}
|
|
418
|
-
return data;
|
|
419
|
-
} catch (Exception e) {
|
|
420
|
-
String msg = "Failed in keys" + e.getMessage();
|
|
421
|
-
throw new Exception(msg);
|
|
422
|
-
} finally {
|
|
423
|
-
if (c != null) c.close();
|
|
424
|
-
}
|
|
425
|
-
} else {
|
|
426
|
-
throw new Exception("Store not opened");
|
|
427
342
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
343
|
+
|
|
344
|
+
public List<String> keys() throws Exception {
|
|
345
|
+
Cursor c = null;
|
|
346
|
+
List<String> data = new ArrayList<>();
|
|
347
|
+
if (_db.isOpen()) {
|
|
348
|
+
try {
|
|
349
|
+
String DATA_SELECT_QUERY = "SELECT " + COL_NAME + " FROM " + this._tableName + " ORDER BY " + COL_NAME + ";";
|
|
350
|
+
|
|
351
|
+
c = (Cursor) _db.query(DATA_SELECT_QUERY);
|
|
352
|
+
if (c.getCount() > 0) {
|
|
353
|
+
if (c.moveToFirst()) {
|
|
354
|
+
do {
|
|
355
|
+
String key = c.getString(c.getColumnIndex(COL_NAME));
|
|
356
|
+
data.add(key);
|
|
357
|
+
} while (c.moveToNext());
|
|
358
|
+
}
|
|
359
|
+
} else {
|
|
360
|
+
data = Collections.emptyList();
|
|
361
|
+
}
|
|
362
|
+
return data;
|
|
363
|
+
} catch (Exception e) {
|
|
364
|
+
String msg = "Failed in keys" + e.getMessage();
|
|
365
|
+
throw new Exception(msg);
|
|
366
|
+
} finally {
|
|
367
|
+
if (c != null) c.close();
|
|
368
|
+
}
|
|
452
369
|
} else {
|
|
453
|
-
|
|
370
|
+
throw new Exception("Store not opened");
|
|
454
371
|
}
|
|
455
|
-
return data;
|
|
456
|
-
} catch (Exception e) {
|
|
457
|
-
String msg = "Failed in values" + e.getMessage();
|
|
458
|
-
throw new Exception(msg);
|
|
459
|
-
} finally {
|
|
460
|
-
if (c != null) c.close();
|
|
461
|
-
}
|
|
462
|
-
} else {
|
|
463
|
-
throw new Exception("Store not opened");
|
|
464
372
|
}
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
373
|
+
|
|
374
|
+
public List<String> values() throws Exception {
|
|
375
|
+
Cursor c = null;
|
|
376
|
+
List<String> data = new ArrayList<>();
|
|
377
|
+
if (_db.isOpen()) {
|
|
378
|
+
try {
|
|
379
|
+
String DATA_SELECT_QUERY = "SELECT " + COL_VALUE + " FROM " + this._tableName + " ORDER BY " + COL_NAME + ";";
|
|
380
|
+
|
|
381
|
+
c = (Cursor) _db.query(DATA_SELECT_QUERY);
|
|
382
|
+
if (c.getCount() > 0) {
|
|
383
|
+
if (c.moveToFirst()) {
|
|
384
|
+
do {
|
|
385
|
+
String key = c.getString(c.getColumnIndex(COL_VALUE));
|
|
386
|
+
data.add(key);
|
|
387
|
+
} while (c.moveToNext());
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
data = Collections.emptyList();
|
|
391
|
+
}
|
|
392
|
+
return data;
|
|
393
|
+
} catch (Exception e) {
|
|
394
|
+
String msg = "Failed in values" + e.getMessage();
|
|
395
|
+
throw new Exception(msg);
|
|
396
|
+
} finally {
|
|
397
|
+
if (c != null) c.close();
|
|
398
|
+
}
|
|
485
399
|
} else {
|
|
486
|
-
|
|
400
|
+
throw new Exception("Store not opened");
|
|
487
401
|
}
|
|
488
|
-
return data;
|
|
489
|
-
} catch (Exception e) {
|
|
490
|
-
String msg = "Failed in keysvalues" + e.getMessage();
|
|
491
|
-
throw new Exception(msg);
|
|
492
|
-
} finally {
|
|
493
|
-
if (c != null) c.close();
|
|
494
|
-
}
|
|
495
|
-
} else {
|
|
496
|
-
throw new Exception("Store not opened");
|
|
497
402
|
}
|
|
498
|
-
}
|
|
499
403
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
404
|
+
public List<Data> keysvalues() throws Exception {
|
|
405
|
+
Cursor c = null;
|
|
406
|
+
List<Data> data = new ArrayList<>();
|
|
407
|
+
if (_db.isOpen()) {
|
|
408
|
+
try {
|
|
409
|
+
String DATA_SELECT_QUERY = "SELECT * FROM " + this._tableName + " ORDER BY " + COL_NAME + ";";
|
|
410
|
+
|
|
411
|
+
c = (Cursor) _db.query(DATA_SELECT_QUERY);
|
|
412
|
+
if (c.getCount() > 0) {
|
|
413
|
+
if (c.moveToFirst()) {
|
|
414
|
+
do {
|
|
415
|
+
Data newData = new Data();
|
|
416
|
+
newData.name = c.getString(c.getColumnIndex(COL_NAME));
|
|
417
|
+
newData.value = c.getString(c.getColumnIndex(COL_VALUE));
|
|
418
|
+
data.add(newData);
|
|
419
|
+
} while (c.moveToNext());
|
|
420
|
+
}
|
|
421
|
+
} else {
|
|
422
|
+
data = Collections.emptyList();
|
|
423
|
+
}
|
|
424
|
+
return data;
|
|
425
|
+
} catch (Exception e) {
|
|
426
|
+
String msg = "Failed in keysvalues" + e.getMessage();
|
|
427
|
+
throw new Exception(msg);
|
|
428
|
+
} finally {
|
|
429
|
+
if (c != null) c.close();
|
|
430
|
+
}
|
|
431
|
+
} else {
|
|
432
|
+
throw new Exception("Store not opened");
|
|
433
|
+
}
|
|
504
434
|
}
|
|
505
|
-
|
|
506
|
-
List<String>
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
435
|
+
|
|
436
|
+
public List<String> filtervalues(String filter) throws Exception {
|
|
437
|
+
String inFilter = filter;
|
|
438
|
+
if (!inFilter.startsWith("%") && !inFilter.endsWith("%")) {
|
|
439
|
+
inFilter = "%" + inFilter + "%";
|
|
440
|
+
}
|
|
441
|
+
Cursor c = null;
|
|
442
|
+
List<String> data = new ArrayList<>();
|
|
443
|
+
if (_db.isOpen()) {
|
|
444
|
+
try {
|
|
445
|
+
String DATA_SELECT_QUERY =
|
|
446
|
+
"SELECT " +
|
|
447
|
+
COL_VALUE +
|
|
448
|
+
" FROM " +
|
|
449
|
+
this._tableName +
|
|
450
|
+
" WHERE " +
|
|
451
|
+
COL_NAME +
|
|
452
|
+
" LIKE '" +
|
|
453
|
+
inFilter +
|
|
454
|
+
"'" +
|
|
455
|
+
" ORDER BY " +
|
|
456
|
+
COL_NAME +
|
|
457
|
+
";";
|
|
458
|
+
c = (Cursor) _db.query(DATA_SELECT_QUERY);
|
|
459
|
+
if (c.getCount() > 0) {
|
|
460
|
+
if (c.moveToFirst()) {
|
|
461
|
+
do {
|
|
462
|
+
String key = c.getString(c.getColumnIndex(COL_VALUE));
|
|
463
|
+
data.add(key);
|
|
464
|
+
} while (c.moveToNext());
|
|
465
|
+
}
|
|
466
|
+
} else {
|
|
467
|
+
data = Collections.emptyList();
|
|
468
|
+
}
|
|
469
|
+
return data;
|
|
470
|
+
} catch (Exception e) {
|
|
471
|
+
String msg = "Failed in values" + e.getMessage();
|
|
472
|
+
throw new Exception(msg);
|
|
473
|
+
} finally {
|
|
474
|
+
if (c != null) c.close();
|
|
475
|
+
}
|
|
530
476
|
} else {
|
|
531
|
-
|
|
477
|
+
throw new Exception("Store not opened");
|
|
532
478
|
}
|
|
533
|
-
return data;
|
|
534
|
-
} catch (Exception e) {
|
|
535
|
-
String msg = "Failed in values" + e.getMessage();
|
|
536
|
-
throw new Exception(msg);
|
|
537
|
-
} finally {
|
|
538
|
-
if (c != null) c.close();
|
|
539
|
-
}
|
|
540
|
-
} else {
|
|
541
|
-
throw new Exception("Store not opened");
|
|
542
479
|
}
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
480
|
+
|
|
481
|
+
public boolean isTable(String table) throws Exception {
|
|
482
|
+
boolean ret = false;
|
|
483
|
+
if (_db.isOpen()) {
|
|
484
|
+
try {
|
|
485
|
+
List<String> tables = getTables();
|
|
486
|
+
if (tables.size() > 0 && tables.contains(table)) {
|
|
487
|
+
ret = true;
|
|
488
|
+
}
|
|
489
|
+
return ret;
|
|
490
|
+
} catch (Exception e) {
|
|
491
|
+
String msg = "Failed in isTable" + e.getMessage();
|
|
492
|
+
throw new Exception(msg);
|
|
493
|
+
}
|
|
494
|
+
} else {
|
|
495
|
+
throw new Exception("Store not opened");
|
|
552
496
|
}
|
|
553
|
-
return ret;
|
|
554
|
-
} catch (Exception e) {
|
|
555
|
-
String msg = "Failed in isTable" + e.getMessage();
|
|
556
|
-
throw new Exception(msg);
|
|
557
|
-
}
|
|
558
|
-
} else {
|
|
559
|
-
throw new Exception("Store not opened");
|
|
560
497
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
498
|
+
|
|
499
|
+
public List<String> tables() throws Exception {
|
|
500
|
+
try {
|
|
501
|
+
List<String> tables = getTables();
|
|
502
|
+
return tables;
|
|
503
|
+
} catch (Exception e) {
|
|
504
|
+
String msg = "Failed in tables" + e.getMessage();
|
|
505
|
+
throw new Exception(msg);
|
|
506
|
+
}
|
|
570
507
|
}
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
508
|
+
|
|
509
|
+
public void deleteTable(String table) throws Exception {
|
|
510
|
+
if (_db.isOpen()) {
|
|
511
|
+
try {
|
|
512
|
+
List<String> tables = getTables();
|
|
513
|
+
if (tables.size() > 0 && tables.contains(table)) {
|
|
514
|
+
_db.execSQL("DROP TABLE IF EXISTS " + table + ";");
|
|
515
|
+
return;
|
|
516
|
+
} else {
|
|
517
|
+
throw new Exception("table " + table + " does not exist");
|
|
518
|
+
}
|
|
519
|
+
} catch (Exception e) {
|
|
520
|
+
String msg = "Failed in deleteTable" + e.getMessage();
|
|
521
|
+
throw new Exception(msg);
|
|
522
|
+
}
|
|
580
523
|
} else {
|
|
581
|
-
|
|
524
|
+
throw new Exception("Store not opened");
|
|
582
525
|
}
|
|
583
|
-
} catch (Exception e) {
|
|
584
|
-
String msg = "Failed in deleteTable" + e.getMessage();
|
|
585
|
-
throw new Exception(msg);
|
|
586
|
-
}
|
|
587
|
-
} else {
|
|
588
|
-
throw new Exception("Store not opened");
|
|
589
526
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
527
|
+
|
|
528
|
+
private List<String> getTables() throws Exception {
|
|
529
|
+
Cursor c = null;
|
|
530
|
+
List<String> tables = new ArrayList<>();
|
|
531
|
+
if (_db.isOpen()) {
|
|
532
|
+
try {
|
|
533
|
+
String DATA_SELECT_QUERY = "SELECT name FROM sqlite_master WHERE TYPE='table'" + " ORDER BY name " + ";";
|
|
534
|
+
|
|
535
|
+
c = (Cursor) _db.query(DATA_SELECT_QUERY);
|
|
536
|
+
if (c.getCount() > 0) {
|
|
537
|
+
if (c.moveToFirst()) {
|
|
538
|
+
do {
|
|
539
|
+
String table = c.getString(c.getColumnIndex("name"));
|
|
540
|
+
if (!table.equals("sqlite_sequence")) {
|
|
541
|
+
tables.add(table);
|
|
542
|
+
}
|
|
543
|
+
} while (c.moveToNext());
|
|
544
|
+
}
|
|
545
|
+
} else {
|
|
546
|
+
tables = Collections.emptyList();
|
|
547
|
+
}
|
|
548
|
+
return tables;
|
|
549
|
+
} catch (Exception e) {
|
|
550
|
+
String msg = "Failed in tables" + e.getMessage();
|
|
551
|
+
Log.v(TAG, msg);
|
|
552
|
+
throw new Exception(msg);
|
|
553
|
+
} finally {
|
|
554
|
+
if (c != null) c.close();
|
|
555
|
+
}
|
|
612
556
|
} else {
|
|
613
|
-
|
|
557
|
+
throw new Exception("Store not opened");
|
|
614
558
|
}
|
|
615
|
-
return tables;
|
|
616
|
-
} catch (Exception e) {
|
|
617
|
-
String msg = "Failed in tables" + e.getMessage();
|
|
618
|
-
Log.v(TAG, msg);
|
|
619
|
-
throw new Exception(msg);
|
|
620
|
-
} finally {
|
|
621
|
-
if (c != null) c.close();
|
|
622
|
-
}
|
|
623
|
-
} else {
|
|
624
|
-
throw new Exception("Store not opened");
|
|
625
559
|
}
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
throw new Exception(e.getMessage());
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
public JSObject exportToJson() {
|
|
651
|
-
JsonStore retJson = new JsonStore();
|
|
652
|
-
JSObject retObj = new JSObject();
|
|
653
|
-
retJson.setDatabase(_dbName.substring(0, _dbName.length() - 9));
|
|
654
|
-
retJson.setEncrypted(_encrypted);
|
|
655
|
-
|
|
656
|
-
String previousName = _tableName;
|
|
657
|
-
try {
|
|
658
|
-
List<String> tables = tables();
|
|
659
|
-
ArrayList<JsonTable> rTables = new ArrayList<JsonTable>();
|
|
660
|
-
for (String table : tables) {
|
|
661
|
-
JsonTable rTable = new JsonTable();
|
|
662
|
-
_tableName = table;
|
|
663
|
-
rTable.setName(table);
|
|
664
|
-
List<Data> dataTable = keysvalues();
|
|
665
|
-
ArrayList<JsonValue> values = new ArrayList<JsonValue>();
|
|
666
|
-
for (Data data : dataTable) {
|
|
667
|
-
JsonValue rData = new JsonValue();
|
|
668
|
-
rData.setKey(data.name);
|
|
669
|
-
rData.setValue(data.value);
|
|
670
|
-
values.add(rData);
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Import from Json object
|
|
563
|
+
* @param values
|
|
564
|
+
* @return
|
|
565
|
+
* @throws Exception
|
|
566
|
+
*/
|
|
567
|
+
public Integer importFromJson(ArrayList<JsonValue> values) throws Exception {
|
|
568
|
+
int changes = Integer.valueOf(0);
|
|
569
|
+
try {
|
|
570
|
+
for (JsonValue val : values) {
|
|
571
|
+
Data data = new Data();
|
|
572
|
+
data.name = val.getKey();
|
|
573
|
+
data.value = val.getValue();
|
|
574
|
+
set(data);
|
|
575
|
+
changes += 1;
|
|
576
|
+
}
|
|
577
|
+
return changes;
|
|
578
|
+
} catch (Exception e) {
|
|
579
|
+
throw new Exception(e.getMessage());
|
|
671
580
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
public JSObject exportToJson() {
|
|
584
|
+
JsonStore retJson = new JsonStore();
|
|
585
|
+
JSObject retObj = new JSObject();
|
|
586
|
+
retJson.setDatabase(_dbName.substring(0, _dbName.length() - 9));
|
|
587
|
+
retJson.setEncrypted(_encrypted);
|
|
588
|
+
|
|
589
|
+
String previousName = _tableName;
|
|
590
|
+
try {
|
|
591
|
+
List<String> tables = tables();
|
|
592
|
+
ArrayList<JsonTable> rTables = new ArrayList<JsonTable>();
|
|
593
|
+
for (String table : tables) {
|
|
594
|
+
JsonTable rTable = new JsonTable();
|
|
595
|
+
_tableName = table;
|
|
596
|
+
rTable.setName(table);
|
|
597
|
+
List<Data> dataTable = keysvalues();
|
|
598
|
+
ArrayList<JsonValue> values = new ArrayList<JsonValue>();
|
|
599
|
+
for (Data data : dataTable) {
|
|
600
|
+
JsonValue rData = new JsonValue();
|
|
601
|
+
rData.setKey(data.name);
|
|
602
|
+
rData.setValue(data.value);
|
|
603
|
+
values.add(rData);
|
|
604
|
+
}
|
|
605
|
+
rTable.setValues(values);
|
|
606
|
+
rTables.add(rTable);
|
|
607
|
+
}
|
|
608
|
+
retJson.setTables(rTables);
|
|
609
|
+
_tableName = previousName;
|
|
610
|
+
ArrayList<String> keys = retJson.getKeys();
|
|
611
|
+
if (keys.contains("tables")) {
|
|
612
|
+
if (retJson.getTables().size() > 0) {
|
|
613
|
+
retObj.put("database", retJson.getDatabase());
|
|
614
|
+
retObj.put("encrypted", retJson.getEncrypted());
|
|
615
|
+
retObj.put("tables", retJson.getTablesAsJSObject());
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
} catch (Exception e) {
|
|
619
|
+
Log.e(TAG, "Error: exportToJson " + e.getMessage());
|
|
620
|
+
} finally {
|
|
621
|
+
return retObj;
|
|
683
622
|
}
|
|
684
|
-
}
|
|
685
|
-
} catch (Exception e) {
|
|
686
|
-
Log.e(TAG, "Error: exportToJson " + e.getMessage());
|
|
687
|
-
} finally {
|
|
688
|
-
return retObj;
|
|
689
623
|
}
|
|
690
|
-
}
|
|
691
624
|
}
|