On Tuesday, January 9, 2018 at 11:03:02 AM UTC-5, Andrea Santini wrote:
>
> i was looking on the net and solved my problem using this code:
>
>
> protocollo_ieri= db(db.protocollo.anno_registro).select().last()
> ieri = protocollo_ieri.anno_registro.year
> data = request.now
> oggi = data.year
>
> ultimo_protocollo = 
> db(db.protocollo).select(db.protocollo.numero_protocollo,orderby=~db.protocollo.numero_protocollo,limitby=(0,1)).first()
> ult_prot = ultimo_protocollo.numero_protocollo
>
> if ieri==oggi:
>     db.protocollo.numero_protocollo.default= (ult_prot +1)
> else: 
>     db.protocollo.numero_protocollo.default= 1
>
>
I think there are a couple problems with this. First, your value of 
ultimo_protocollo will end up being the maximum value across all years, but 
you only want the maximum value within the current year. Second, unless you 
lock the db.protocollo table on each of these requests, you could end up 
with a race condition where separate requests made nearly simultaneously 
both read the same current value for ieri and ultimo_protocollo and then 
end up creating separate records with identical values for 
numero_protocollo.

Anthony

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to