On Thursday, December 28, 2017 at 11:22:25 AM UTC-5, Jordan Ladora wrote:
>
> Hi,
>
> I'm using postgres and have a table-
>
> db.define_table('volumes',
> Field('vol', 'decimal(100, session.decplaces)', default=0,
> readable=False, writable=False),
> auth.signature, migrate=True,
> )
>
Notice that 'decimal(100, session.decplaces)' is a string literal, not
Python code calling a decimal() function. The string literal is parsed by
the DAL, extracting the strings "100" and "session.decplaces", expecting
each to be interpretable as an integer. Of course, the string
"session.decplaces" is not an integer, so you get an error. Instead, you
have to create a string that includes the relevant integer value:
'decimal(100, %s)' % session.decplaces
which will ultimately generate the string:
'decimal(100, 7)'
Generally, though, storing the number of decimal places in a session
variable is probably not a good idea. Presumably you are using the session
because you want to allow different user sessions to have different numbers
of decimal places. But that doesn't work because the decimal places can
affect the database schema (depending on the database) -- so every time a
different user makes a request, you'll end up running a database migration
if migrations are turned on, or otherwise there will be no point to
specifying the different decimal places if migrations are turned off. Pick
one decimal place and use it for all users (which means there is no reason
to store it in the session).
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.