我试图在使用以下代码创建的数据库表中插入一些值:
conn = db.connect('test.sqlite')
cur = conn.cursor()
sql= 'SELECT InitSpatialMetadata()'
cur.execute(sql)
conn.commit()
#connection to the DB
qid=QInputDialog()
tablefacette,ok=QInputDialog.getText(qid,u'Table name',None,QLineEdit.Normal,None)
tablefacette=str(tablefacette)
#asking user for a table name
cur.execute('DROP TABLE IF EXISTS %s' %tablefacette)
cur.execute('CREATE TABLE %s (IDface INTEGER NOT NULL PRIMARY KEY, Xp1 FLOAT NOT NULL, \
Yp1 FLOAT NOT NULL, Zp1 FLOAT NOT NULL, Xp2 FLOAT NOT NULL, Yp2 FLOAT NOT NULL, \
Zp2 FLOAT NOT NULL, Xp3 FLOAT NOT NULL, Yp3 FLOAT NOT NULL, Zp3 FLOAT NOT NULL)' %tablefacette)
#creation of the table
for i in range(0,len(IDface)):
cur.execute("INSERT INTO %s" %tablefacette, "(IDface, Xp1, Yp1, Zp1, Xp2, Yp2, Zp2, Xp3, Yp3, Zp3) VALUES \
(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (IDface[i], Xp1[i], Yp1[i], Zp1[i], Xp2[i], Yp2[i], Zp2[i], Xp3[i], Yp3[i], Zp3[i]))
conn.commit()
#filling the table with values Xp[i] etc which come from a list that I created
问题来自于上一次使用的%s当前执行,此函数最多接受2个参数,但由于使用了%s,因此有3个参数。那么你有什么解决办法或者想法来帮助我吗?我想用用户给出的名称填充我的列表,并用来自表的值填充它。在
感谢您对此事的关注!在
我改成这样写:
相关问题 更多 >
编程相关推荐