for future references: 

issuing db.commit() is necessary only if you're using DAL outside web2py. 
As soon as the function in the controller is executed, a db.commit() is 
issued automatically as long as no exceptions are thrown.

query = db(db.table.field1=='What I am looking for')
query.update(field2='hello')   
rows = query.select()
row = rows[0]
row.update_record()

works ok, although there is no need for the last 3 lines to be executed.

query = db(db.table.field1=='What I am looking for')
deletedRow = query.delete()

works fine also.


On Sunday, December 30, 2012 11:49:05 AM UTC+1, Wonton wrote:
>
> Hello viniciusban!
>
> The line "db.commit()" solved these 2 problems, thank you very much!
>
> Regarding to why I used "update_record()" without parameters, I took it 
> from an example I saw on Internet, maybe the example was wrong or maybe 
> (probably) I missunderstood the example.
>
> Thank you very much again!
>
> El domingo, 30 de diciembre de 2012 01:57:15 UTC+1, viniciusban escribió:
>>
>> On Sat, Dec 29, 2012 at 10:19 PM, Wonton <[email protected]> wrote: 
>> > Hello everyone and happy new year! 
>>
>> Hi. 
>>
>> > 
>> > I'm having an issue regarding the updating and deletion of a row in my 
>> > tables and I can't find any solution, so I hope you can help me. 
>> > 
>> > 1) Regarding to the update: 
>> > As far as I know, to update a row I should do something like this: 
>> >    query = db(db.table.field1=='What I am looking for') 
>> >    query.update(field2='hello') 
>> >    rows = query.select() 
>>
>> Issue a db.commit() here 
>>
>> > 
>> >    row = rows[0] 
>> >    row.update_record() 
>> > 
>> > But this is not working, it doesn't update the row. 
>>
>> Probably you have a transaction issue. 
>>
>> BTW, your update_record() doesn't change any field content. What are 
>> you trying to do with it? 
>>
>>
>> > 
>> > So, I'm confused about the use of update and update_record, is ok if I 
>> only 
>> > use update(...)? 
>>
>> Actually, update() would be preferred over update_record() because it 
>> generates a SQL UPDATE statement. On the other hand, update_record() 
>> generates a SQL UPDATE after the record has been read, via SQL SELECT. 
>>
>> Thinking "transactionally", you should use update() all the time. 
>> update_record() would be for a few situations. 
>>
>> > 
>> > 2) Regarding to the delete: 
>> > I'm deleting a row with this code: 
>> >     query = db(db.table.field1=='What I am looking for') 
>> >     deletedRow = query.delete() 
>>
>> Again, try to db.commit() here, after query.delete() 
>>
>> > The problem is that if I open this table with Database AppAdmin and 
>> refresh 
>> > it, the (supposed deleted) row is still there. 
>> > Is the row really deleted, I guess not, so what could I be doing wrong? 
>>
>> Remind Web2py issues an automatic db.commit() at the end of every 
>> succesful request, but if you're in Web2py shell, there's no "end of 
>> request". So, you should db.commit() by yourself. 
>>
>

-- 



Reply via email to