python sqlite3 长语句插入出错
问题描述
python使用sqlite3 长语句插入出错Python2.7下面是源码,还有测试结果,原原本本在终端操作是没问题的,但是在python中跑就出bug了
import xlrdimport multiprocessingfrom sql import sql_methodmysqlite=sql_method()def table_compare():query=’’’select * FROM compare_sales_order WHERE ( compare_sales_order.order_num, compare_sales_order.product_name, compare_sales_order.col_color) not IN(SELECT order_num, product_name, col_color FROM sales_order) ’’’# print querydata=mysqlite.conn.execute(query)for i in data: print itable_compare()
Ran 1 test in 0.000s
FAILED (errors=1)
ErrorTraceback (most recent call last): File 'C:Python27libunittestcase.py', line 329, in run testMethod() File 'C:Python27libunittestloader.py', line 32, in testFailure raise exceptionImportError: Failed to import test module: testTraceback (most recent call last): File 'C:Python27libunittestloader.py', line 254, in _find_tests module = self._get_module_from_name(name) File 'C:Python27libunittestloader.py', line 232, in _get_module_from_name __import__(name) File 'E:pythonexcel_pythontest.py', line 14, in <module> table_compare() File 'E:pythonexcel_pythontest.py', line 11, in table_compare data=mysqlite.conn.execute(query)OperationalError: near ',': syntax error
原原本本的输入到终端没有任何问题
问题解答
回答1:你的SQL写得有问题
sql = '''select *FROM compare_sales_order aWHERE not exists (SELECT 1FROM sales_order bwhere a.order_num=b.order_num and a.product_name=b.product_name and a.col_color=b.col_color )'''
相关文章:
1. javascript - nginx 反向代理 js跨域问题?2. javascript - sublime已经安装了babel插件和sublimelinter-jshint为什么还是显示es6语法错误?3. html5 - 为什么浏览器可以显示HTML文档中未被定义的标签?4. css3 - img垂直水平居中问题5. javascript - 图片能在网站显示,但控制台仍旧报错403 (Forbidden)6. mysql - Sequel Pro 如何格式化(美化)SQL语句?7. 主从复制 - MySQL 主从延迟 300s 以上,求大神解答8. 请教使用PDO连接MSSQL数据库插入是乱码问题?9. php怎么连接数据库10. 关于设计mysql中一个字段自增的函数。

网公网安备