• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: duplicate pk error: recovering from
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: duplicate pk error: recovering from


  • Subject: Re: duplicate pk error: recovering from
  • From: Art Isbell <email@hidden>
  • Date: Fri, 3 Jan 2003 09:58:54 -1000

On Friday, January 3, 2003, at 07:47  AM, Jonathan Rochkind wrote:

Let's say I know I'm about to perform an insert to the db which might result in a "cannot insert duplicate pk" excpetion. I want to CATCH this exception, and then RECOVER from it. That is, restore the EOF stack so it's not trying to insert that bad EO anymore, it just gets rid of the bad EO.

I can't quite figure out how to catch that exception,

Place editingContext.saveChanges() in a "try" block and catch a RuntimeException. The problem is that different databases create different error messages, so you'll probably have to examine the error message that your database writes and parse the exception message for the particular error message corresponding to a duplicate primary key error.


nor can I figure out how to recover from it.

editingContext.revert() will restore the editing context to its state after the last successful saveChanges(). So you might want to limit your unsaved changes to only that which might result in a duplicate primary key error.


Art
http://homepage.mac.com/aisbell/
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: String conversion with HTML entities
  • Next by Date: How shall I...?
  • Previous by thread: duplicate pk error: recovering from
  • Next by thread: How shall I...?
  • Index(es):
    • Date
    • Thread