• 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: [SOLVED] Re: DB uniqueness constraints and dealing with them
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [SOLVED] Re: DB uniqueness constraints and dealing with them


  • Subject: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • From: Neil MacLennan <email@hidden>
  • Date: Fri, 04 Jul 2008 20:00:40 +0100

In case anyone's building a library here... this is some code for MySQL uniqueness (with some credit to Practical WebObjects Ch 5). I think that's Frontbase, Openbase, Postgres and MySQL covered so far...

<snippet>
try {
editingContext.saveChanges();
} catch (EOGeneralAdaptorException e) {
if (isDbDuplicateKeyError(e)) {
log.error("Duplicate Key Found for: " + tx.barcode());
//... more code...
} else {
throw e;
}
} catch (er.extensions.ERXValidationException ve) {
log.error("Validation Error for: " + tx.barcode() + ". Reverting E-ticket. Not Saved. " + ve.getMessage());
editingContext.revert();
}
</snippet>



// Supporting Method
private boolean isDbDuplicateKeyError(EOGeneralAdaptorException e) {
if (e .userInfo().objectForKey(EOAdaptorChannel.FailedAdaptorOperationKey) ! = null) {
EOAdaptorOperation operation = (EOAdaptorOperation )e.userInfo().objectForKey(EOAdaptorChannel.FailedAdaptorOperationKey);
if (operation.exception() != null) {
if (operation.exception().getMessage().indexOf("error code: 1062") >= 0) {
// Duplicate Key was found. 1062 is MySQL's error code for unique constraint violation
return true;
}
}
}
return false;
}


.neilmac

On 4 Jul 2008, at 16:36, Miguel Arroz wrote:

In PostgreSQL it works. I don't know if it works on other DBs, but I suppose the error message will contain the constraint name somehow. Anyway, test it on the DBs you use

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
      • From: Florijan Stamenkovic <email@hidden>
References: 
 >DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Q <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Jerome Chan <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)
 >Re: DB uniqueness constraints and dealing with them (From: Q <email@hidden>)
 >[SOLVED] Re: DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)
 >Re: [SOLVED] Re: DB uniqueness constraints and dealing with them (From: Florijan Stamenkovic <email@hidden>)
 >Re: [SOLVED] Re: DB uniqueness constraints and dealing with them (From: Miguel Arroz <email@hidden>)

  • Prev by Date: Re: Practical Webobjects Utilities Framework
  • Next by Date: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • Previous by thread: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • Next by thread: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • Index(es):
    • Date
    • Thread