Reputation: 3784
I haven't used SQLite before. As far as I remember, when I was using MySQL, if I create a constraint with the option of UNIQUE
I would not receive any errors if I try to add a duplicate element.
It seems like that's not the case for SQLite.
This is how I create my Table:
// Create table for Wi-Fi Information
myDB.execSQL("CREATE TABLE IF NOT EXISTS " + WIFI_DATABASE_TABLE
+ " (WifiName VARCHAR UNIQUE);");
This is how I insert elements
if (tab == DBTable.WIFI_DATABASE) {
myDB.execSQL("INSERT INTO " + WIFI_DATABASE_TABLE
+ " (WifiName)" + SQLValues + ";");
}
My problem is when I insert the same element I am getting Column WifiName name not unique (code 19)
error. What I want is simply not to see any errors. How can I do that without playing around with catching exceptions?
Upvotes: 0
Views: 1113
Reputation: 749
The syntax for conflict resolution on an INSERT
is to use OR IGNORE
INSERT OR IGNORE INTO ...
More info: http://www.sqlite.org/lang_conflict.html
Upvotes: 1