Yes, that makes sense.

I'd double check the data you're trying to insert and how exactly it's bound to that SQL statement - in other words, check that the code really does what you think it does.

-- Kostya

12.04.2011 5:20, Art пишет:
Oops, I was a bit too imprecise there. The ID from the SMS examples
becomes the NATIVE_ID column value. I'm not entering a new value for
the primary key for each entry at all. Does that make more sense?

On Apr 11, 3:07 pm, Kostya Vasilyev<[email protected]>  wrote:
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



--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
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

Reply via email to