简体   繁体   English

不同类型的sqlite3 python的多个参数

[英]Multiple parameters of different types sqlite3 python

I can't seem to figure out how to parameterize multiple different formats (both real and string in the same query 我似乎无法弄清楚如何参数化多种不同的格式(同一查询中的实数和字符串)

conn = sqlite3.connect(dbfile)
c = conn.cursor()

def update_data(text,var2):
    c.execute("UPDATE T SET T12M = ? WHERE date = ?", (var2, text))
    conn.commit()

It works if I hard code what I want but I can't seem to get the variable number/text to work. 如果我对想要的内容进行硬编码,则它可以工作,但是我似乎无法使可变数字/文本起作用。 For ex this works but I want to pass in variable numbers/strings: UPDATE T SET T12M = 10 WHERE date = '9/28/2015'; 对于前一个,这是可行的,但我想传递可变数字/字符串:UPDATE T SET T12M = 10 WHERE date ='9/28/2015';

尝试使用花括号和.format()方法:

c.execute("UPDATE T SET T12M = {} WHERE date = {}".format(var2, text))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM