如何在CQL 3预准备语句中绑定IN子句中的值? [英] How to bind IN-clause values in a CQL 3 prepared statement?

查看:220
本文介绍了如何在CQL 3预准备语句中绑定IN子句中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大致类似的表。

I have a table that is roughly like

create table mytable (
   id uuid,
   something text,
   primary key (id)
);

我试图创建一个具有绑定in-子句的预备语句:

I'm trying to create a prepared statement that has a bound in-clause:

PreparedStatement ps = session.prepare("select * from mytable where id IN (?)");
...
UUID[] ids = { uuid1, uuid2, uuid3} ;

无论我如何表示ids绑定,java驱动程序拒绝它们。

No matter how I express the ids to bind, the java driver rejects them.

ps.bind(/ * as array * /):driver complains语句只有一个值,2提供

ps.bind( /*as array*/): driver complains statement has only one value, 2 supplied

ps.bind(/ *作为逗号分隔的字符串列表uuids * /):驱动程序抱怨它想要UUID.class对象字符串

ps.bind( /*as comma separated string list of uuids*/): driver complains it wants UUID.class objects, not strings

ps.bind(/ *作为列表对象* /):驱动程序抱怨它想要UUID.class objs ,而不是List.class对象

ps.bind( /*as list object*/): driver complains it wants UUID.class objs, not a List.class object

我真的希望驱动程序没有期待多少?占位符,因为在列表中有值,因为这意味着你必须重新准备语句每次你想执行它,Datastax文档说不做!

I really hope the driver isn't expecting as many ? place holders as there are values in the in-list, because that means you'd have to reprepare the statement every time you wanted to execute it, which the Datastax docs says not to do!

我看过 com.datastax.driver.core.BoundStatement.bind()方法,没有任何其他方法可以工作的指示 - 没有魔术包装器或任何东西。

I looked at the com.datastax.driver.core.BoundStatement.bind() method and there is no indication that anything else would work - no magic wrappers or anything.

有办法吗?

推荐答案

正确的语法是 SELECT * FROM mytable WHERE id IN?(不包括)。这将允许您传递一个UUID列表来绑定到单个查询参数。

The correct syntax is SELECT * FROM mytable WHERE id IN ? (without parens around the ?). This will allow you to pass a list of UUIDs to bind to that single query parameter.

这篇关于如何在CQL 3预准备语句中绑定IN子句中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆