热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

将集合绑定为“wherecolin?”子句的右侧-Bindcollectionastheright-hand-sideofa“wherecolin?”clause

InOracleOCI,Icanprepareastatementlike:在OracleOCI中,我可以准备一个如下声明:select*fromtwherepki

In Oracle OCI, I can prepare a statement like:

在Oracle OCI中,我可以准备一个如下声明:

select * from t where pk in :1

and bind a VArray collection for the :1 placeholder.

并绑定一个VArray集合:1占位符。

I don't see any way to do the equivalent in SQLite, unless I use one of the following works arounds:

我没有看到任何方法在SQLite中执行等效操作,除非我使用以下工作之一:

  • prepare

    select * from t where pk=:1

    select * from t其中pk =:1

    instead and execute this N times with all the pks in my collection, and manually do a "union" of the rows from the N queries

    相反,并使用我的集合中的所有pks执行N次,并手动执行N个查询中的行的“联合”

  • put my collection of pk in a temporary table and do a join with t on it.

    把我的pk集合放在一个临时表中,并用它来连接。

  • textually replace :1 with the collection values, negating the benefits of prepared statements.
  • 文本替换:1与集合值,否定准备语句的好处。

Am I missing something? And what would be the recommended way to emulate OCI's collection binding? Thanks, --DD

我错过了什么吗?什么是模拟OCI集合绑定的推荐方法?谢谢,--DD

1 个解决方案

#1


Alas, sqlite only supports binding to scalars, so you're right that you can't bind a parameter to a collection. If the number of items in the collector is bounded, you could prepare a statement with 'IN (?, ?, ?, ?)' [[assuming a max of four items]] then bind the actual scalars in the array (if less than 4, bind the last one repeatedly, or bind a value that you know is "impossible" as a placeholder); otherwise, the approaches you sketch are indeed more or less all that comes to mind.

唉,sqlite只支持绑定到标量,所以你不能将参数绑定到集合。如果收集器中的项目数量有限,您可以准备一个带有'IN(?,?,?,?)'[[假设最多有四个项目]]的语句,然后绑定数组中的实际标量(如果更少) 4,重复绑定最后一个,或绑定一个你知道“不可能”的值作为占位符);否则,你绘制的方法确实或多或少都会浮现在脑海中。


推荐阅读
author-avatar
timer_open
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有