我的表有3列(1)id(2)firstname(3)lastname
我的局部变量具有以下值
id = '1'
firstname = 'xxx'
lastname = 'yyy'
查询下面的工作,只在DB中插入id的值
query.exec_("insert into sportsmen (id) values('%s')" %id)
如何扩展上述查询以一次性插入所有3个值(id,firstname,lastname)?
答案 0 :(得分:0)
您必须执行以下命令:
query.exec_("insert into sportsmen (id, firstname, lastname) values('%s', '%s', '%s')" % (id, firstname, lastname))