def get_siege(id):
c.execute("SELECT siege FROM gods where name = 'Agni' ")
# c.execute("SELECT name, siege FROM gods where name = %s " % (id))
return c.fetchall()
The table is called gods and the two columns are name (text) and siege (int). the second line is an test example where I retrieve the gods' siege stat by name. Specifically Agni is the name of the god and that works fine. Im making a method that allows me to pass the name through the method to retrieve the siege stat. the third line is what I thought should work but returns no such column: Agni
我找到了使用不同语法的解决方案。
c.execute("SELECT name, siege FROM gods where name = :god", {"god" : id})
不要进行字符串格式化,请使用下面的代码,该代码应该更好,更安全,并将参数转换为元组
c.execute("SELECT name, siege FROM gods where name = %s ", % (id,))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.