• 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: Handling DB Unique Constraints
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Handling DB Unique Constraints


  • Subject: Re: Handling DB Unique Constraints
  • From: Ramsey Lee Gurley <email@hidden>
  • Date: Sun, 29 Nov 2009 21:01:10 -0500

On Nov 24, 2009, at 5:21 PM, Chuck Hill wrote:

>
> On Nov 24, 2009, at 2:17 PM, Anjo Krank wrote:
>
>> Not really sure of the messages can be useful, tough, as they use the name of the constraint:
>>
>> ERROR:  duplicate key value violates unique constraint "bb"
>>
>> and not the key (postgres). So the end user probably won't know about this. But it may still be better than a real exception.
>
> Run the constraint name + entity name through the "validation exception to nice message" part of Wonder.
>
> e.g.
> LoginUser.uniqueUserName = "You have already registered under this user name."
>
> Where uniqueUserName is the constraint name.
>
>
> Chuck

That'd be awesome on 5.4.  EOEntity.indexNamed(foo).  If only I could get an index name... Look at what MySQL returns for a table with a two column unique index:

EvaluateExpression failed: <com.webobjects.jdbcadaptor._MySQLPlugIn$MySQLExpression: "INSERT INTO Parent(parentLastName, id, parentName) VALUES (?, ?, ?)" withBindings: 1:"bil-ly"(parentLastName), 2:9(id), 3:"blanks"(parentName)>:
    Next exception:SQL State:23000 -- error code: 1062 -- msg: Duplicate entry 'blanks-bil-ly' for key 2

What a disaster... Even if I wanted to parse that to construct an error message, I don't get all the keys that are required by the unique constraint. :-/

Anyway, I do have a question related to this: Is it possible to get a handle to the eo in there?  I can't find it in the db context or the throwable.  Right now, the best I can do is throw a

ERXValidationFactory.defaultFactory().createCustomException(null, "UniqueConstraintException");

and return a message like

"Could not save your changes: The value was not unique."

I suppose that's better than crashing, but it's not exactly helpful either.  Perhaps I could reconstruct the object in a disposable ec from the failed AdaptorOperation and pass that 'clone' object to the validation factory?  Or is that asking for trouble?  If I could just get "Parent.parentName.UniqueConstraintException" I could at least make a reasonable assumption about the unique constraint in some/most cases.

Ramsey

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: Handling DB Unique Constraints
      • From: Chuck Hill <email@hidden>
References: 
 >Handeling DB Unique Constraints (From: David Avendasora <email@hidden>)
 >Re: Handeling DB Unique Constraints (From: Chuck Hill <email@hidden>)
 >Re: Handeling DB Unique Constraints (From: Anjo Krank <email@hidden>)
 >Re: Handeling DB Unique Constraints (From: Anjo Krank <email@hidden>)
 >Re: Handeling DB Unique Constraints (From: Chuck Hill <email@hidden>)

  • Prev by Date: Re: Customising DisplayToMany property level components
  • Next by Date: Re: Handling DB Unique Constraints
  • Previous by thread: Re: Handeling DB Unique Constraints
  • Next by thread: Re: Handling DB Unique Constraints
  • Index(es):
    • Date
    • Thread