Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RMET-2046 SQLite 3.33.0 update - Android #12

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
.metadata/*
*.swp
*~
.idea
.iml
node_modules
package-lock.json
spec/myplugin
Expand Down
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## unreleased

- Update for SQLCipher 4.4.2 and SQLite 3.33.0

## cordova-sqlcipher-adapter 0.1.7-OS7

- Fix: Add another use case for self-healing the database (https://outsystemsrd.atlassian.net/browse/RMET-1191)
Expand All @@ -8,7 +12,6 @@

- Logger removal for MABS 7


## cordova-sqlcipher-adapter 0.1.7-OS5

- Support to 64-bits
Expand Down
11 changes: 4 additions & 7 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,10 @@
<source-file src="src/android/io/sqlc/SQLitePlugin.java" target-dir="src/io/sqlc"/>
<source-file src="src/android/io/sqlc/SQLiteAndroidDatabase.java" target-dir="src/io/sqlc"/>

<!-- SQLCipher distribution for Android: -->
<source-file src="src/android/sqlcipher/libs/sqlcipher.jar" target-dir="libs" />
<source-file src="src/android/sqlcipher/libs/armeabi/libsqlcipher.so" target-dir="libs/armeabi" />
<source-file src="src/android/sqlcipher/libs/armeabi-v7a/libsqlcipher.so" target-dir="libs/armeabi-v7a" />
<source-file src="src/android/sqlcipher/libs/x86/libsqlcipher.so" target-dir="libs/x86" />
<source-file src="src/android/sqlcipher/libs/arm64-v8a/libsqlcipher.so" target-dir="libs/arm64-v8a" />
<source-file src="src/android/sqlcipher/libs/x86_64/libsqlcipher.so" target-dir="libs/x86_64" />
<lib-file src="src/android/libs/android-database-sqlcipher-classes.jar" />
<lib-file src="src/android/libs/android-database-sqlcipher-ndk.jar" />
<!-- androidx.sqlite now required -->
<framework src="androidx.sqlite:sqlite:2.1.0" />

<!-- [FUTURE TBD] consider using external aar again -->
<!-- THANKS to @jcesarmobile for GUIDANCE in accepted answer:
Expand Down
58 changes: 36 additions & 22 deletions src/android/io/sqlc/SQLiteAndroidDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
/* ** NOT USED in this plugin version:
import android.database.Cursor;
import android.database.CursorWindow;

import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteDatabase;
Expand Down Expand Up @@ -81,8 +80,23 @@ public void initialize(CordovaInterface cordova) {
*
* @param dbfile The database File specification
*/
void open(File dbfile, String key) throws Exception {
mydb = SQLiteDatabase.openOrCreateDatabase(dbfile, key, null);
void open(File dbfile, String key, boolean migrateCipher) throws Exception {

SQLiteDatabaseHook hook = null;
if(migrateCipher) {
hook = new SQLiteDatabaseHook() {
public void preKey(SQLiteDatabase database) {}
public void postKey(SQLiteDatabase database) {
database.rawExecSQL("PRAGMA cipher_migrate");
}
};
}
mydb = SQLiteDatabase.openDatabase(
dbfile.getAbsolutePath(),
key,
null,
SQLiteDatabase.OPEN_READWRITE | SQLiteDatabase.CREATE_IF_NECESSARY,
hook);
}

/**
Expand Down Expand Up @@ -346,24 +360,24 @@ private void bindArgsToStatement(SQLiteStatement myStatement, JSONArray sqlArgs)
}
}
}
private static Object[] getParamsFromJSON(JSONArray paramsAsJson) throws JSONException {
Object[] params = new Object[paramsAsJson.length()];

for (int i = 0; i < paramsAsJson.length(); i++) {
if (paramsAsJson.get(i) instanceof Float || paramsAsJson.get(i) instanceof Double) {
params[i] = paramsAsJson.getDouble(i);
} else if (paramsAsJson.get(i) instanceof Number) {
params[i] = paramsAsJson.getLong(i);
} else if (paramsAsJson.isNull(i)) {
params[i] = null;
} else {
params[i] = paramsAsJson.getString(i);
}
}
return params;
}

private static Object[] getParamsFromJSON(JSONArray paramsAsJson) throws JSONException {
Object[] params = new Object[paramsAsJson.length()];

for (int i = 0; i < paramsAsJson.length(); i++) {
if (paramsAsJson.get(i) instanceof Float || paramsAsJson.get(i) instanceof Double) {
params[i] = paramsAsJson.getDouble(i);
} else if (paramsAsJson.get(i) instanceof Number) {
params[i] = paramsAsJson.getLong(i);
} else if (paramsAsJson.isNull(i)) {
params[i] = null;
} else {
params[i] = paramsAsJson.getString(i);
}
}

return params;
}

/**
* Get rows results from query cursor.
Expand Down Expand Up @@ -482,4 +496,4 @@ static enum QueryType {
rollback,
other
}
} /* vim: set expandtab : */
} /* vim: set expandtab : */
Loading