Right. You've set _id as the primary key, so trying to insert a second "1" should fail.
You can just leave out the value for _id when inserting, and a new, unique one will be assigned automatically (because of autoincrement). 12.04.2011 1:41 пользователь "Art" <[email protected]> написал: > Hey all, > > I'm getting this SQLiteConstraintException (error code 19: constraint > failed) when using InsertHelper's prepareForInsert/bind/execute > methodology. I'm trying to build a table including some imported SMS > message information and I'm able to insert one entry per contact, but > then I get the error whenever I try to add another entry for the same > that contact. So 1 entry is OK, 2+ entries fails. > > For example, I have two SMSes from John Doe, so I want to grab that > info and put it in a table. e.g.: > SMS A: > ID: 1 > Name: John Doe > Number: 555-1234 > Message: Hello > > SMS B: > ID: 1 > Name: John Doe > Number: 555-1234 > Message: Goodbye > > SMS A will insert just fine, but SMS B will fail with the following: > > 04-11 14:10:07.373: ERROR/DatabaseUtils(296): Error executing > InsertHelper with table ContactTable > 04-11 14:10:07.373: ERROR/DatabaseUtils(296): > android.database.sqlite.SQLiteConstraintException: error code 19: > constraint failed > 04-11 14:10:07.373: ERROR/DatabaseUtils(296): at > android.database.sqlite.SQLiteStatement.native_execute(Native Method) > 04-11 14:10:07.373: ERROR/DatabaseUtils(296): at > android.database.sqlite.SQLiteStatement.executeInsert(SQLiteStatement.java: > 96) > 04-11 14:10:07.373: ERROR/DatabaseUtils(296): at > android.database.DatabaseUtils$InsertHelper.execute(DatabaseUtils.java: > 935) > (leaving out the rest for brevity's sake) > > FYI: I create the table by using > SQLiteDatabase.execSQL(creationString), where creationString is: > private static final String creationString = "CREATE TABLE " + > CONTACT_TABLE > + " (" + KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + NATIVE_ID > + " INTEGER DEFAULT 0," + USER_NAME + " TEXT DEFAULT NULL," > + MESSAGE + " TEXT DEFAULT NULL," + IM_TIME_STAMP + " LONG DEFAULT > 0," + ");"; > > Any ideas on why the first insertion per contact would work, but > future ones fail? I can post the code too, but it's just a loop with > prepareForInsert(); bind() x4; execute(); The InsertHelper object is > created outside the loop. > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

