python sqlite3 长语句插入出错
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-07-05 10:35:44
0
1
1071

python使用sqlite3 长语句插入出错
Python2.7
下面是源码,还有测试结果,原原本本在终端操作是没问题的,但是在python中跑就出bug了

import xlrd
import multiprocessing
from sql import sql_method
mysqlite=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 query
data=mysqlite.conn.execute(query)
for i in data:
    print i
table_compare()

Ran 1 test in 0.000s

FAILED (errors=1)

Error
Traceback (most recent call last):
  File "C:\Python27\lib\unittest\case.py", line 329, in run
    testMethod()
  File "C:\Python27\lib\unittest\loader.py", line 32, in testFailure
    raise exception
ImportError: Failed to import test module: test
Traceback (most recent call last):
  File "C:\Python27\lib\unittest\loader.py", line 254, in _find_tests
    module = self._get_module_from_name(name)
  File "C:\Python27\lib\unittest\loader.py", line 232, in _get_module_from_name
    __import__(name)
  File "E:\python\excel_python\test.py", line 14, in <module>
    table_compare()
  File "E:\python\excel_python\test.py", line 11, in table_compare
    data=mysqlite.conn.execute(query)
OperationalError: near ",": syntax error

原原本本的输入到终端没有任何问题

曾经蜡笔没有小新
曾经蜡笔没有小新

全部回复(1)
给我你的怀抱

你的SQL写得有问题

sql = """
select
    *
FROM
    compare_sales_order a
WHERE
    not exists
    (
        SELECT 
            1
        FROM sales_order b
        where 
            a.order_num=b.order_num
            and a.product_name=b.product_name
            and a.col_color=b.col_color
    )
"""
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!