0
我收到錯誤:sqlite3.OperationalError: near "%": syntax error
當我嘗試運行下面的代碼。 進口使用%s
SQLITE3sqlite3.OperationalError:接近「%」:語法錯誤?
def getFromDB(DBname,table, url):
conn = sqlite3.connect(DBname)
cursor = conn.cursor()
sql = '''SELECT * FROM %s WHERE URL=%s'''
stuff = cursor.execute(sql, (table,url))
stuff = stuff.fetchall()
return stuff
url = 'http://www.examplesite.com/'
getFromDB('AuthorData.sqlite','forbes',url)
我使用的參數在我的SQL
查詢。謝謝您的幫助!
的[sqlite3的(https://docs.python.org/3/library/sqlite3.html)模塊使用''作爲佔位? –
試過了。我得到了相同的錯誤,除了'%'它顯示'?'。 –
啊,是的,錯過了你想傳遞一個標識符(表名)。這不會使用佔位符。你必須格式化爲字符串。例如,請參閱http://stackoverflow.com/questions/3247183/variable-table-name-in-sqlite。 –