Fix #18/#38: insertId for INSERT reported for Android

This commit is contained in:
Chris Brody 2012-08-04 15:10:10 +02:00
parent 6194a6b4fc
commit 7a93d8d849
2 changed files with 15 additions and 6 deletions

View File

@ -158,10 +158,19 @@ public class SQLitePlugin extends Plugin {
query = queryarr[i]; query = queryarr[i];
params = paramsarr[i]; params = paramsarr[i];
query_id = queryIDs[i]; query_id = queryIDs[i];
Cursor myCursor = this.myDb.rawQuery(query, params); if (query.toLowerCase().startsWith("insert")) {
SQLiteStatement myStatement = this.myDb.compileStatement(query);
long insertId = myStatement.executeInsert();
this.processResults(myCursor, query_id, tx_id); //String result = "[{'insertId':'" + insertId + "'}]";
myCursor.close(); String result = "{'insertId':'" + insertId + "'}";
this.sendJavascript("SQLitePluginTransaction.queryCompleteCallback('" + tx_id + "','" + query_id + "', " + result + ");");
} else {
Cursor myCursor = this.myDb.rawQuery(query, params);
this.processResults(myCursor, query_id, tx_id);
myCursor.close();
}
} }
this.myDb.setTransactionSuccessful(); this.myDb.setTransactionSuccessful();
} }

View File

@ -206,8 +206,8 @@ Make a change like this to index.html to run a small test program to verify the
+ tx.executeSql('CREATE TABLE IF NOT EXISTS test_table (id integer primary key, data text, data_num integer)'); + 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) { + tx.executeSql("INSERT INTO test_table (data, data_num) VALUES (?,?)", ["test", 100], function(tx, res) {
+ console.log("insertId: " + res.insertId + " -- probably 1"); + console.log("insertId: " + res.insertId + " -- probably 1"); // check #18/#38 is fixed
+ alert("insertId: " + res.insertId + " -- should be valid"); // reproduce #18/#38 + alert("insertId: " + res.insertId + " -- should be valid");
+ +
+ db.transaction(function(tx) { + db.transaction(function(tx) {
+ tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) { + tx.executeSql("SELECT data_num from test_table;", [], function(tx, res) {