Trying ZODB, background in Relational: mimic auto_increment?

Thomas Guettler hv at tbz-pariv.de
Thu Aug 14 10:41:57 EDT 2008


auto increment:

> Here's one way
> 
>    class Sequence(Persistence):
>        def __init__(self):
>            self.current = 0
> 
>        def next(self):
>            self.current += 1
>            return self.current
> 
>    ticketSequence = Sequence()
> 
>    class Ticket(Persistence):
>        def __init__(self):
>            self.id = ticketSequence.next()
> 

I am sorry, but this does not work if several threads or processes
try to get a new id.

Have a look at:
http://www.zope.org/Documentation/Books/ZDG/current/Persistence.stx
"Resolving Conflicts".

BTW, that's one of the points why I switched from ZODB to Postgres.

  HTH,
    Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de



More information about the Python-list mailing list