且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将python字典插入SQLite数据库

更新时间:2023-01-22 08:39:45

Afaik,当查询中包含?"时占位符execute()方法会根据参数类型自动进行正确的转义.因此,以下方法应该起作用:

Afaik, when query has a "?" placeholder execute() method does right escaping automatically basing on argument types. So, the following should work:

query = 'INSERT INTO packages VALUES(%s)' % ','.join(['?'] * len(Tags))
cursor.execute(query, Tags)