"Koen Bok" <[EMAIL PROTECTED]> writes:

> I need to have a uninterrupted number sequence in my table for
> invoices. I was trying to do it like this, but I can't get it to work.
> Can anyone give me a hint?

Let your database do the job.  It is always aware of all connections
made to it, their contexts, their priorities, what transaction isolation
level is being used, etc.

It will be better on this task.

IF you insist on doing that at your code, make the column UNIQUE (or a
PK...) and write something like this pseudocode:


    def save_data():
        def insert_data():
           try:
               unique_column_value = get_max_from_unique_column
               Class(unique_column_value + 1, 'other data')
           except YourDBExceptionForConstraintViolation:
               sleep(random.random())
               insert_data()

The 'sleep(random.random())' is there to avoid constant clashes and to
be "fair" to all connections that are inserting data on your table.



-- 
Jorge Godoy      <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
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