how to delete records from table older than 1 day?

175 views
Skip to first unread message

Amit

unread,
Jul 16, 2012, 6:12:56 AM7/16/12
to web...@googlegroups.com
Hi,
I have created table Employe with following fields:
db.define_table(
   'Employee',
   Field('created_on','datetime', default=request.now),
   Field('emp_id'),
   Field('emp_age'),
   Field('emp_address),
)
 inserting data into the table is working fine but when i am trying to delete data one day older using below command:

db.executesql('DELETE FROM db.Employee WHERE created_on < date_sub(now(), INTERVAL 1 DAY);')

It's not working and i am not getting any error also, so can anybody help me resolve this issue.
NOTE: I am using Sqlite database.


Niphlod

unread,
Jul 16, 2012, 6:25:43 AM7/16/12
to web...@googlegroups.com
Why write such a query when DAL allows you to use a more (portable, concise) pythonic way ?

import datetime
yesterday
= request.now - datetime.timedelta(days=1)
db
(db.employee.created_on < yesterday).delete()

Amit

unread,
Jul 16, 2012, 11:25:42 PM7/16/12
to web...@googlegroups.com
Thanks Niphold, its working as intended :)
Reply all
Reply to author
Forward
0 new messages