简体   繁体   English

python sqlite3.OperationalError:“-”附近:语法错误

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

I know there are other questions like this but I cannot find a working solution. 我知道还有其他类似问题,但找不到有效的解决方案。 I have a db file on my desktop, i get the DB column names from the DB file. 我的桌面上有一个数据库文件,我从数据库文件中获取数据库列名称。 I create the values list from an excel file with the same column name as the DB file, then i try to update the database file with the script below but I keep getting the error in the title. 我从具有与数据库文件相同列名的excel文件创建值列表,然后尝试使用下面的脚本更新数据库文件,但标题中始终出现错误。 This worked on Monday... now it is throwing this error 这个工作在星期一...现在抛出此错误

    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('select * from powersupplies') cursor = conn.execute('从电源选择*')

This line here. 这条线在这里。 If any of these values you are selecting have a "-" in them, then this might be your problem. 如果您选择的任何这些值中都带有“-”,则可能是您的问题。 I have run into this exact error before and getting rid of dashes has fixed it for me. 我之前遇到过这个确切的错误,而摆脱破折号已经为我修复了。

However, someone else may have a better solution for you of how to include them. 但是,其他人可能会对您如何包含它们有更好的解决方案。

声明:本站的技术帖子网页,遵循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? python- sqlite3.OperationalError:“,”附近:语法错误” - python- sqlite3.OperationalError: near “,”: syntax error" sqlite3.OperationalError:靠近“&lt;”:语法错误:python 格式中的 sql 问题? - sqlite3.OperationalError: near "<": syntax error: Issue with sql in python formatting? sqlite3.OperationalError:“)”附近:tkinter Python 中的语法错误 - sqlite3.OperationalError: near “)”: syntax error in tkinter Python python- sqlite3.OperationalError:“ &lt;”附近:语法错误 - python- sqlite3.OperationalError: near “<”: syntax error sqlite3.OperationalError:靠近“?”:python中的语法错误—使用“ IN”运算符 - sqlite3.OperationalError: near “?”: syntax error in python — using 'IN' operator sqlite3.OperationalError:接近“&lt;”:语法错误 - sqlite3.OperationalError: near "<": syntax error sqlite3.OperationalError:接近“,”:语法错误 - sqlite3.OperationalError: near ",": syntax error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM