Skip to content

Commit

Permalink
Test executeSql with not enough or too many parameters; document the bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher J. Brody committed Jun 20, 2016
1 parent 5354934 commit cf7e180
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ Some other projects by [@brodybits](https://github.com/brodybits):
- It is NOT possible to open multiple databases with the same name but in different locations (iOS version).
- Incorrect or missing insertId/rowsAffected in results for INSERT/UPDATE/DELETE SQL statements with extra semicolon(s) in the beginning for Android in case the `androidDatabaseImplementation: 2` (built-in android.database implementation) option is used.
- readTransaction does *not* reject modification SQL statements with extra semicolon(s) in the beginning
- Unlike the HTML5/[Web SQL API](http://www.w3.org/TR/webdatabase/) this plugin handles executeSql calls with too few parameters without error reporting and the iOS version handles executeSql calls with too many parameters without error reporting.
- Problems reported with PhoneGap Build in the past:
- PhoneGap Build Hydration.
- Apparently FIXED: ~~PhoneGap Build may fail to build the iOS version unless the name of the app starts with an uppercase and contains no spaces (see [litehelpers/Cordova-sqlite-storage#243](https://github.com/litehelpers/Cordova-sqlite-storage/issues/243); [Wizcorp/phonegap-facebook-plugin#830](https://github.com/Wizcorp/phonegap-facebook-plugin/issues/830); [phonegap/build#431](https://github.com/phonegap/build/issues/431)).~~
Expand Down
88 changes: 85 additions & 3 deletions spec/www/spec/db-tx-value-bindings-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var mytests = function() {

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
// create columns with no type affinity
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data_text1, data_text2, data_int, data_real)');
}, function(err) {
expect(false).toBe(true);
Expand All @@ -131,7 +132,6 @@ var mytests = function() {
}, function() {
db.transaction(function(tx) {

// create columns with no type affinity
tx.executeSql("insert into test_table (data_text1, data_text2, data_int, data_real) VALUES (?,?,?,?)", ["314159", "3.14159", 314159, 3.14159], function(tx, res) {

expect(res).toBeDefined();
Expand Down Expand Up @@ -227,14 +227,14 @@ var mytests = function() {

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
// CREATE columns with no type affinity
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data1, data2)');
}, function(err) {
expect(false).toBe(true);
expect(err.message).toBe('---');

}, function() {
db.transaction(function(tx) {
// create columns with no type affinity
tx.executeSql("insert into test_table (data1, data2) VALUES (?,?)", ['abc', [1,2,3]], function(tx, res) {
expect(res).toBeDefined();
expect(res.rowsAffected).toBe(1);
Expand All @@ -256,14 +256,14 @@ var mytests = function() {

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
// create columns with no type affinity
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data1, data2)');
}, function(err) {
expect(false).toBe(true);
expect(err.message).toBe('---');

}, function() {
db.transaction(function(tx) {
// create columns with no type affinity
tx.executeSql("INSERT INTO test_table (data1, data2) VALUES (?,?)", [true, false], function(tx, rs1) {
expect(rs1).toBeDefined();
expect(rs1.rowsAffected).toBe(1);
Expand All @@ -281,6 +281,88 @@ var mytests = function() {
});
});

it(suiteName + "executeSql with not enough parameters", function(done) {
var db = openDatabase("not-enough-parameters.db", "1.0", "Demo", DEFAULT_SIZE);

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
// CREATE columns with no type affinity
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data1, data2)');

}, function(error) {
expect(false).toBe(true);
expect(error.message).toBe('---');
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);

}, function() {
db.transaction(function(tx) {
tx.executeSql("INSERT INTO test_table (data1, data2) VALUES (?,?)", ['first'], function(tx, rs1) {
// ACTUAL for plugin (Android/iOS/Windows):
if (isWebSql) expect('RESULT NOT EXPECTED for Web SQL').toBe('--');
expect(rs1).toBeDefined();
expect(rs1.rowsAffected).toBe(1);

tx.executeSql("select * from test_table", [], function(tx, rs2) {
expect(rs2.rows.length).toBe(1);
expect(rs2.rows.item(0).data1).toBe('first');
expect(rs2.rows.item(0).data2).toBeNull();
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});

}, function(error) {
// CORRECT (Web SQL):
if (!isWebSql) expect('Plugin behavior changed please update this test').toBe('--');
expect(true).toBe(true);
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});
});
});
});

it(suiteName + "executeSql with too many parameters", function(done) {
var db = openDatabase("too-many-parameters.db", "1.0", "Demo", DEFAULT_SIZE);

db.transaction(function(tx) {
tx.executeSql('DROP TABLE IF EXISTS test_table');
// CREATE columns with no type affinity
tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data1, data2)');

}, function(error) {
expect(false).toBe(true);
expect(error.message).toBe('---');
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);

}, function() {
db.transaction(function(tx) {
tx.executeSql("INSERT INTO test_table (data1, data2) VALUES (?,?)", ['first', 'second', 'third'], function(tx, rs1) {
// ACTUAL for iOS plugin:
if (isWebSql) expect('RESULT NOT EXPECTED for Web SQL').toBe('--');
expect(rs1).toBeDefined();
expect(rs1.rowsAffected).toBe(1);

tx.executeSql("select * from test_table", [], function(tx, rs2) {
expect(rs2.rows.length).toBe(1);
expect(rs2.rows.item(0).data1).toBe('first');
expect(rs2.rows.item(0).data2).toBe('second');
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});

}, function(error) {
// CORRECT (Web SQL; Android & Windows plugin):
if (!isWebSql && !isAndroid && !isWindows) expect('Plugin behavior changed please update this test').toBe('--');
expect(true).toBe(true);
// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});
});
});
});

});

describe(scenarioList[i] + ': extra tx column value binding test(s)', function() {
Expand Down

0 comments on commit cf7e180

Please sign in to comment.