Skip to content

Commit

Permalink
android.database end transaction if active before closing
Browse files Browse the repository at this point in the history
Needed for new BUG 666 workaround solution to pass selfTest
in case of builtin android.database implementation
(no Android-sqlite-connector / Android-sqlite-native-driver libraries).

Ref:
- storesafe/cordova-sqlite-storage#730
- storesafe/cordova-sqlite-storage#666
  • Loading branch information
Christopher J. Brody committed Dec 14, 2017
1 parent 51ced03 commit 9f1d0a7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Changes

###### cordova-sqlite-legacy-express-core 1.0.4-devtest00
###### cordova-sqlite-legacy-express-core 1.0.4-newdev01

TBD
- android.database end transaction if active before closing (needed for new BUG 666 workaround solution to pass selfTest in case of builtin android.database implementation)

###### cordova-sqlite-legacy-express-core 1.0.3

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-sqlite-legacy-express-core",
"version": "1.0.4-devtest00",
"version": "1.0.4-newdev01",
"description": "Native interface to SQLite for PhoneGap/Cordova (legacy express core version)",
"cordova": {
"id": "cordova-sqlite-legacy-express-core",
Expand Down
2 changes: 1 addition & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="cordova-sqlite-legacy-express-core"
version="1.0.4-devtest00">
version="1.0.4-newdev01">

<name>Cordova sqlite storage plugin - legacy express core version</name>

Expand Down
9 changes: 9 additions & 0 deletions src/android/io/sqlc/SQLiteAndroidDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class SQLiteAndroidDatabase

SQLiteDatabase mydb;

boolean isTransactionActive = false;

/**
* NOTE: Using default constructor, no explicit constructor.
*/
Expand All @@ -70,6 +72,10 @@ void open(File dbfile) throws Exception {
*/
void closeDatabaseNow() {
if (mydb != null) {
if (isTransactionActive) {
mydb.endTransaction();
isTransactionActive = false;
}
mydb.close();
mydb = null;
}
Expand Down Expand Up @@ -195,6 +201,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams,
needRawQuery = false;
try {
mydb.beginTransaction();
isTransactionActive = true;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -210,6 +217,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams,
try {
mydb.setTransactionSuccessful();
mydb.endTransaction();
isTransactionActive = false;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -224,6 +232,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams,
needRawQuery = false;
try {
mydb.endTransaction();
isTransactionActive = false;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand Down

0 comments on commit 9f1d0a7

Please sign in to comment.