On Sunday, January 20, 2013 10:02:37 AM UTC-8, Jeremy Evans wrote:
>
> On Sunday, January 20, 2013 9:10:43 AM UTC-8, Tim Craft wrote:
>
>> Inserting/updating records with non-unique values for columns with a 
>> unique constraint raises a Sequel::DatabaseError exception. It's difficult 
>> to separate/distinguish this error because of the common exception class 
>> and because different database adapters use different error messages. 
>> Resulting in something like this (for sqlite/postgres): 
>> https://gist.github.com/4579910
>>
>> ActiveRecord has a RecordNotUnique exception class to handle this, does 
>> Sequel have anything similar?
>>
>
> Sequel does not currently have something similar.  Database drivers 
> generally do not provide specific methods that can be called to determine 
> this, so it must be done by parsing exception messages in most cases. 
>  Sequel currently does that for disconnect detection on most adapters, and 
> it is difficult to get correct, as there are generally different messages 
> for different types of disconnects.
>
> There have been few requests for such support in the previous 5 years (I 
> can find only 1, back in 2009), so I'm not sure how many people actually 
> need this.  Most people who would need such a thing are probably using 
> models with validates_unique, and probably don't have a problem with 
> raising a regular exception if the race is lost.  That being said, it seems 
> like a useful thing to me, so I'll look into implementing it.
>

I've just pushed a commit that makes Sequel handle constraint violations by 
raising different exception classes depending on the type of constraint 
being violated (unique, check, foreign key, not null): 
https://github.com/jeremyevans/sequel/commit/3b74892e922306539fe29a37aaf895b9e102f402

Jeremy 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/sequel-talk?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to