From be6834720b55aa7161beefff95ed6c75e489db89 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Sat, 5 May 2012 22:09:01 +0200 Subject: [PATCH] Fix for #18 for INSERT statement ONLY for Simple-DroidGap-test --- Simple-DroidGap-test/assets/www/SQLitePlugin.js | 6 ++++++ .../phonegap/plugin/sqlitePlugin/SQLitePlugin.java | 13 +++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Simple-DroidGap-test/assets/www/SQLitePlugin.js b/Simple-DroidGap-test/assets/www/SQLitePlugin.js index 4ca0f06..27d128c 100644 --- a/Simple-DroidGap-test/assets/www/SQLitePlugin.js +++ b/Simple-DroidGap-test/assets/www/SQLitePlugin.js @@ -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); diff --git a/Simple-DroidGap-test/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java b/Simple-DroidGap-test/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java index 74a50f3..803cfe3 100644 --- a/Simple-DroidGap-test/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java +++ b/Simple-DroidGap-test/src/com/phonegap/plugin/sqlitePlugin/SQLitePlugin.java @@ -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 + ");"); } }