From b522d4f0a828aad2037b68cfc16beef4284d33c0 Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Sun, 25 Sep 2016 12:34:25 +0200 Subject: [PATCH 1/2] db-tx-sql-select-value-test.js based on rename of db-tx-sql-results.js --- .travis.yml | 2 +- circle.yml | 2 +- spec/www/index.html | 2 +- .../{db-tx-sql-results.js => db-tx-sql-select-value-test.js} | 0 4 files changed, 3 insertions(+), 3 deletions(-) rename spec/www/spec/{db-tx-sql-results.js => db-tx-sql-select-value-test.js} (100%) diff --git a/.travis.yml b/.travis.yml index 5b8a67a30..93f1aeed6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ script: - date && cordova-paramedic --platform ios --plugin ${TRAVIS_BUILD_DIR} || echo error-ignored - date && cp ${SPEC_WWW_DIR}/spec/self-test.js ${TESTS_PATH} && ${CORDOVA_PARAMEDIC_CMD} - date && cp ${SPEC_WWW_DIR}/spec/db-tx-string-test.js ${TESTS_PATH} && ${CORDOVA_PARAMEDIC_CMD} - - date && cp ${SPEC_WWW_DIR}/spec/db-tx-sql-results.js ${TESTS_PATH} && ${CORDOVA_PARAMEDIC_CMD} + - date && cp ${SPEC_WWW_DIR}/spec/db-tx-sql-select-value-test.js ${TESTS_PATH} && ${CORDOVA_PARAMEDIC_CMD} - date && cp ${SPEC_WWW_DIR}/spec/db-sql-operations-test.js ${TESTS_PATH} && ${CORDOVA_PARAMEDIC_CMD} - date && cp ${SPEC_WWW_DIR}/spec/sql-batch-test.js ${TESTS_PATH} && ${CORDOVA_PARAMEDIC_CMD} - date && cp ${SPEC_WWW_DIR}/spec/db-tx-sql-features-test.js ${TESTS_PATH} && ${CORDOVA_PARAMEDIC_CMD} diff --git a/circle.yml b/circle.yml index de7dc54ec..86e9df86e 100644 --- a/circle.yml +++ b/circle.yml @@ -22,7 +22,7 @@ test: - cordova-paramedic --platform android --plugin . || echo error-ignored - cp $SPEC_ROOT/spec/self-test.js $TESTS_PATH && $CORDOVA_PARAMEDIC_CMD - cp $SPEC_ROOT/spec/db-tx-string-test.js $TESTS_PATH && $CORDOVA_PARAMEDIC_CMD - - cp $SPEC_ROOT/spec/db-tx-sql-results.js $TESTS_PATH && $CORDOVA_PARAMEDIC_CMD + - cp $SPEC_ROOT/spec/db-tx-sql-select-value-test.js $TESTS_PATH && $CORDOVA_PARAMEDIC_CMD - cp $SPEC_ROOT/spec/db-sql-operations-test.js $TESTS_PATH && $CORDOVA_PARAMEDIC_CMD - cp $SPEC_ROOT/spec/sql-batch-test.js $TESTS_PATH && $CORDOVA_PARAMEDIC_CMD - cp $SPEC_ROOT/spec/db-tx-sql-features-test.js $TESTS_PATH && $CORDOVA_PARAMEDIC_CMD diff --git a/spec/www/index.html b/spec/www/index.html index 75731f49c..3b9c419a2 100644 --- a/spec/www/index.html +++ b/spec/www/index.html @@ -22,7 +22,7 @@ - + diff --git a/spec/www/spec/db-tx-sql-results.js b/spec/www/spec/db-tx-sql-select-value-test.js similarity index 100% rename from spec/www/spec/db-tx-sql-results.js rename to spec/www/spec/db-tx-sql-select-value-test.js From e2aca272390d1d265134acea08e7f40126d8c2cf Mon Sep 17 00:00:00 2001 From: "Christopher J. Brody" Date: Sun, 25 Sep 2016 12:34:57 +0200 Subject: [PATCH 2/2] remove other tests from db-tx-sql-select-value-test.js --- spec/www/spec/db-tx-sql-select-value-test.js | 953 +------------------ 1 file changed, 1 insertion(+), 952 deletions(-) diff --git a/spec/www/spec/db-tx-sql-select-value-test.js b/spec/www/spec/db-tx-sql-select-value-test.js index a61d8ef0e..8eafc9ca2 100644 --- a/spec/www/spec/db-tx-sql-select-value-test.js +++ b/spec/www/spec/db-tx-sql-select-value-test.js @@ -23,7 +23,7 @@ var mytests = function() { for (var i=0; i In SQLite, a column with type INTEGER PRIMARY KEY is an alias for the ROWID - // and - // > If the table is initially empty, then a ROWID of 1 is used. - expect(rs.insertId).toBe(1); - expect(rs.rowsAffected).toBe(1); - - // Plugin DEVIATION: - // rs.insertId & res.rowsAffected should be immutable - // ref: https://www.w3.org/TR/webdatabase/#database-query-results - rs.insertId = 2; - rs.rowsAffected = 3; - if (isWebSql) { - expect(rs.insertId).toBe(1); - expect(rs.rowsAffected).toBe(1); - } else { - expect(rs.insertId).toBe(2); - expect(rs.rowsAffected).toBe(3); - } - - db.transaction(function(tx) { - // second tx object: - expect(tx).toBeDefined(); - - tx.executeSql('SELECT COUNT(id) AS cnt FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).cnt).toBe(1); - }); - - tx.executeSql('SELECT data_num FROM test_table;', [], function(tx, rs) { - ++check_count; - - expect(rs.rows.length).toBe(1); - expect(rs.rows.item(0).data_num).toBe(100); - - // Plugin DEVIATION: - // rs.rows.length should be immutable - // ref: https://www.w3.org/TR/webdatabase/#database-query-results - rs.rows.length = 2; - if (isWebSql) { - expect(rs.rows.length).toBe(1); - } else { - expect(rs.rows.length).toBe(2); - } - }); - - tx.executeSql('SELECT data FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data).toBe('test'); - store_data_text = res.rows.item(0).data; - expect(store_data_text).toBe('test'); - }); - - tx.executeSql('UPDATE test_table SET data_num = ? WHERE data_num = 100', [101], function(tx, res) { - ++check_count; - - expect(res.rowsAffected).toBe(1); - }); - - tx.executeSql('SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data_num).toBe(101); - }); - - tx.executeSql('SELECT * FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data_num).toBe(101); - expect(res.rows.item(0).data).toBe('test'); - - store_rows = res.rows; - expect(store_rows.item(0).data_num).toBe(101); - expect(store_rows.item(0).data).toBe('test'); - }); - - tx.executeSql('SELECT * FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(store_rows.item(0).data_num).toBe(101); - expect(store_rows.item(0).data).toBe('test'); - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data_num).toBe(101); - expect(res.rows.item(0).data).toBe('test'); - - store_row_item = res.rows.item(0); - expect(store_row_item.data_num).toBe(101); - expect(store_row_item.data).toBe('test'); - }); - - tx.executeSql('SELECT * FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - - expect(res.rows.item(0).data_num).toBe(101); - expect(res.rows.item(0).data).toBe('test'); - - var temp1 = res.rows.item(0); - var temp2 = res.rows.item(0); - - expect(temp1.data).toBe('test'); - expect(temp2.data).toBe('test'); - - // Object from rows.item is immutable in Android/iOS WebKit Web SQL but NOT in this plugin: - temp1.data = 'another'; - - if (isWebSql) { - // Web SQL STANDARD: - // 1. this is a native object that is NOT affected by the change: - expect(temp1.data).toBe('test'); - // 2. object returned by second resultSet.rows.item call not affected: - expect(temp2.data).toBe('test'); - } else { - // PLUGIN: - // 1. DEVIATION - temp1 is just like any other Javascript object: - expect(temp1.data).toBe('another'); - // 2. DEVIATION - same object is returned by second resultSet.rows.item IS affected: - expect(temp2.data).toBe('another'); - } - }); - - tx.executeSql("DELETE FROM test_table WHERE data LIKE 'tes%'", [], function(tx, res) { - ++check_count; - - expect(res.rowsAffected).toBe(1); - }); - - tx.executeSql('SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(0); - }); - - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }, function() { - console.log('second tx ok success cb'); - expect(check_count).toBe(10); - - expect(store_rows.item(0).data).toBe('test'); - - expect(store_data_text).toBe('test'); - expect(store_row_item.data).toBe('test'); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }); - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - // not check_counted: - //}, function() { - // console.log('first tx success cb OK'); - }); - - }, MYTIMEOUT); - - it(suiteName + 'tx sql starting with extra space results test', function(done) { - if (isWP8) pending('BROKEN for WP8'); - - var db = openDatabase('tx-sql-starting-with-extra-space-results-test.db', '1.0', 'Test', DEFAULT_SIZE); - - expect(db).toBeDefined(); - - var check_count = 0; - - db.transaction(function(tx) { - // first tx object: - expect(tx).toBeDefined(); - - tx.executeSql('DROP TABLE IF EXISTS test_table'); - tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)'); - - tx.executeSql(' INSERT INTO test_table (data, data_num) VALUES (?,?)', ['test', 100], function(tx, res) { - // check tx & res object parameters: - expect(tx).toBeDefined(); - expect(res).toBeDefined(); - - expect(res.insertId).toBeDefined(); - expect(res.rowsAffected).toBe(1); - - db.transaction(function(tx) { - // second tx object: - expect(tx).toBeDefined(); - - tx.executeSql(' SELECT COUNT(id) AS cnt FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).cnt).toBe(1); - }); - - tx.executeSql(' SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data_num).toBe(100); - }); - - tx.executeSql(' SELECT data FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data).toBe('test'); - }); - - tx.executeSql(' UPDATE test_table SET data_num = ? WHERE data_num = 100', [101], function(tx, res) { - ++check_count; - - expect(res.rowsAffected).toBe(1); - }); - - tx.executeSql(' SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data_num).toBe(101); - }); - - tx.executeSql(" DELETE FROM test_table WHERE data LIKE 'tes%'", [], function(tx, res) { - ++check_count; - - expect(res.rowsAffected).toBe(1); - }); - - tx.executeSql(' SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(0); - }); - - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }, function() { - console.log('second tx ok success cb'); - expect(check_count).toBe(7); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }); - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }); - - }, MYTIMEOUT); - - it(suiteName + 'tx sql starting with extra semicolon results test', function(done) { - // [BUG #458] BROKEN for androidDatabaseImplementation: 2 (built-in android.database) setting - if (isWP8) pending('BROKEN for WP8'); - if (isAndroid && isImpl2) pending('BROKEN for androidDatabaseImplementation: 2 (built-in android.database) setting'); - - var db = openDatabase('tx-sql-starting-with-extra-semicolon-results-test.db', '1.0', 'Test', DEFAULT_SIZE); - - expect(db).toBeDefined(); - - var check_count = 0; - - db.transaction(function(tx) { - // first tx object: - expect(tx).toBeDefined(); - - tx.executeSql(';DROP TABLE IF EXISTS test_table'); - tx.executeSql('; CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)'); - - tx.executeSql(';INSERT INTO test_table (data, data_num) VALUES (?,?)', ['test', 100], function(tx, res) { - // check tx & res object parameters: - expect(tx).toBeDefined(); - expect(res).toBeDefined(); - - expect(res.insertId).toBeDefined(); - expect(res.rowsAffected).toBe(1); - - db.transaction(function(tx) { - // second tx object: - expect(tx).toBeDefined(); - - tx.executeSql(';SELECT COUNT(id) AS cnt FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).cnt).toBe(1); - }); - - tx.executeSql('; SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data_num).toBe(100); - }); - - tx.executeSql(';; SELECT data FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data).toBe('test'); - }); - - tx.executeSql('; ;UPDATE test_table SET data_num = ? WHERE data_num = 100', [101], function(tx, res) { - ++check_count; - - expect(res.rowsAffected).toBe(1); - }); - - tx.executeSql(' ; SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(1); - expect(res.rows.item(0).data_num).toBe(101); - }); - - tx.executeSql(";DELETE FROM test_table WHERE data LIKE 'tes%'", [], function(tx, res) { - ++check_count; - - expect(res.rowsAffected).toBe(1); - }); - - tx.executeSql('; SELECT data_num FROM test_table;', [], function(tx, res) { - ++check_count; - - expect(res.rows.length).toBe(0); - }); - - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }, function() { - console.log('second tx ok success cb'); - expect(check_count).toBe(7); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }); - }, function(e) { - // not expected: - expect(false).toBe(true); - expect(JSON.stringify(e)).toBe('---'); - done(); - }); - - }, MYTIMEOUT); - - describe(scenarioList[i] + ': NON-standard Multi-row INSERT with parameters (post-sqlite 3.6 feature)]', function() { - - it(suiteName + 'Multi-row INSERT with parameters - DEVIATION: (post-sqlite 3.6 feature)' + - ((!isWebSql && isAndroid && isImpl2) ? - ' [SQLResultSet.rowsAffected BROKEN for androidDatabaseImplementation: 2 (built-in android.database)]' : - ''), function(done) { - if (isWP8) pending('SKIP: NOT SUPPORTED for WP8'); - if (isWebSql && isAndroid) pending('SKIP for Android Web SQL'); // FUTURE TBD (??) - - var db = openDatabase('Multi-row-INSERT-with-parameters-test.db', '1.0', 'Test', DEFAULT_SIZE); - - db.transaction(function(tx) { - tx.executeSql('DROP TABLE IF EXISTS TestTable;'); - tx.executeSql('CREATE TABLE TestTable (x,y);'); - - tx.executeSql('INSERT INTO TestTable VALUES (?,?),(?,?)', ['a',1,'b',2], function(ignored1, rs1) { - expect(rs1).toBeDefined(); - expect(rs1.insertId).toBeDefined(); - expect(rs1.insertId).toBe(2); - if (isWebSql || !(isAndroid && isImpl2)) // [rowsAffected BROKEN for built-in (AOSP) android.database] - expect(rs1.rowsAffected).toBe(2); - else - expect(rs1.rowsAffected).toBe(1); // [ACTUAL (BROKEN) for built-in (AOSP) android.database] - - tx.executeSql('SELECT * FROM TestTable', [], function(ignored, resultSet) { - // EXPECTED (CORRECT RESULT): - expect(resultSet.rows.length).toBe(2); - expect(resultSet.rows.item(0).x).toBe('a'); - expect(resultSet.rows.item(0).y).toBe(1); - expect(resultSet.rows.item(1).x).toBe('b'); - expect(resultSet.rows.item(1).y).toBe(2); - - // Close (plugin only - always the case in this test) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }); - }, function(error) { - // NOT EXPECTED (ERROR RESULT): - expect(false).toBe(true); - expect(error.message).toBe('--'); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }, MYTIMEOUT); - }); - - describe(suiteName + 'NON-STANDARD SQL statement list test(s)', function() { - - it(suiteName + 'INSERT statement list (NOT covered by Web SQL standard) - ' + - (isWebSql ? 'Web SQL ERROR' : 'DEVIATION - PLUGIN BROKEN (with potential data loss)'), function(done) { - var db = openDatabase('INSERT-statement-list-test.db', '1.0', 'Test', DEFAULT_SIZE); - - db.transaction(function(tx) { - tx.executeSql('DROP TABLE IF EXISTS TestList;'); - tx.executeSql('CREATE TABLE TestList (data);'); - - // REJECTED by [WebKit] Web SQL; PLUGIN BROKEN with potential data loss - // FUTURE TODO: REJECT BY PLUGIN - tx.executeSql('INSERT INTO TestList VALUES (1); INSERT INTO TestList VALUES(2);'); - }, function(error) { - // ERROR RESULT (expected for Web SQL) - if (!isWebSql) - expect('Plugin behavior changed').toBe('--'); - expect(error).toBeDefined(); - expect(error.code).toBeDefined(); - expect(error.message).toBeDefined(); - - expect(error.code).toBe(5); // (SQLError.SYNTAX_ERR) - - // WebKit Web SQL error message (apparenly with SQLite error code) - if (isWebSql) - expect(error.message).toMatch(/could not prepare statement.*1 not an error/); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }, function() { - // TBD ACTUAL RESULT [PLUGIN BROKEN with possible data loss]: - if (isWebSql) - expect('Unexpected result for Web SQL').toBe('--'); - - db.transaction(function(tx2) { - tx2.executeSql('SELECT * FROM TestList', [], function(ignored, resultSet) { - // CORRECT RESULT: - //expect(resultSet.rows.length).toBe(2); - // ACTUAL RESULT for PLUGIN [BROKEN with possible parameter data loss]: - expect(resultSet.rows.length).toBe(1); - - // FIRST ROW CORRECT: - expect(resultSet.rows.item(0).data).toBe(1); - // SECOND ROW MISSING: - //expect(resultSet.rows.item(1).data).toBe(2); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }); - }); - }, MYTIMEOUT); - - it(suiteName + 'executeSql with SELECT statement list - NOT ALLOWED [PLUGIN BROKEN]', function(done) { - // TO FIX ref: https://www.sqlite.org/c3ref/prepare.html - // When calling sqlite3_prepare_v2 check the OUT pzTail pointer - // to ensure there is no other statement afterwards. - // May take some more work for Android & Windows versions. - - var db = openDatabase('tx-sql-with-select-statement-list.db'); - - db.transaction(function(tx) { - tx.executeSql('SELECT 1; SELECT 2', [], function(ignored, rs) { - // INCORRECT (PLUGIN BROKEN) - if (isWebSql) - expect('WebKit Web SQL implementation changed (DEVIATION)').toBe('--'); - else - expect(rs).toBeDefined(); - - // EXTRA for INVESTIGATION: statement list with syntax error after the first statement - tx.executeSql('SELECT 1; SLCT 2', [], function(ignored1, rs2) { - expect(rs2).toBeDefined(); - isWebSql ? done() : db.close(done, done); - }, function(ignored, error) { - expect('Plugin behavior changed, please update this test').toBe('--'); - expect(error).toBeDefined(); - // TBD ... - isWebSql ? done() : db.close(done, done); - }); - }, function(ignored, error) { - if (!isWebSql) - expect('PLUGIN FIXED, please update this test').toBe('--'); - - expect(error).toBeDefined(); - expect(error.code).toBeDefined(); - expect(error.message).toBeDefined(); - - expect(error.code).toBe(5); // (SQLError.SYNTAX_ERR) - - // WebKit Web SQL error message (apparenly with SQLite error code) - if (isWebSql) - expect(error.message).toMatch(/could not prepare statement.*1 not an error/); - - // Close (plugin only), return false, and finish: - return isWebSql ? (done() || false) : - (db.close(done, done) || false); - }) - }); - }, MYTIMEOUT); - - }); - - describe(suiteName + 'Binary BLOB data INSERT test(s)', function() { - - it(suiteName + "INSERT Binary literal BLOB data (X'010203'), check results, and check stored data HEX value", function(done) { - var db = openDatabase('Binary-literal-BLOB-data-INSERT-test.db'); - - db.transaction(function(tx) { - tx.executeSql('DROP TABLE IF EXISTS TestTable;'); - tx.executeSql('CREATE TABLE TestTable (x);'); - - tx.executeSql("INSERT INTO TestTable VALUES (X'010203')", [], function(ignored, rs1) { - // EXPECTED: CORRECT RESULT: - expect(rs1).toBeDefined(); - expect(rs1.insertId).toBe(1); - expect(rs1.rowsAffected).toBe(1); - - tx.executeSql('SELECT HEX(x) AS hex_value FROM TestTable', [], function(ignored, resultSet) { - // EXPECTED: CORRECT RESULT: - expect(resultSet).toBeDefined(); - expect(resultSet.rows).toBeDefined(); - expect(resultSet.rows.length).toBe(1); - expect(resultSet.rows.item(0).hex_value).toBe('010203'); - - // Close (plugin only - always the case in this test) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }); - }, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }, MYTIMEOUT); - - }); - - describe(suiteName + 'STANDARD multi-row INSERT tests', function() { - - it(suiteName + 'INSERT multiple rows from with SELECT; check results & check stored data [rowsAffected INCORRECT with androidDatabaseImplementation: 2 (built-in android.database) setting]', function(done) { - var db = openDatabase('INSERT-with-SELECT-test.db', '1.0', 'Test', DEFAULT_SIZE); - - db.transaction(function(tx) { - tx.executeSql('DROP TABLE IF EXISTS tt1;'); - tx.executeSql('DROP TABLE IF EXISTS tt2;'); - - tx.executeSql('CREATE TABLE tt1 (data);'); - tx.executeSql('CREATE TABLE tt2 (data);'); - - tx.executeSql('INSERT INTO tt1 VALUES (?)', ['test-value-1']); - tx.executeSql('INSERT INTO tt1 VALUES (?)', ['test-value-2']); - - // THANKS for GUIDANCE: http://www.tutorialspoint.com/sqlite/sqlite_insert_query.htm - tx.executeSql('INSERT INTO tt2 SELECT data FROM tt1;', [], function(ignored1, rs1) { - // EXPECTED (CORRECT RESULT): - expect(rs1).toBeDefined(); - - // ref: https://www.w3.org/TR/webdatabase/#dom-sqlresultset-insertid - // > If the statement inserted multiple rows, the ID of the last row must be the one returned. - // (insertId acts like sqlite3_last_insert_rowid) - expect(rs1.insertId).toBe(2); - - // [INCORRECT rowsAffected with androidDatabaseImplementation: 2 (built-in android.database) setting] - if (!(isAndroid && isImpl2)) - expect(rs1.rowsAffected).toBe(2); - else - expect(rs1.rowsAffected).toBe(1); - - tx.executeSql('SELECT * FROM tt2', [], function(ignored, rs2) { - // EXPECTED: CORRECT RESULT: - expect(rs2).toBeDefined(); - expect(rs2.rows).toBeDefined(); - expect(rs2.rows.length).toBe(2); - expect(rs2.rows.item(0).data).toBe('test-value-1'); - expect(rs2.rows.item(1).data).toBe('test-value-2'); - - // Close (plugin only - always the case in this test) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }); - }, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }, MYTIMEOUT); - - it(suiteName + 'INSERT with TRIGGER & check results [rowsAffected INCORRECT with androidDatabaseImplementation: 2 (built-in android.database) setting]', function(done) { - if (isWP8) pending('SKIP (NOT SUPPORTED) for WP8'); // NOT SUPPORTED for WP8 - - var db = openDatabase('INSERT-with-TRIGGER-test.db', '1.0', 'Test', DEFAULT_SIZE); - - db.transaction(function(tx) { - tx.executeSql('DROP TABLE IF EXISTS tt1;'); - tx.executeSql('DROP TABLE IF EXISTS tt2;'); - - tx.executeSql('CREATE TABLE tt1 (data);'); - tx.executeSql('CREATE TABLE tt2 (data);'); - - tx.executeSql('INSERT INTO tt2 VALUES (?)', ['extra1']); - tx.executeSql('INSERT INTO tt2 VALUES (?)', ['extra2']); - - // THANKS for GUIDANCE: http://www.tutorialspoint.com/sqlite/sqlite_triggers.htm - tx.executeSql("CREATE TRIGGER t1 AFTER INSERT ON tt1 BEGIN INSERT INTO tt2 VALUES(datetime('now')); END;"); - - tx.executeSql('INSERT INTO tt1 VALUES (?)', ['test-value'], function(ignored1, rs1) { - // EXPECTED (CORRECT RESULT): - expect(rs1).toBeDefined(); - - // Apparently this is the last INSERT rowid on tt1, - // NOT on tt2 - expect(rs1.insertId).toBe(1); - // [INCORRECT rowsAffected with androidDatabaseImplementation: 2 (built-in android.database) setting] - if (!(isAndroid && isImpl2)) - expect(rs1.rowsAffected).toBe(2); - else - expect(rs1.rowsAffected).toBe(1); - - tx.executeSql('SELECT COUNT(*) AS count1 FROM tt1', [], function(ignored, rs2) { - // EXPECTED: CORRECT RESULT: - expect(rs2).toBeDefined(); - expect(rs2.rows).toBeDefined(); - expect(rs2.rows.length).toBe(1); - expect(rs2.rows.item(0).count1).toBe(1); - - tx.executeSql('SELECT COUNT(*) AS count2 FROM tt2', [], function(ignored, rs3) { - // EXPECTED: CORRECT RESULT: - expect(rs3).toBeDefined(); - expect(rs3.rows).toBeDefined(); - expect(rs3.rows.length).toBe(1); - expect(rs3.rows.item(0).count2).toBe(3); - - // Close (plugin only - always the case in this test) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - - }); - }); - }, function(error) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(error.message).toBe('--'); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }, MYTIMEOUT); - - }); - - describe(suiteName + 'ALTER TABLE tests', function() { - - it(suiteName + 'ALTER TABLE ADD COLUMN test', function(done) { - var dbname = 'ALTER-TABLE-ADD-COLUMN-test.db'; - var createdb = openDatabase(dbname, '1.0', 'Test', DEFAULT_SIZE); - - createdb.transaction(function(tx) { - tx.executeSql('DROP TABLE IF EXISTS TestTable;'); - tx.executeSql('CREATE TABLE TestTable (data1);'); - - tx.executeSql('INSERT INTO TestTable VALUES (?)', ['test-value-1']); - }, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - - // Close (plugin only) & finish: - (isWebSql) ? done() : createdb.close(done, done); - }, function() { - if (isWebSql) { - addColumnTest(); - } else { - createdb.close(addColumnTest, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - }); - } - }); - - function addColumnTest() { - var db = openDatabase(dbname, '1.0', 'Test', DEFAULT_SIZE); - - db.transaction(function(tx) { - tx.executeSql('ALTER TABLE TestTable ADD COLUMN data2;'); - tx.executeSql('UPDATE TestTable SET data2=?;', ['test-value-2']); - - tx.executeSql('SELECT * FROM TestTable', [], function(ignored, resultSet) { - // EXPECTED: CORRECT RESULT: - expect(resultSet).toBeDefined(); - expect(resultSet.rows).toBeDefined(); - expect(resultSet.rows.length).toBe(1); - expect(resultSet.rows.item(0).data1).toBe('test-value-1'); - expect(resultSet.rows.item(0).data2).toBe('test-value-2'); - - // Close (plugin only - always the case in this test) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - } - }, MYTIMEOUT); - - it(suiteName + 'ALTER TABLE RENAME test', function(done) { - var dbname = 'ALTER-TABLE-RENAME-test.db'; - var createdb = openDatabase(dbname, '1.0', 'Test', DEFAULT_SIZE); - - createdb.transaction(function(tx) { - tx.executeSql('DROP TABLE IF EXISTS TestTable;'); - tx.executeSql('DROP TABLE IF EXISTS tt2;'); - tx.executeSql('CREATE TABLE TestTable (data1);'); - - tx.executeSql('INSERT INTO TestTable VALUES (?)', ['test-value-1']); - }, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - - // Close (plugin only) & finish: - (isWebSql) ? done() : createdb.close(done, done); - }, function() { - if (isWebSql) { - tableRenameTest(); - } else { - createdb.close(tableRenameTest, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - }); - } - }); - - function tableRenameTest() { - var db = openDatabase(dbname, '1.0', 'Test', DEFAULT_SIZE); - - db.transaction(function(tx) { - tx.executeSql('ALTER TABLE TestTable RENAME TO tt2;'); - - tx.executeSql('SELECT * FROM tt2', [], function(ignored, resultSet) { - // EXPECTED: CORRECT RESULT: - expect(resultSet).toBeDefined(); - expect(resultSet.rows).toBeDefined(); - expect(resultSet.rows.length).toBe(1); - expect(resultSet.rows.item(0).data1).toBe('test-value-1'); - - // Close (plugin only - always the case in this test) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - }, function(e) { - // ERROR RESULT (NOT EXPECTED): - expect(false).toBe(true); - expect(e).toBeDefined(); - - // Close (plugin only) & finish: - (isWebSql) ? done() : db.close(done, done); - }); - } - }, MYTIMEOUT); - - }); - describe(suiteName + 'Infinity value manipulation results', function() { // Android/iOS plugin BROKEN: