简体   繁体   English

sqlite3“OperationalError:near”(“:语法错误”python

[英]sqlite3 “OperationalError: near ”(“: syntax error” python

simply put i am trying to make a sql database table and input data into it. 简单地说我正在尝试制作一个sql数据库表并将数据输入其中。 I have it working in a simpler way, but when I put it into my script it results in this error. 我让它以更简单的方式工作,但是当我将它放入我的脚本时会导致此错误。 I'm hoping its something simple I missed. 我希望我错过了一些简单的东西。 Any help/advice would be greatly appreciated. 任何帮助/建议将不胜感激。

conn = sqlite3.connect('Data1.db')

c = conn.cursor()

# Create table
c.execute('''CREATE TABLE Data_Output6
         (date text, output6MV real)''') 

Averages_norm = []

for i, x in enumerate(Averages):
    Averages_norm.append(x*output_factor)
    c.execute("INSERT INTO Data_Output6 VALUES (%r,%r)" %(xdates[i],Averages_norm[-1]))
conn.commit()

results in the error: 导致错误:

57     for i, x in enumerate(Averages):
58         Averages_norm.append(x*output_factor)
---> 59         c.execute("INSERT INTO Data_Output6 VALUES (%r,%r)"%(xdates[i],Averages_norm[-1]))
60     conn.commit()
61 

OperationalError: near "(": syntax error OperationalError:接近“(”:语法错误

Simply put, let the DB API do that formatting: 简单地说,让DB API进行格式化:

c.execute("INSERT INTO Data_Output6 VALUES (?, ?)", (xdates[i], Averages_norm[-1]))

And refer to the documentation https://docs.python.org/2/library/sqlite3.html where is mentioned: 请参阅文档https://docs.python.org/2/library/sqlite3.html ,其中提到:

Instead, use the DB-API's parameter substitution. 而是使用DB-API的参数替换。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sqlite3“ OperationalError:附近”)“:语法错误” python - sqlite3 “OperationalError: near ”)“: syntax error” python sqlite3.OperationalError:靠近“WHERE”:语法错误(Python 2,sqlite3) - sqlite3.OperationalError: near “WHERE”: syntax error (Python 2, sqlite3) Python-sqlite3 sqlite3.OperationalError:接近“%”:语法错误? - Python - sqlite3 sqlite3.OperationalError: near “%”: syntax error? Sqlite3:OperationalError:在“ TABLE”附近:语法错误 - Sqlite3: OperationalError: near “TABLE”: syntax error SQLite3 OperationalError:靠近“(”:语法错误 - SQLite3 OperationalError: near “(”: syntax error Python和sqlite3抛出错误:sqlite3.OperationalError:near“s”:语法错误 - Python and sqlite3 throwing an error: sqlite3.OperationalError: near “s”: syntax error Python2.7-SQLite3库输出错误消息“ sqlite3.OperationalError:靠近“?”:语法错误” - Python2.7 - SQLite3 library outputs error message “sqlite3.OperationalError: near ”?“: syntax error” Python:sqlite3.OperationalError:在“ &lt;”附近:语法错误(使用HTML源代码更新sqlite3字段) - Python: sqlite3.OperationalError: near “<”: syntax error (updating sqlite3 field with html source code) Python SQlite3更新函数sqlite3.OperationalError:“ WHERE”附近:语法错误 - Python SQlite3 Update function, sqlite3.OperationalError: near “WHERE”: syntax error sqlite3.OperationalError:“,”附近:语法错误python - sqlite3.OperationalError: near “,”: syntax error python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM