emilsjolander / sprinkles

Sprinkles is a boiler-plate-reduction-library for dealing with databases in android applications
Apache License 2.0
772 stars 84 forks source link

Get SQLException if anything happened when inserting #89

Open a-thomas opened 9 years ago

a-thomas commented 9 years ago

Hi there,

When inserting in db, the Transaction uses SQLLiteDatabase.insert() method, so Transaction returns -1 if any errors occured. It might be interesting to replace it by SQLLiteDatabase.insertOrThrow() which is the same but without catching SQLException.

public long insert(String table, String nullColumnHack, ContentValues values) {
        try {
            return insertWithOnConflict(table, nullColumnHack, values, CONFLICT_NONE);
        } catch (SQLException e) {
            Log.e(TAG, "Error inserting " + values, e);
            return -1;
        }
    }

Replacing it could be dangerous for current Sprinkles users when it comes to upgrade. It should be more clever to provide an alternative way of saving the Transaction.

It should be helpful in case you want to figure out the origin of an error in production as Log.e() is unusable.