it will not work, update accepts values or expressions which are translated
to sql,
lambda is a function not an expression
db(db.person1.id>0).update(
visits = db.person1.visits + 1,
name = db.person1.name.capitalize(),
)
will translated in
UPDATE person1 SET visits=visits+1, name=name.capitalize() WHERE id>0
I don't think that there are sql functions to capitalize, at least not in
all databases
if you want to update only a single record then you can use python built in
capitalize function
row = db.person1[person_id]
db(db.person1.id==row.id).update(
visits = db.person1.visits + 1,
name =row.name.capitalize(),
)
On Mon, Nov 12, 2012 at 7:19 AM, Cliff Kachinske <[email protected]> wrote:
> Niphlod,
>
> Would a lambda work there?
>
> something like db.person1.name = lambda db.person1.name:
> db.person1.name.capitalize()
>
> On Saturday, November 10, 2012 1:02:42 PM UTC-5, mweissen wrote:
>>
>> I have tried this example
>>
>> def visit():
>> db(db.person1.id>0).update(
>> visits = db.person1.visits + 1,
>> )
>>
>> It is in the book and works fine.
>> Now I have added another line...
>>
>> def visit():
>> db(db.person1.id>0).update(
>> visits = db.person1.visits + 1,
>> name = db.person1.name.capitalize(),
>> )
>>
>> .. and I got an error:
>> <type 'exceptions.AttributeError'> 'Field' object has no attribute
>> 'capitalize'(1) I do not understand why it is possible to add 1 to a
>> field, but not to do something other with a string.
>>
>> (2) Is there any simple solution? Of course I could write something like
>>
>> for r in db(db.person1.id>0).select():
>> ... update ...
>>
>> Regards, Martin
>>
>> --
>
>
>
>
--