no no no.
db(query).update(field=expression)
expression is not a python expression but an DAL expression that gets
translated into SQL.
This is wrong
db4.data_table.FreezeTime=datetime.strptime(db4.data_table.ReqTime.split(".")
[0], "%Y-%m-%dT%H:%M:%S")
because it assumes it gets evaluated by Python and not by the
database.
The only operators that web2py DAL can stranlated into SQL are those
supported by SQL:
a=b+c
a=b-c
a=b*c
a=b/c
a=b[c:d]
a=b.year()
a=b.day()
a=b.month()
a=b.hour()
a=b.minutes()
a=b.seconds()
and combinations therefore.
You can also do
from gluon.sql import Expression
db(...).update(field=Expression('...sql expression..')
and you can use any sql expression.
This is documented in the book.
On Nov 20, 12:43 pm, Lorin Rivers <[email protected]> wrote:
> What about using a function? I need run db.table.field through split (the
> time part has too many decimal places) and then convert from string to time
>
> Here's what I tried:
> db4((db4.data_table.ReqTime >="2010-11-08T22:09:00") &
> (db4.data_table.ReqTime < "2010-11-08T22:09:10") & (db4.data_table.MacAddr ==
> "00000000000000DF")).update(db4.data_table.FreezeTime=datetime.strptime(db4.data_table.ReqTime.split(".")[0],
> "%Y-%m-%dT%H:%M:%S"))
>
> and got:
> AttributeError: 'Field' object has no attribute 'split'
>
> On Nov 20, 2010, at 11:40 , mdipierro wrote:
>
> > something like this?
>
> > db(query).update(field1=db.table.field2+db.table.field3)
>
> > Massimo
>
> --
> Lorin Rivers
> Mosasaur: Killer Technical Marketing <http://www.mosasaur.com>
> <mailto:[email protected]>
> 512/203.3198 (m)