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 selfTest to pass on builtin android.database implementation
(no Android-sqlite-connector / Android-sqlite-native-driver libraries)

ref: #730
  • Loading branch information
Christopher J. Brody committed Dec 12, 2017
1 parent 1bea0b2 commit 8192bc8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## cordova-sqlite-storage 2.1.4-fixdev01

- android.database end transaction if active before closing

## cordova-sqlite-storage 2.1.3

##### cordova-sqlite-legacy-core 1.0.5
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-storage",
"version": "2.1.3",
"version": "2.1.4-fixdev01",
"description": "Native interface to SQLite for PhoneGap/Cordova",
"cordova": {
"id": "cordova-sqlite-storage",
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-storage"
version="2.1.3">
version="2.1.4-fixdev01">

<name>Cordova sqlite storage plugin</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 @@ -56,6 +56,8 @@ class SQLiteAndroidDatabase

SQLiteDatabase mydb;

boolean isTransactionActive = false;

/**
* NOTE: Using default constructor, no explicit constructor.
*/
Expand All @@ -75,6 +77,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 @@ -227,6 +233,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
needRawQuery = false;
try {
mydb.beginTransaction();
isTransactionActive = true;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -242,6 +249,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
try {
mydb.setTransactionSuccessful();
mydb.endTransaction();
isTransactionActive = false;

queryResult = new JSONObject();
queryResult.put("rowsAffected", 0);
Expand All @@ -256,6 +264,7 @@ private void executeSqlBatchStatement(String query, JSONArray json_params, JSONA
needRawQuery = false;
try {
mydb.endTransaction();
isTransactionActive = false;

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

0 comments on commit 8192bc8

Please sign in to comment.