From a3f2cd2304e3c929305d50a7a78397c9a3956400 Mon Sep 17 00:00:00 2001 From: Chris Brody Date: Wed, 20 Aug 2014 21:15:13 +0200 Subject: [PATCH] Fix for INSERT on Android version - working with both #120 (INSERT or IGNORE) and constraint violation error reporting --- src/android/org/pgsqlite/SQLitePlugin.java | 19 +++++++++++-------- test-www/www/index.html | 3 +-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/android/org/pgsqlite/SQLitePlugin.java b/src/android/org/pgsqlite/SQLitePlugin.java index 0a86d175d..912d0bffc 100755 --- a/src/android/org/pgsqlite/SQLitePlugin.java +++ b/src/android/org/pgsqlite/SQLitePlugin.java @@ -384,19 +384,22 @@ private void executeSqlBatch(String dbname, String[] queryarr, JSONArray[] jsonp try { insertId = myStatement.executeInsert(); + + // statement has finished with no constraint violation: + queryResult = new JSONObject(); + if (insertId != -1) { + queryResult.put("insertId", insertId); + queryResult.put("rowsAffected", 1); + } else { + queryResult.put("rowsAffected", 0); + } } catch (SQLiteException ex) { + // report error result with the error message + // could be constraint violation or some other error ex.printStackTrace(); errorMessage = ex.getMessage(); Log.v("executeSqlBatch", "SQLiteDatabase.executeInsert(): Error=" + errorMessage); } - - queryResult = new JSONObject(); - if (insertId != -1) { - queryResult.put("insertId", insertId); - queryResult.put("rowsAffected", 1); - } else { - queryResult.put("rowsAffected", 0); - } } if (queryType == QueryType.begin) { diff --git a/test-www/www/index.html b/test-www/www/index.html index 2f6620676..6ff3acad3 100755 --- a/test-www/www/index.html +++ b/test-www/www/index.html @@ -1032,8 +1032,7 @@ }); }); - // XXX fix for #120 (INSERT or IGNORE on Android version) broke this one: - if (isWebSql || !/Android/.test(navigator.userAgent)) test(suiteName + "constraint violation", function() { + test(suiteName + "constraint violation", function() { var db = openDatabase("Constraint-violation-test.db", "1.0", "Demo", DEFAULT_SIZE); ok(!!db, "db object");