Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check insertId in advanced rowsAffected test #802

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 76 additions & 22 deletions spec/www/spec/tx-semantics-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,51 +243,105 @@ var mytests = function() {
})
});

test_it(suiteName + 'test rowsAffected [advanced]', function () {
var db = openDatabase("RowsAffectedAdvanced", "1.0", "Demo", DEFAULT_SIZE);

stop();
it(suiteName + 'test insertId & rowsAffected [advanced]', function (done) {
var db = openDatabase('test-rowsAffected-advanced.db');

db.transaction(function (tx) {
tx.executeSql('DROP TABLE IF EXISTS characters');
tx.executeSql('CREATE TABLE IF NOT EXISTS characters (name unique, creator, fav tinyint(1))');
tx.executeSql('DROP TABLE IF EXISTS companies');
tx.executeSql('CREATE TABLE IF NOT EXISTS companies (name unique, fav tinyint(1))');

// INSERT or IGNORE with the real thing:
tx.executeSql('INSERT or IGNORE INTO characters VALUES (?,?,?)', ['Sonic', 'Sega', 0], function (tx, res) {
expect(res.rowsAffected).toBe(1);
tx.executeSql('INSERT INTO characters VALUES (?,?,?)', ['Tails', 'Sega', 0], function (tx, res) {
expect(res.rowsAffected).toBe(1);
tx.executeSql('INSERT INTO companies VALUES (?,?)', ['Sega', 1], function (tx, res) {
expect(res.rowsAffected).toBe(1);
tx.executeSql('INSERT or IGNORE INTO characters VALUES (?,?,?)', ['Sonic', 'Sega', 0], function (txIgnored, rs1) {
expect(rs1.rowsAffected).toBe(1);
expect(rs1.insertId).toBe(1);

tx.executeSql('INSERT INTO characters VALUES (?,?,?)', ['Tails', 'Sega', 0], function (txIgnored, rs2) {
expect(rs2.rowsAffected).toBe(1);
expect(rs2.insertId).toBe(2);

tx.executeSql('INSERT INTO companies VALUES (?,?)', ['Sega', 1], function (txIgnored, rs3) {
expect(rs3.rowsAffected).toBe(1);
expect(rs3.insertId).toBe(1);

// query with subquery
var sql = 'UPDATE characters ' +
' SET fav=(SELECT fav FROM companies WHERE name=?)' +
' WHERE creator=?';
tx.executeSql(sql, ['Sega', 'Sega'], function (tx, res) {
equal(res.rowsAffected, 2);
tx.executeSql(sql, ['Sega', 'Sega'], function (txIgnored, rs4) {
expect(rs4.rowsAffected).toBe(2);
try {
// defined on plugin; throws on (WebKit) Web SQL:
expect(rs4.insertId).toBeDefined();

// NOT EXPECTED to get here on (WebKit) Web SQL:
if (isWebSql) expect('(WebKit) Web SQL behavior changed').toBe('--');

expect(rs4.insertId).toBe(1);
} catch(e) {
// SHOULD NOT CATCH EXCEPTION on plugin:
if (!isWebSql) expect('EXCEPTION NOT EXPECTED on plugin').toBe('--');
// XXX TODO CHECK message, etc.
}

// query with 2 subqueries
var sql = 'UPDATE characters ' +
' SET fav=(SELECT fav FROM companies WHERE name=?),' +
' creator=(SELECT name FROM companies WHERE name=?)' +
' WHERE creator=?';
tx.executeSql(sql, ['Sega', 'Sega', 'Sega'], function (tx, res) {
equal(res.rowsAffected, 2);
// knockoffs shall be ignored:
tx.executeSql('INSERT or IGNORE INTO characters VALUES (?,?,?)', ['Sonic', 'knockoffs4you', 0], function (tx, res) {
equal(res.rowsAffected, 0);
tx.executeSql(sql, ['Sega', 'Sega', 'Sega'], function (txIgnored, rs5) {
expect(rs5.rowsAffected).toBe(2);
try {
// defined on plugin; throws on (WebKit) Web SQL:
expect(rs5.insertId).toBeDefined();

// EXPECTED to get here on plugin only:
if (isWebSql) expect('(WebKit) Web SQL behavior changed').toBe('--');

expect(rs5.insertId).toBe(1);
} catch(e) {
// SHOULD NOT CATCH EXCEPTION on plugin:
if (!isWebSql) expect('EXCEPTION NOT EXPECTED on plugin').toBe('--');
// XXX TODO CHECK message, etc.
}

start();
}, function(tx, err) {
ok(false, 'knockoff should have been ignored');

start();
// knockoffs shall be ignored:
tx.executeSql('INSERT or IGNORE INTO characters VALUES (?,?,?)', ['Sonic', 'knockoffs4you', 0], function (txIgnored, rs6) {
expect(rs6.rowsAffected).toBe(0);
// XXX TBD ???:
if (isWebSql)
expect(rs6.insertId).toBe(1);
else
expect(rs6.insertId).not.toBeDefined();

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
}, function(txIgnored, error) {
// NOT EXPECTED - knockoff should have been ignored:
expect(false).toBe(true);
expect(error.message).toBe('--');

// Close (plugin only) & finish:
(isWebSql) ? done() : db.close(done, done);
});

});

});

});

});

});

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

Expand Down