DB uniqueness constraints and dealing with them

2008-07-03 Thread Florijan Stamenkovic
Hi all, While reading older discussions on dealing with DB uniqueness restraints I've found out that the EOGeneralAdaptorException thrown differs among databases. Is there some generic code that deals with this in absolute terms ( don't you just *love* the word absolute being used in conj

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Florijan Stamenkovic
On Jul 03, 2008, at 12:58, Florijan Stamenkovic wrote: Hi all, While reading older discussions on dealing with DB uniqueness restraints I've found out that the EOGeneralAdaptorException thrown differs among databases. Is there some generic code that deals with this in absolute terms ( do

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Mike Schrag
While reading older discussions on dealing with DB uniqueness restraints I've found out that the EOGeneralAdaptorException thrown differs among databases. Is there some generic code that deals with this in absolute terms ( don't you just *love* the word absolute being used in conjunction wi

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Florijan Stamenkovic
On Jul 03, 2008, at 14:35, Mike Schrag wrote: While reading older discussions on dealing with DB uniqueness restraints I've found out that the EOGeneralAdaptorException thrown differs among databases. Is there some generic code that deals with this in absolute terms ( don't you just *love*

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Q
On 04/07/2008, at 2:58 AM, Florijan Stamenkovic wrote: Hi all, While reading older discussions on dealing with DB uniqueness restraints I've found out that the EOGeneralAdaptorException thrown differs among databases. Is there some generic code that deals with this in absolute terms ( do

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Jerome Chan
What about doing save -> if error check to see if existing record exists and if so throw up a duplicate error ? On Jul 4, 2008, at 7:52 AM, Q wrote: On 04/07/2008, at 2:58 AM, Florijan Stamenkovic wrote: Hi all, While reading older discussions on dealing with DB uniqueness restraints

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Lachlan Deck
On 04/07/2008, at 10:30 AM, Jerome Chan wrote: What about doing save -> if error check to see if existing record exists and if so throw up a duplicate error ? Same race condition applies. On Jul 4, 2008, at 7:52 AM, Q wrote: On 04/07/2008, at 2:58 AM, Florijan Stamenkovic wrote: Hi a

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Florijan Stamenkovic
The save -> error check is exactly what I had in mind, sorry if I was not clear about it. However, I would rather like to delete the newly saved EO, and throw a validation exception. But this is only possible if I can find the exactly same EO, once before it saved to the db, and once after.

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Lachlan Deck
On 04/07/2008, at 1:01 PM, Florijan Stamenkovic wrote: The save -> error check is exactly what I had in mind, sorry if I was not clear about it. However, I would rather like to delete the newly saved EO, and throw a validation exception. But this is only possible if I can find the exactly s

Re: DB uniqueness constraints and dealing with them

2008-07-03 Thread Chuck Hill
On Jul 3, 2008, at 9:47 PM, Lachlan Deck wrote: On 04/07/2008, at 1:01 PM, Florijan Stamenkovic wrote: The save -> error check is exactly what I had in mind, sorry if I was not clear about it. However, I would rather like to delete the newly saved EO, and throw a validation exception. But

Re: DB uniqueness constraints and dealing with them

2008-07-04 Thread Q
On 04/07/2008, at 1:01 PM, Florijan Stamenkovic wrote: The save -> error check is exactly what I had in mind, sorry if I was not clear about it. However, I would rather like to delete the newly saved EO, and throw a validation exception. But this is only possible if I can find the exactly

Re: DB uniqueness constraints and dealing with them

2008-07-04 Thread Paul Stringer
With the following I was able to get the keys and values with some regexing, but not very database independant but does work with FrontBase. It relies on the sql exception message predictably containing the key and value information. Wether other databases do I don't know but you may get so

Re: DB uniqueness constraints and dealing with them

2008-07-04 Thread Chuck Hill
I guess I will play show and tell too :-) It all starts in an EOEditingContext subclass, with the saveChanges method: public void saveChanges() { try { super.saveChanges(); } catch (EOGeneralAdaptorException e) { throw i

Re: DB uniqueness constraints and dealing with them

2008-07-08 Thread Florijan Stamenkovic
A slightly modified version of Chuck's db specific stuff, for OpenBase: public class OpenBaseExInterpreter implements ExInterpreter{ private Pattern column = Pattern.compile("column \\'(.*)\\' is not unique"), table = Pattern.compile("SQL\\: INSER

Re: DB uniqueness constraints and dealing with them

2008-07-08 Thread Florijan Stamenkovic
Uhm sorry, that was partly bad. Matcher will not find any groups unless one of the matching methods is invoked on it first... The working version of the code is: public class OpenBaseExInterpreter implements ExInterpreter{ private Pattern column = Pattern.comp

Re: DB uniqueness constraints and dealing with them

2008-07-10 Thread Susanne Schneider
Hi Florijan, be aware that your solution will only work for english installation of Oracle. Otherwise you will have custom error messages in the installation language. Regards Susanne -- Susanne Schneider Coordinator secuTrial Development iAS interActive Systems GmbH Dieffenbachstraße 33 c, D-1

Re: DB uniqueness constraints and dealing with them

2008-07-10 Thread Florijan Stamenkovic
Susane, My solution if for OpenBase only. Though I guess that the different languages issue might be applicable to it too. I'll have to check. Thx, F On Jul 10, 2008, at 04:40, Susanne Schneider wrote: Hi Florijan, be aware that your solution will only work for english installation of O

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

2008-07-04 Thread Florijan Stamenkovic
Right all, well, thanks everyone for sinking that ship of an idea down to the abyss, where it apparently belongs :) Arghhh... So, the seems to be no way to really properly handle this, is there? Paul, thanks for the code, I am currently deploying on OpenBase, I will look into what kind of

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

2008-07-04 Thread Florijan Stamenkovic
One more question though... An adapter exception *is* thrown, regardless of the database backing EOF, right? No standardized info is provided, but it is guaranteed that the exception is thrown, right??? F On Jul 04, 2008, at 11:03, Florijan Stamenkovic wrote: Right all, well, thanks everyon

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

2008-07-04 Thread Chuck Hill
On Jul 4, 2008, at 8:11 AM, Florijan Stamenkovic wrote: One more question though... An adapter exception *is* thrown, regardless of the database backing EOF, right? No standardized info is provided, but it is guaranteed that the exception is thrown, right??? Yes, that much works. On

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

2008-07-04 Thread Miguel Arroz
Hi! What I do in those situations is searching for the name of the constraint. Like: catch (EOGeneralAdaptorException saveException) { if (Util.isOptimisticLockingFailure(saveException)) { NSLog.out.appendln("saveAnswersOnSurvey - Optimistic locking failure"); } else if ( saveE

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

2008-07-04 Thread Neil MacLennan
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... try { editingContext.saveChanges(); } catch (EOGeneralAdaptorException e) { if

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

2008-07-04 Thread Florijan Stamenkovic
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 MacLen

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

2008-07-04 Thread Neil MacLennan
On 4 Jul 2008, at 20:13, Florijan Stamenkovic wrote: However, the code below does not extrapolate the column name from the exception, do you maybe have some code for that? Sadly I don't :-( The MySQL error (1062) returns a message like, "ERROR 1062 (23000): Duplicate entry 'AB1' for key 3"