尝试从Python将行插入SQLite表时出现错误。
相关代码;
sql = '''INSERT INTO scr(scr=?, close_date=?, vendor=?, application=?, dev=?, tester=?, release=?)''', (issueId, closeDate, vendor, application, assignedDev, assignedTester, enterpriseRelease)
try:
cursor.execute(sql)
db.commit()
except Exception, err:
print("\nFailed to insert row into table scr:\n" + str(sql))
print(Exception, err)
并返回错误:
Failed to insert row into table scr:
('INSERT INTO scr(scr=?, close_date=?, vendor=?, application=?, dev=?, tester=?, release=?)', ('236500', '0', 'Database', 'Starbase Deleted', 'john.doe', 'jane.doe', 'None'))
(<type 'exceptions.Exception'>, ValueError('operation parameter must be str or unicode',))
最佳答案
您的sql语句不正确,请尝试以下操作:
sql = '''INSERT INTO scr(scr, close_date, vendor, application, dev, tester, release) VALUES (?, ?, ?, ?, ?, ?, ?)'''
params = (issueId, closeDate, vendor, application, assignedDev, assignedTester, enterpriseRelease)
try:
cursor.execute(sql, params)
db.commit()
except Exception as err:
print("\nFailed to insert row into table scr:\n" + str(sql))
print(Exception, err)