查看文章
 
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进行过滤处理。


类别:Django||添加到搜藏 |分享到i贴吧|浏览(171)|评论 (0)
 
最近读者:
 
网友评论:
发表评论:
姓 名:
网址或邮箱: (选填)
内 容:
     

   
帮助中心 | 空间客服 | 投诉中心 | 空间协议
©2012 Baidu