check again after dropping the db and recreating it. if you're using sqlite 
and that field(..., 'integer') was a string before, for a well known and 
very well documented bug of sqlite, that behaviour will happen.

db.define_table('a_table', Field('a_field', 'integer'))
db.a_table.insert(a_field=1)
db(db.a_table.id > 0).update(a_field = db.a_table.a_field + 1)

will make a_field == 2.

On Wednesday, May 28, 2014 11:03:59 AM UTC+2, Mirko wrote:
>
> I never updated data this way before, and after having made some tests, it 
> turns out that db.table.lft type is a Field that is converted into a string 
> and then an integer later (I don't know how).
>
> And I try the example from the book 
> db(db.table.lft>0).update(lft=db.table.lft+1) appends the string '1' to the 
> value (casted to string) of db.table.lft (this seems very weird to me 
> because db.table.lft type is Field)
>
> For example if db.table.lft (Field, type int) row value is 12345, 
> db.table.lft+1 after db update will give 123451
>
> Or am I missing something ?
>
>
> On Wednesday, May 28, 2014 8:21:56 AM UTC, Marian wrote:
>>
>> I want to negate a value with this expression:
>>
>> db(db.table.lft > 0).update(lft = 0 - db.table.lft)
>>
>> but I get the following TypeError:
>> TypeError: unsupported operand type(s) for -: 'int' and 'Field'
>>
>> My workaround is:
>> db(db.table.lft > 0).update(lft = db.table.lft - db.table.lft - db.table.lft)
>>
>>
>> *It seems that update expression need to start with the field or do I miss 
>> something?*
>>
>>

-- 
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