On Tuesday, May 23, 2017 at 7:40:13 AM UTC-4, T.R.Rajkumar wrote:
>
> I solved the issue as hinted by Anthony and Dave S. 
>
> In model db.py I added this function
>
> def get_new_amcno():
>     rows =  db.executesql("exec gen_amcno_new @ucod = 
> ?,@divcod=?,@sec=?",placeholders=([session.unit,session.divn, 
> session.sec]),as_dict=True) 
>     for i in rows:
>         amcno = i['amcno']
>     return amcno
>
> And in table definition for amcno I set the default = get_new_amcno
>

First, why use db.executesql rather than a regular DAL query? Second, you 
should move the call to get_new_amcno to the controller function where you 
need to do this insert and set the defaults there -- otherwise, you are 
doing this database query on every single request to the app, even all the 
requests where it is not needed. To set the defaults after the table 
definition, just do:

db.mytable.myfield.default = 'some value'

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