Thank you for this precision.

Now comes an other problem (I think) :
In fact I might have multiple columns with unique constraints or whatever
constraints.

Then I take a look at SQLAlchemy Exceptions, and I found that "Note that
there is no guarantee that different DB-API implementations will raise the
same exception type for any given error condition." in DBAPIError core
exceptions.

My point is that the only indicator of the origin of the error is the
exception error mesage which could be different over different databases (am
I right ?) (I made a little test over SQLite and MySQL and it appears the
messages are different).

I understand this might not be directly related to SQLAlchemy but if this
problem exists I don't really see how to deal with it.
I could make an other query to see which columns fail (this might be a
little "crappy") or try to "parse" the error message while assuming the
column name will appear inside ?


On Mon, Nov 1, 2010 at 4:27 PM, Michael Bayer <[email protected]>wrote:

> you'd want to put a unique constraint on your username column, then let the
> transaction fail, do a rollback(), report the username isn't available.   If
> you'd like to do the rollback and then continue without losing other pending
> changes, you'd use begin_nested().
>
> On Oct 31, 2010, at 3:35 PM, Guguscat wrote:
>
> > Hello,
> >
> > I am using SQLAlchemy in a Pylons project and I like it.
> >
> > However I am questioning about the best way to insert data into a
> > database.
> >
> > I have a User class mapping my user table which has a Column
> > 'username' which has a unique constraint.
> >
> > So I have a form to add a new user when I submit the form I query the
> > database to see if the 'username' is already being used.
> >
> > I think the way I'm doing it is not good in the case where I have two
> > people trying to add the same 'username' at the same time, I guess the
> > both queries will return an empty set then when comitting the sessions
> > one will go well and one will fail returning a 503 error to the user.
> >
> > So I would like instead of doing this try to flush the session and
> > catch the exception if any and find the error.
> >
> > I don't know which method is the best or if one method is wrong
> > furthermore I don't know enough about database systems and if they all
> > react the same way.
> >
> > Thanks for anyone who could give me more information about this.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> [email protected]<sqlalchemy%[email protected]>
> .
> > For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<sqlalchemy%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>

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

Reply via email to