On May 19, 2013, at 4:39 AM, lars van gemerden <l...@rational-it.com> wrote:

> Hi all,
> 
> I generate webpages in which end-users can input data that is stored in a 
> database via sqla.The datamodel is not pre-defined but created by (other) 
> users/designers.   
> 
> My question is how can i best let the end-user know which field contains the 
> error if the end-user violates a unique constraint; e.g. if the user creates 
> an account by filling in a username/password, the username must be unique so 
> the user must get an error ("username already exists" oss) if he tries to 
> fill in an existing username.
> 
> If i commit the data, the exception thrown is somewhat cryptic (is the 
> message created by sqla or the database?). 
> 
> Some related questions:
> 
> - are there arguments in the exception i could use?
> - should i just query the table for the existence of the unique constrained 
> value (i seem to remember that is impossible in the "validate" solution, so 
> how else)?
> 
> I might be able to come up with some sort of solution, but i am looking for a 
> good/the best (structurally sound, not too slow, not overly complex) 
> solution, also useable for other constraints (e.g. non-null, maybe other 
> query/multi-record based constraints). 

the messages are generated by the database and the DBAPI in use, SQLAlchemy 
just passes them through.  There's no standardization for those messages, so if 
your target database isn't providing enough parseable information, you may need 
to do a quick query against the unique fields on the table first in order to 
produce validation logic.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to