查看文章 |
django 运行sql语句的方法
2010-04-13 15:14
from django.db import connection cursor = connection.cursor() cursor.execute("SELECT t.tid FROM bbs_threads t LEFT JOIN bbs_tmsgs tm ON tm.tid=t.tid WHERE t.ifcheck=1 AND t.fid IN (5,55,54,65,20,13,76,131,7,130,129,132,133,112,113) AND t.subject like %s AND lastpost > %s ORDER BY lastpost DESC LIMIT 500", ['%%%s%%' % keyword,s_postdate]) sl = dictfetchall(cursor)
在execute 中提交的sql语句如果使用[]方式指定搜索的关键词,execute会对sql进行过滤处理。 |
最近读者:

