简体   繁体   中英

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';

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

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

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.

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