SQLite 更新地址簿时出错
我正在尝试找到一种修改地址簿记录的方法,该方法在所有操作系统(无论如何,3.0 之后)上都可以正常工作,并与 Google 联系人/Outlook 正确同步。
我尝试将新的电子邮件数据写入现有记录并将其写回。在 iOS4 上测试时,这几天工作得很好,我以为我已经在家干了,但我发现在 iOS 3.1.3 上,ABAddressBookSave 调用会抛出 SQLite 数据库错误,抱怨试图创建重复条目:
CPSqliteStatementPerform: constraint failed for INSERT INTO ABPerson (ROWID, First, Last, Middle, Organization, Kind, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, StoreID, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); CPSqliteStatementReset: PRIMARY KEY must be unique
当我尝试删除时旧条目并将其替换为全新条目,它会导致重复的电子邮件地址条目(我猜测这是因为同步过程将其视为新记录并尝试合并它们,也许是在与 Google 同步时
) (“iPhone 地址簿编程指南”)给出了创建和删除条目的示例,但没有提供部分更新的示例。
有什么想法吗?感谢所有建议,
干杯
Peter Johnson
Soluble Apps (www.solvableapps.com)
I am trying to find a way to amend an Address Book record which will work the same on all OSs (post 3.0, anyway) and correctly sync with Google Contacts/Outlook.
I tried writing the new email data to the existing record and writing it back out. This worked fine for several days when testing on iOS4, and I thought I was home and dry, but I found that on iOS 3.1.3 the ABAddressBookSave call throws a SQLite database error, complaining about trying to create duplicate entries:
CPSqliteStatementPerform: constraint failed for INSERT INTO ABPerson (ROWID, First, Last, Middle, Organization, Kind, Nickname, Prefix, Suffix, FirstSort, LastSort, CreationDate, ModificationDate, CompositeNameFallback, StoreID, FirstSortSection, LastSortSection, FirstSortLanguageIndex, LastSortLanguageIndex) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?); CPSqliteStatementReset: PRIMARY KEY must be unique
When I tried deleting the old entry and replacing it with an entirely new one instead, it caused duplicate email address entries (I am guessing this is because the sync process saw it as a new record and tried to merge them, maybe when synching with Google)
The Apple docs ("Address Book Programming Guide for iPhone") gives examples for creating and deleting entries, but not for partial updating.
Any ideas? All suggestions gratefully received
Cheers
Peter Johnson
Soluble Apps (www.solubleapps.com)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

看起来我自己可能已经解决了这个问题。
我在记录被更改后对其进行了 ABAddressBookAddRecord - 虽然当它是刚刚创建的新记录时这是有意义的,但当它是已更新的旧记录时,这可能是 SQL 错误的原因,创建了两个地址簿中的条目。
我仍然需要在 3.1.3 上测试这个理论(当我可以借用我兄弟的触摸:)),但我希望这对某人有帮助。
Its looking like I may have solved this myself.
I was doing ABAddressBookAddRecord on the record after it had been altered- whilst this makes sense when its a new record that has just been created, it was probably the cause of the SQL error when it was an old record that had been updated, creating two entries for it in the address book.
I still have to test this theory on 3.1.3 (when I can borrow my brother's touch :)), but I hope this helps someone.