SQLite:将值列表绑定到“WHERE col IN (:PRM)";

SQLite: bind list of values to quot;WHERE col IN ( :PRM )quot;(SQLite:将值列表绑定到“WHERE col IN (:PRM);)
本文介绍了SQLite:将值列表绑定到“WHERE col IN (:PRM)";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做的就是发送一个类似的查询

all I want to do is send a query like

SELECT * FROM table WHERE col IN (110, 130, 90);

所以我准备了以下声明

SELECT * FROM table WHERE col IN (:LST);

然后我用

sqlite_bind_text(stmt, 1, "110, 130, 90", -1, SQLITE_STATIC);

不幸的是,这变成了

SELECT * FROM table WHERE col IN ('110, 130, 90');

and 没用(注意两个额外的单引号).我已经尝试在字符串中添加额外的 ' 但它们被转义了.我没有找到关闭转义或防止文本被单引号括起来的选项.我能想到的最后一件事是不使用准备好的语句,但我只将其作为最后的选择.您有什么想法或建议吗?

and is useless (note the two additional single quotes). I already tried putting extra ' in the string but they get escaped. I didn't find an option to turn off the escaping or prevent the text from being enclosed by single quotes. The last thing I can think of is not using a prepared statement, but I'd only take it as last option. Do you have any ideas or suggestions?

谢谢

参数的数量是动态的,所以它可能是三个数字,如上例所示,一个或十二个.

The number of parameters is dynamic, so it might be three numbers, as in the example above, one or twelve.

推荐答案

可以动态构建表单的参数化 SQL 语句

You can dynamically build a parameterized SQL statement of the form

 SELECT * FROM TABLE WHERE col IN (?, ?, ?)

然后为每个?"调用 sqlite_bind_int 一次您添加到语句中.

and then call sqlite_bind_int once for each "?" you added to the statement.

无法将一个文本参数直接绑定到多个整数(或者,就此而言,多个文本)参数.

There is no way to directly bind a text parameter to multiple integer (or, for that matter, multiple text) parameters.

这是我想到的伪代码:

-- Args is an array of parameter values
for i = Lo(Args) to Hi(Args)
   paramlist = paramlist + ', ?'

sql = 'SELECT * FROM TABLE WHERE col IN (' + Right(paramlist, 3)  + ')'

for i = Lo(Args) to Hi(Args)
  sql_bind_int(sql, i, Args[i]

-- execute query here.

这篇关于SQLite:将值列表绑定到“WHERE col IN (:PRM)";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

FastAPI + Tortoise ORM + FastAPI Users (Python) - Relationship - Many To Many(FastAPI+Tortoise ORM+FastAPI用户(Python)-关系-多对多)
Window functions not working in pd.read_sql; Its shows error(窗口函数在pd.read_sql中不起作用;它显示错误)
Select the latest record for an Id per day - Oracle pl sql(选择每天ID的最新记录-Oracle pl SQL)
(Closed) Leaflet.js: How I can Do Editing Geometry On Specific Object I Select Only?((已关闭)Leaflet.js:如何仅在我选择的特定对象上编辑几何图形?)
Select the table name as a column in a UNION select query in MySQL(在MySQL的UNION SELECT查询中选择表名作为列)
Opposite SQL Query for Prestashop Database | Show products not in warehouse(Prestashop数据库的相反SQL查询|显示不在仓库中的产品)