python sqlite3 長語句插入出錯
問題描述
python使用sqlite3 長語句插入出錯Python2.7下面是源碼,還有測試結(jié)果,原原本本在終端操作是沒問題的,但是在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 )'''
相關(guān)文章:
1. Python中使用超長的List導(dǎo)致內(nèi)存占用過大2. css3 - 純css實現(xiàn)點擊特效3. javascript - 有適合開發(fā)手機端Html5網(wǎng)頁小游戲的前端框架嗎?4. javascript - 關(guān)于apply()與call()的問題5. javascript - jQuery post()方法,里面的請求串可以轉(zhuǎn)換為GBK編碼么?可以的話怎樣轉(zhuǎn)換?6. 安全性測試 - nodejs中如何防m(xù)ySQL注入7. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?8. javascript - JS變量被清空9. javascript - axios請求回來的數(shù)據(jù)組件無法進行綁定渲染10. javascript - main head .intro-text{width:40%} main head{display:flex}為何無效?
