Skip to content

Commit

Permalink
Quick workaround fix for storesafe#19
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Feb 12, 2016
1 parent e493b1c commit 35de640
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changes

## 0.1.4-rc

- Workaround fix for empty readTransaction issue

## 0.1.4-pre

- Implement database close and delete operations for Windows "Universal"
Expand Down
5 changes: 5 additions & 0 deletions SQLitePlugin.coffee.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,11 @@
@addStatement "BEGIN", [], null, (tx, err) ->
throw newSQLError "unable to begin transaction: " + err.message, err.code

# Workaround for litehelpers/Cordova-sqlite-storage#409
# extra statement in case user function does not add any SQL statements
else
@addStatement "SELECT 1", [], null, null

return

SQLitePluginTransaction::start = ->
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-sqlcipher-adapter",
"version": "0.1.4-pre",
"version": "0.1.4-rc",
"description": "SQLCipher database adapter for PhoneGap/Cordova, based on cordova-sqlite-storage",
"cordova": {
"id": "cordova-sqlcipher-adapter",
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="io.litehelpers.cordova.sqlcipher"
version="0.1.4-pre">
version="0.1.4-rc">

<name>Cordova sqlcipher adapter</name>

Expand Down
4 changes: 2 additions & 2 deletions spec/www/spec/legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -950,8 +950,7 @@ var mytests = function() {

});

// NOTE [BUG #230]: this is now working if we do not depend on a valid sqlite_master table
// XXX TODO: test with and without transaction callbacks, also with empty db.readTransaction()
/* XXX MOVED:
test_it(suiteName + 'empty transaction (no sql statements) and then SELECT transaction', function () {
stop(2);
Expand Down Expand Up @@ -981,6 +980,7 @@ var mytests = function() {
start();
});
});
** */

test_it(suiteName + ' test simultaneous transactions, different dbs', function () {
stop();
Expand Down
140 changes: 140 additions & 0 deletions spec/www/spec/simple-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,146 @@ var mytests = function() {
// FUTURE TODO ref: litehelpers/Cordova-sqlite-storage#232
// test case of sql error handler returning values such as "true" (string), 1, 0, null


it(suiteName + 'empty transaction (no callback argument) and then SELECT transaction', function (done) {

var db = openDatabase("tx-with-no-argment", "1.0", "Demo", DEFAULT_SIZE);

try {
// synchronous error expected:
db.transaction();

// not expected to get here:
expect(false).toBe(true);
} catch (err) {
// got error like we expected
expect(true).toBe(true);
}

// verify we can still continue
var gotStringLength = false; // poor man's spy
db.transaction(function (tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (tx, res) {
expect(res.rows.item(0).stringlength).toBe(10);
gotStringLength = true;
});
}, function (error) {
// not expected:
expect(false).toBe(true);
}, function () {
// expected result (transaction committed ok)
expect(true).toBe(true);
expect(gotStringLength).toBe(true);
done();
});
});

it(suiteName + 'empty readTransaction (no callback argument) and then SELECT transaction', function (done) {

var db = openDatabase("read-tx-with-no-argment", "1.0", "Demo", DEFAULT_SIZE);

try {
// synchronous error expected:
db.readTransaction();

// not expected to get here:
expect(false).toBe(true);
} catch (err) {
// got error like we expected
expect(true).toBe(true);
}

// verify we can still continue
var gotStringLength = false; // poor man's spy
db.readTransaction(function (tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (tx, res) {
expect(res.rows.item(0).stringlength).toBe(10);
gotStringLength = true;
});
}, function (error) {
// not expected:
expect(false).toBe(true);
}, function () {
// expected result (transaction committed ok)
expect(true).toBe(true);
expect(gotStringLength).toBe(true);
done();
});
});

it(suiteName + 'empty transaction (no sql statements) and then SELECT transaction', function (done) {

var db = openDatabase("empty-tx", "1.0", "Demo", DEFAULT_SIZE);

db.transaction(function(tx) {
expect(true).toBe(true);
}, function(err) {
// not expected:
expect(false).toBe(true);
done();
}, function() {
// as expected:
expect(true).toBe(true);

// verify we can still continue
var gotStringLength = false; // poor man's spy
db.transaction(function (tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (tx, res) {
expect(res.rows.item(0).stringlength).toBe(10);
gotStringLength = true;
});
}, function (error) {
// not expected:
expect(false).toBe(true);
}, function () {
// expected result (transaction committed ok)
expect(true).toBe(true);
expect(gotStringLength).toBe(true);
done();
});

});

});

// Check fix for litehelpers/Cordova-sqlite-storage#409:
it(suiteName + 'empty readTransaction (no sql statements) and then SELECT transaction', function (done) {

var db = openDatabase("empty-read-tx", "1.0", "Demo", DEFAULT_SIZE);

db.readTransaction(function(tx) {
expect(true).toBe(true);
}, function(err) {
// not expected:
expect(false).toBe(true);
done();
}, function() {
// as expected:
expect(true).toBe(true);

// verify we can still continue
var gotStringLength = false; // poor man's spy
db.transaction(function (tx) {
tx.executeSql("SELECT LENGTH('tenletters') AS stringlength", [], function (tx, res) {
expect(res.rows.item(0).stringlength).toBe(10);
gotStringLength = true;
});
}, function (error) {
// not expected:
expect(false).toBe(true);
}, function () {
// expected result (transaction committed ok)
expect(true).toBe(true);
expect(gotStringLength).toBe(true);
done();
});

});

});



if (!isWebSql) {
// NOTE: this was an issue due to the inconsistency ng cordova documentation and source code which
// triggered problems reported in litehelpers/Cordova-sqlite-storage#246 and
Expand Down
2 changes: 2 additions & 0 deletions www/SQLitePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,8 @@
this.addStatement("BEGIN", [], null, function(tx, err) {
throw newSQLError("unable to begin transaction: " + err.message, err.code);
});
} else {
this.addStatement("SELECT 1", [], null, null);
}
};

Expand Down

0 comments on commit 35de640

Please sign in to comment.