From 9f1d0a7983de2936aac0de2eceb46e07017bd1b9 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Mon, 11 Dec 2017 20:05:05 -0500 Subject: [PATCH] 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 (no Android-sqlite-connector / Android-sqlite-native-driver libraries). Ref: - litehelpers/Cordova-sqlite-storage#730 - litehelpers/Cordova-sqlite-storage#666 --- CHANGES.md | 4 ++-- package.json | 2 +- plugin.xml | 2 +- src/android/io/sqlc/SQLiteAndroidDatabase.java | 9 +++++++++ 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 6f750b34..4f63fec3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/package.json b/package.json index bf0368f3..de01ba1d 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/plugin.xml b/plugin.xml index 8380b945..d2e83367 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.0.4-newdev01"> Cordova sqlite storage plugin - legacy express core version diff --git a/src/android/io/sqlc/SQLiteAndroidDatabase.java b/src/android/io/sqlc/SQLiteAndroidDatabase.java index a3870445..a1887184 100644 --- a/src/android/io/sqlc/SQLiteAndroidDatabase.java +++ b/src/android/io/sqlc/SQLiteAndroidDatabase.java @@ -51,6 +51,8 @@ class SQLiteAndroidDatabase SQLiteDatabase mydb; + boolean isTransactionActive = false; + /** * NOTE: Using default constructor, no explicit constructor. */ @@ -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; } @@ -195,6 +201,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams, needRawQuery = false; try { mydb.beginTransaction(); + isTransactionActive = true; queryResult = new JSONObject(); queryResult.put("rowsAffected", 0); @@ -210,6 +217,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams, try { mydb.setTransactionSuccessful(); mydb.endTransaction(); + isTransactionActive = false; queryResult = new JSONObject(); queryResult.put("rowsAffected", 0); @@ -224,6 +232,7 @@ void executeSqlBatch(String[] queryarr, JSONArray[] jsonparams, needRawQuery = false; try { mydb.endTransaction(); + isTransactionActive = false; queryResult = new JSONObject(); queryResult.put("rowsAffected", 0);