Fix for #18 for INSERT statement ONLY for Simple-DroidGap-test

This commit is contained in:
Chris Brody 2012-05-05 22:09:01 +02:00
parent 67cd416c70
commit be6834720b
2 changed files with 15 additions and 4 deletions

View File

@ -77,6 +77,12 @@ DDB.prototype.completeQuery = function(id, data) {
var r = new DDB_Result();
r.rows.resultSet = data;
r.rows.length = data.length;
if (!!data.length && data.length > 0 && !!data[0].insertId) {
r.insertId = data[0].insertId;
}
if (!!data.length && data.length > 0 && !!data[0].rowsAffected) {
r.rowsAffected = data[0].rowsAffected;
}
try {
if (typeof query.successCallback === 'function') {
query.successCallback(query.tx, r);

View File

@ -166,8 +166,15 @@ public class SQLitePlugin extends Plugin {
* Transaction id
*/
public void executeSql(String query, String[] params, String tx_id) {
String cmd = query.toLowerCase();
try {
if (isDDL(query)) {
if (cmd.startsWith("insert")) {
SQLiteStatement myStatement = this.myDb.compileStatement(query);
long insertId = myStatement.executeInsert();
this.sendJavascript("dddb.completeQuery('" + tx_id + "', [{'insertId':'" + insertId +
"', 'rowsAffected':'1'}]);");
} else if (isDDL(query)) {
this.myDb.execSQL(query);
this.sendJavascript("dddb.completeQuery('" + tx_id + "', '');");
}
@ -240,9 +247,7 @@ public class SQLitePlugin extends Plugin {
}
// Let JavaScript know that there are no more rows
this.sendJavascript("dddb.completeQuery('" + tx_id + "', " + result
+ ");");
this.sendJavascript("dddb.completeQuery('" + tx_id + "', " + result + ");");
}
}