yes; it's:

db.define_table('user',
                SQLField('email', 'string', length=320, notnull=True,
required=True, unique=True),
                SQLField('greet', 'boolean'),
                SQLField('day', 'string', length=2),
                SQLField('month', 'string', length=9),
                SQLField('year', 'string', length=4))

and then for FORMs I have:
db.user.email.requires=[IS_LOWER(), IS_EMAIL(), IS_NOT_IN_DB(db,
db.user.email)]
db.user.greet.requires=[IS_NOT_EMPTY()]

I can't find in the web2py framework code where the exception would be
thrown.
I'm using sqlite locally.


On May 1, 2:13 pm, mdipierro <[email protected]> wrote:
> what's the model? is unique=True in there?
>
> On 1 Mag, 05:06, Carl <[email protected]> wrote:
>
>
>
> > db.user.insert isn't throwing an exception if a duplicate record is
> > inserted but instead continues to the db.commit() instruction -- when
> > I using appadmin I can confirm that the duplicate record has been
> > added.
>
> > My insert code...
>
> > try:
> >    existingEmail = db.user.insert(email=request.vars.email,
> >                                            greet=False)
> >    db.commit()
> > except:
> >    #email record already exists
> >    ### handling code
>
> > Curiously... if I go to:
> > .../appadmin/select/db?query=db.user.id>0 then try to add a record
> > with a duplicate email address the form reports "value already in
> > database!"
>
> > This suggests that my db.py setting is okay. What am I missing in my
> > code?
>
> > Carl
>
> > On Apr 30, 7:17 pm, Carl <[email protected]> wrote:
>
> > > thanks M / very speedy concise reply.
> > > p 138/139 explains it all - sorry to have missed this detail.
>
> > > On Apr 30, 6:45 pm, mdipierro <[email protected]> wrote:
>
> > > > This
>
> > > > db.user.email.requires=[IS_NOT_EMPTY(),IS_LOWER(),IS_NOT_IN_DB
> > > > (db,db.user.email)]
>
> > > > is only enforced at the level for form validation. If you want the
> > > > database to enforce integrity
>
> > > > db.define_table('user',
>
> > > > >                 SQLField('email', 'string', length=320, unique=True),
> > > > >                 SQLField('hash','string'))
>
> > > > On Apr 30, 12:07 pm, Carl <[email protected]> wrote:
>
> > > > > I have this in my model: db.py:
>
> > > > > db.define_table('user',
> > > > >                 SQLField('email', 'string', length=320),
> > > > >                 SQLField('hash','string'))
> > > > > db.user.email.requires=[IS_NOT_EMPTY(),IS_LOWER(),IS_NOT_IN_DB(db,
> > > > > db.user.email)]
>
> > > > > In my controller: default.py:
>
> > > > > try:
> > > > > uid = db.user.insert(email=request.vars.email,
> > > > >                                    hash=converted)
> > > > > except:
> > > > >    etc...
>
> > > > > I can execute the controller code again and again with the same value
> > > > > in request.vars.email with success. I was expecting an exception to be
> > > > > throw (which I would catch) when I tried to insert an existing email
> > > > > address.
>
> > > > > What am I missing?
>
> > > > > Can anyone help?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" 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/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to