[英]sqlite3.OperationalError: near “,”: syntax error python
[英]python sqlite3.OperationalError: near “-”: syntax error
我知道還有其他類似問題,但找不到有效的解決方案。 我的桌面上有一個數據庫文件,我從數據庫文件中獲取數據庫列名稱。 我從具有與數據庫文件相同列名的excel文件創建值列表,然后嘗試使用下面的腳本更新數據庫文件,但標題中始終出現錯誤。 這個工作在星期一...現在拋出此錯誤
values = ['111-222-333-44', 'xxxxx', '8W 1 CPD FR with ESD Guard', 'STEVES Power INC', '6.01', '9.05', 'beach', 'None', '7000008']
#values is autocreated but here is the list
conn = sqlite3.connect(databasefile)
cursor = conn.execute('select * from powersupplies')
names = list(map(lambda x: x[0], cursor.description))
col_names = ', '.join(names)
print col_names
col_spaces = ','.join(['?'] * len(names))
print col_spaces
c = conn.cursor()
sql = 'INSERT INTO powersupplies (%s) values(%s)' % (col_names, col_spaces)
c.execute(sql, values)
conn.commit()
conn.close()
cursor = conn.execute('從電源選擇*')
這條線在這里。 如果您選擇的任何這些值中都帶有“-”,則可能是您的問題。 我之前遇到過這個確切的錯誤,而擺脫破折號已經為我修復了。
但是,其他人可能會對您如何包含它們有更好的解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.