Skip to content

Commit

Permalink
Fix for INSERT on Android version - working with both storesafe#120 (…
Browse files Browse the repository at this point in the history
…INSERT or IGNORE) and constraint violation error reporting
  • Loading branch information
Chris Brody committed Aug 20, 2014
1 parent cf45b7e commit a3f2cd2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/android/org/pgsqlite/SQLitePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions test-www/www/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down

0 comments on commit a3f2cd2

Please sign in to comment.