On 04/06/07, Carl Franks <[EMAIL PROTECTED]> wrote:
On 04/06/07, Jonas Alves <[EMAIL PROTECTED]> wrote:
> On 04/06/07, Carl Franks <[EMAIL PROTECTED]> wrote:
> >
> > It was originally posted to the html-widget list by Jonas Alves.
> > I didn't add it to svn, but didn't get round to replying to explain
> > why - my bad!
> >
> > Unless both the form processing and any subsequent use of the form
> > input, are wrapped within a DB transaction - then the uniqueness check
> > is rather useless.
>
> Hi Carl,
> Can you please explain why is it useless? I'm using this approach in 
production
> and I'm satisfied with it.

Ok, 'useless' was a rather emotive word, but I would say it's not a
good way to do it.

The word 'transaction' should have been enough of a clue as to what's
wrong with it.

If your database of choice doesn't support transactions, then you'll
need to use a unique index on the appropriate column, and just check
for errors when you attempt the insert.

I'm using transactions, and I'm also forcing the uniqueness with
constraints at the database level.
But I like to make the check before calling the insert method. I know
that probably is redundant, and that i could check the exception
thrown to see if it's a duplicate key error. But I prefer to check
everything before trying to insert. When i reach the model everything
should be ok. If I got an exception there then something is very wrong
and the application should die.

--
Jonas

_______________________________________________
HTML-FormFu mailing list
HTML-FormFu@lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/html-formfu

Reply via email to