• 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: Florijan Stamenkovic <email@hidden>
  • Date: Fri, 04 Jul 2008 15:13:35 -0400

Well, OpenBase is not covered yet, but I am working on it :) The SQL error is provided, so some regexing should do the trick. However, the code below does not extrapolate the column name from the exception, do you maybe have some code for that?

Thx,
F

On Jul 04, 2008, at 15:00, Neil MacLennan wrote:

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

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


This email sent to email@hidden

_______________________________________________ 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: Neil MacLennan <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>)
 >Re: [SOLVED] Re: DB uniqueness constraints and dealing with them (From: Neil MacLennan <email@hidden>)

  • Prev by Date: Re: [SOLVED] Re: DB uniqueness constraints and dealing with them
  • Next by Date: Re: empty relationship qualifier question
  • 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