简体   繁体   English

将多个元组传递给 python SQLite 命令

[英]Pass multiple tuple to python SQLite command

I'm trying to pass multiple tuple to placeholders in SQLite.我正在尝试将多个元组传递给 SQLite 中的占位符。 Example I got 2 tuple like below:示例我有 2 个元组,如下所示:

tup_A = (1, 2, 3, 4)
tup_B = (5, 6, 7, 8)

The SQL command like: SQL 命令如下:

sql = 'SELECT * FROM abc WHERE col_A IN (?,?,?,?) AND NOT IN (?,?,?,?) ORDER BY col_A;'

So I have tried the executor:所以我尝试了执行者:

results = executor(sql, (tup_A,tup_B))

and

results = executor(sql, tup_A + tup_B)

but it result in但它导致

OperationalError('near "IN": syntax error',)

I have tried successfully run command with one parameter:我已经尝试使用一个参数成功运行命令:

    sql = 'SELECT * FROM abc WHERE col_A IN (?,?,?,?) ORDER BY col_A;'
    results = executor(sql, tup_A)

Any help would be greatly appreciated任何帮助将不胜感激

I realized that I missed the col_a before NOT IN clause, and this command work:我意识到我在 NOT IN 子句之前错过了 col_a,并且这个命令有效:

results = executor(sql, tup_A + tup_B)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM