Thanks Niphlod. I didn't knew you could do that. I will try and see how 
this works.

El viernes, 29 de noviembre de 2013 15:31:16 UTC-6, Niphlod escribió:
>
> that's the "idiotest" (does it even exist ? ) scheme ever, but alas, if 
> you need to because you're forced to, there is absolutely nothing you can 
> come up with that is backed up by most database backends.
>
> if you're going to use only backends that support *select ... for update*you 
> can use DAL's db(q).select(for_update=True) to mark a specific 
> "counter" as non-updateable by others. in that case, a simple table like
>
> id,branch_name,counter
>
> will come in handy
>
> let's create a table in a console (named A)
> db.define_table('branches', Field('branch_name'), Field('counter', 
> 'integer'))
> db.branches.insert(branch_name='A', counter=0)
> db.commit()
> db(db.branches.branch_name == 'A').select(for_update=True)
> db(db.branches.branch_name == 'A').update(counter=db.branches.counter + 1)
> ....
>
> then, on a different console (named B)
> db.define_table('branches', Field('branch_name'), Field('counter', 
> 'integer'))
> db(db.branches.branch_name == 'A').select(for_update=True)
> ....
>
> you'll notice that B "is on hold" until A issues a db.commit(). 
> That's because when you do a *select .... for update* you're holding a 
> lock on that record until you commit the transaction (in your case, you'd 
> commit AFTER assigning a new invoice number). 
> Nobody can fetch/update/delete that row until you commit()
>
> If you're willing to pay a small price in concurrency, that's the way I'd 
> go to meet your business requirements. 
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to