【发布时间】:2013-06-11 12:35:46
【问题描述】:
我正在使用这个功能:
def checker(name,s)
MY_T = "SELECT count(*) FROM `"+session.SessionInfo.Name where EventName='"+name+"'"
我想检查表是否存在,我该怎么做?
我看到一些例子使用:XXXX.execute() 这是什么意思?
这是我看到的:
query = cursor.execute("""SELECT count(*) FROM scan WHERE prefix = %s and code_id = %s and answer = %s and station_id = %s""",
(prefix, code_id, answer, station,))
if query != 1:
例如,我尝试打印 MY_T 以查看它是否返回 -1,但它只打印 "select count (*)...... "
如何查看? 任何帮助将不胜感激。
【问题讨论】:
-
query = cursor.execute("""SELECT count(*) FROM scan WHERE prefix = %s and code_id = %s and answer = %s and station_id = %s""", (prefix, code_id, answer, station,))这很不安全,你应该改用绑定变量。 -
恐怕这取决于您使用的数据库。使用 sqlite3,你可以做到
SELECT * FROM sqlite_master WHERE type = 'table' AND name = 'the_table_name' -
您使用的是哪个数据库/驱动程序?你能提供更多信息吗?