使用参数表名插入。 什么是最理想和最好的方式
我有这个代码,它是有效的,但我在想是否有可能在一行上使用赋值。 这是我的密码
sql = """INSERT INTO {} (exchange, buy, sell) VALUES (% s,% s,% s)""". format (table)
self.cursor.execute (sql, (exchange, buy, sell))
self.connection.commit ()
试着这样做,但不起作用
sql = """INSERT INTO {} (exchange, buy, sell) VALUES ({}, {}, {})""". format (table, exchange, buy, sell)
在最后一句中,返回未找到的错误。“mytable”
sql = """INSERT INTO %s (exchange, buy, sell) VALUES (% s,% s,% s)""% (table, exchange, buy, sell)
如果您使用的是Python3.7及更高版本,您可以试试这个
请注意字符串开头之前的
f
相关问题 更多 >
编程相关推荐