android - PRIMARY KEY must be unique exception on call update -
i getting exception when try update ma table:
this line causing crash:
rowsaffected = mdatabase.update(applicationdatabase.channels_table_name, values, channel.database_key_epg_id + " = ?", new string[] { values.getasstring(channel.database_key_epg_id) });
here how create table:
private static final string channels_table_create = "create table " + channels_table_name + " (" + basecolumns._id + " integer not null primary key, " + channel.database_key_kind + " text, " + channel.database_key_index + " integer, " + channel.database_key_name + " text, " + channel.database_key_epg_id + " text, " + channel.database_key_hashtag + " text, " + channel.database_key_image_url + " text, " + channel.database_key_logo_image_url + " text, " + channel.database_key_live_thumbnails + " integer, " + channel.database_key_blended_tv + " integer, " + channel.database_key_favorite + " integer);";
the logcat:
04-05 10:45:27.348: e/androidruntime(18041): fatal exception: thread-51422 04-05 10:45:27.348: e/androidruntime(18041): android.database.sqlite.sqliteconstraintexception: primary key must unique (code 19) 04-05 10:45:27.348: e/androidruntime(18041): @ android.database.sqlite.sqliteconnection.nativeexecuteforchangedrowcount(native method) 04-05 10:45:27.348: e/androidruntime(18041): @ android.database.sqlite.sqliteconnection.executeforchangedrowcount(sqliteconnection.java:883) 04-05 10:45:27.348: e/androidruntime(18041): @ android.database.sqlite.sqlitesession.executeforchangedrowcount(sqlitesession.java:754) 04-05 10:45:27.348: e/androidruntime(18041): @ android.database.sqlite.sqlitestatement.executeupdatedelete(sqlitestatement.java:64) 04-05 10:45:27.348: e/androidruntime(18041): @ android.database.sqlite.sqlitedatabase.updatewithonconflict(sqlitedatabase.java:1565) 04-05 10:45:27.348: e/androidruntime(18041): @ android.database.sqlite.sqlitedatabase.update(sqlitedatabase.java:1514) 04-05 10:45:27.348: e/androidruntime(18041): @ com.orange.programmetv.fr.providers.channelsprovider.update(channelsprovider.java:109) 04-05 10:45:27.348: e/androidruntime(18041): @ android.content.contentprovider$transport.update(contentprovider.java:235) 04-05 10:45:27.348: e/androidruntime(18041): @ android.content.contentresolver.update(contentresolver.java:992) 04-05 10:45:27.348: e/androidruntime(18041): @ com.orange.programmetv.fr.services.applicationservice.parsechannel(applicationservice.java:354) 04-05 10:45:27.348: e/androidruntime(18041): @ com.orange.programmetv.fr.services.applicationservice.parsechannels(applicationservice.java:339) 04-05 10:45:27.348: e/androidruntime(18041): @ com.orange.programmetv.fr.services.applicationservice.access$5(applicationservice.java:327) 04-05 10:45:27.348: e/androidruntime(18041): @ com.orange.programmetv.fr.services.applicationservice$1.work(applicationservice.java:321) 04-05 10:45:27.348: e/androidruntime(18041): @ com.orange.programmetv.fr.services.applicationservice$request.run(applicationservice.java:240) 04-05 10:45:27.348: e/androidruntime(18041): @ java.lang.thread.run(thread.java:856)
i don't understand why getting primary key must unique exception? not doing insert doing update.
in update setting (in values
) _id value used row.
don't update _id in values.
edit
or, clause matches more 1 row , values contains _id. clause violation occurs because setting same _id several rows, forbidden nature of primary key.
Comments
Post a Comment