View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0003975 | SymmetricDS | Bug | public | 2019-05-22 16:47 | 2025-06-04 17:25 |
Reporter | elong | Assigned To | |||
Priority | normal | ||||
Status | acknowledged | Resolution | open | ||
Product Version | 3.8.0 | ||||
Summary | 0003975: Android SQLITE_CONSTRAINT_PRIMARYKEY | ||||
Description | User reported that an update will sometimes get 0 rows affected, which causes a fallback to an insert, which then returns SQLITE_CONSTRAINT_PRIMARYKEY because the row already exists. The call to select changes() to return the affected rows is returning 0 in some cases. Code re-implementation for AndrdoidSqlTemplate.update(SQLiteDatabase database, String sql, Object[] values, int[] types) is provided here: https://sourceforge.net/p/symmetricds/discussion/1354726/thread/664087b442/ | ||||
Tags | dialect: android | ||||
|
if (values != null) { // no longer using execSQL as not able to reliably get number of rows updated using select changes() afterward //database.execSQL(sql, toStringArray(values)); android.database.sqlite.SQLiteStatement statement = database.compileStatement(sql); //statement.bindAllArgsAsStrings(toStringArray(values)); <-- cannot bind null values for (int i = 0; i < values.length; i++) { String value = toStringArray(values)[i]; if (value != null) { statement.bindString(i+1, value); } else { statement.bindNull(i+1); } } numberRowsUpdated = statement.executeUpdateDelete(); } else { // no longer using execSQL as not able to reliably get number of rows updated using select changes() afterward //database.execSQL(sql); android.database.sqlite.SQLiteStatement statement = database.compileStatement(sql); numberRowsUpdated = statement.executeUpdateDelete(); } // For some reason neither query below is always returning the number of rows updated //int numberRowsUpdated = queryForObject(database, "select changes()", Integer.class); //long numberRowsUpdated = android.database.DatabaseUtils.longForQuery(database, "SELECT changes()", null); Log.i(TAG, "update() - number rows updated =<" + numberRowsUpdated + "> when executing SQL =<" + sql + ">"); return numberRowsUpdated; |