Android : Android sqlite get name of failed constraint for resolving

on Friday, August 15, 2014


During the syncing of multimaster database between android sqlite and sql server, I need to resolve failed unique constraints on android. I have already created sqlite database in android with all the primary key, foreign key and unique constraints in it.


This is an example of one sample table.



db.execSQL("CREATE TABLE " + Tables.ARTIST + " ("
+ BaseColumns._ID + " INTEGER,"
+ ArtistColumns.ID + " TEXT NULL,"
+ ArtistColumns.MODELTYPE + " TEXT NULL,"
+ ArtistColumns.NAME + " TEXT NULL,"
+ "FOREIGN KEY (" + ArtistColumns.MODELTYPE + ") " + References.MODELTYPE_ID + ","
+ "unique(" + ArtistColumns.MODELTYPE + "," + ArtistColumns.NAME + ")"
+ "PRIMARY KEY(" + ArtistColumns.ID + "))");


I am using contentprovider for database operations. In the insert method in provider, I can catch an exception for failed constraint by catching SQLiteConstraintException. But I need to know how I can get the name of unique constraint that failed so that I can resolve the conflict.


0 comments:

Post a Comment