|
| 1 | +package net.zetetic.tests; |
| 2 | + |
| 3 | +import android.database.Cursor; |
| 4 | + |
| 5 | +import net.sqlcipher.database.SQLiteDatabase; |
| 6 | +import net.sqlcipher.database.SQLiteStatement; |
| 7 | +import net.sqlcipher.database.SQLiteConstraintException; |
| 8 | + |
| 9 | +import net.zetetic.ZeteticApplication; |
| 10 | + |
| 11 | +import android.util.Log; |
| 12 | + |
| 13 | +public class ExecuteInsertConstraintErrorMessageTest extends SQLCipherTest { |
| 14 | + |
| 15 | + @Override |
| 16 | + public boolean execute(SQLiteDatabase database) { |
| 17 | + database.execSQL("CREATE TABLE tt(a UNIQUE, b)"); |
| 18 | + database.execSQL("INSERT INTO tt VALUES (101, 'Alice')"); |
| 19 | + try { |
| 20 | + SQLiteStatement insertStatement = database.compileStatement("INSERT INTO tt VALUES (101, 'Betty')"); |
| 21 | + long ignored = insertStatement.executeInsert(); |
| 22 | + } catch (SQLiteConstraintException e) { |
| 23 | + Log.v(ZeteticApplication.TAG, "EXPECTED RESULT: DID throw SQLiteConstraintException", e); |
| 24 | + String message = e.getMessage(); |
| 25 | + setMessage(message); |
| 26 | + if (!message.matches("error code 19: UNIQUE constraint failed: tt\\.a")) { |
| 27 | + Log.e(ZeteticApplication.TAG, "NOT EXPECTED: INCORRECT exception message: " + message); |
| 28 | + return false; |
| 29 | + } |
| 30 | + return true; |
| 31 | + } catch (Exception e) { |
| 32 | + Log.e(ZeteticApplication.TAG, "NOT EXPECTED: DID throw other exception", e); |
| 33 | + return false; |
| 34 | + } |
| 35 | + |
| 36 | + return false; |
| 37 | + } |
| 38 | + |
| 39 | + @Override |
| 40 | + public String getName() { |
| 41 | + return "Execute insert constraint error message Test"; |
| 42 | + } |
| 43 | +} |
0 commit comments