I guess that one may want some more constraints on the autoincrement field.
For example, it shall begin at 100  for ecample.
It may be because for example, before the application exists some paper
records where made which were referenced by number < 100)

For such a problem, I've set up with:

Field('ref_number', compute=lambda r: r['id'] + 100)

Which I hope would eliminate the race solution as it is calculate upon
insertion in the database... Is it the case ?

-Mathieu



On Thu, May 27, 2010 at 23:25, mdipierro <[email protected]> wrote:

> What is wrong with the default id field that web2py creates for every
> table?
>
> On May 27, 3:16 pm, matclab <[email protected]> wrote:
> > Hello,
> >  I'm finding this message in a thread from February...
> >
> >  I thought that autoincremented field would guaranty unicity in the
> > table.
> >  I'm afraid the provided solution would allow two record to have the
> > same autonumber field (think about an access from two users at the
> > same time).
> >  I guess the autoincrement should be done on the DAL or database side,
> > inside a transaction....
> >
> >  What do you think about it ?
> >
> > On 19 jan, 21:38, Thadeus Burgess <[email protected]> wrote:
> >
> > > max_id=   db(db.table.autonumber>1).select(db.table.autonumber,  #
> > > select all records, and only pull the autonumber column
> > >                                 orderby=~db.table.autonumber, #
> > > descending sort on the autonumber, (highest first)
> > >                                 limitby=(0,1) # limit the query and
> > > only select the first record
> > >                         ).first().autonumber # pull the first record
> > > from the web2py rows object, and get its autonumber member
> >
> > > db.table.autonumber.default = max_id + 1 # Set the table default as
> > > the last autonumber and incremented by one.
> > > db.table.autonumber.writable = False
> >
> > > form = crud.create(db.table)
> >
> > > -Thadeus
> >
> > > On Tue, Jan 19, 2010 at 4:32 AM, ceriox <[email protected]> wrote:
> > > > thanks for the reply but i'm not a good web2py programmer ... i
> > > > writing my first real app
> > > > you can write the code for my request? (i can't understand the post
> of
> > > > your link)
> >
> > > > --
> > > > You received this message because you are subscribed to the Google
> Groups "web2py-users" group.
> > > > To post to this group, send email to [email protected].
> > > > To unsubscribe from this group, send email to
> [email protected]<web2py%[email protected]>
> .
> > > > For more options, visit this group athttp://
> groups.google.com/group/web2py?hl=en.
>

Reply via email to