Bound statement with named parameters?

300 views
Skip to first unread message

Jan Algermissen

unread,
Aug 12, 2013, 9:21:52 AM8/12/13
to java-dri...@lists.datastax.com
Hi,

I noticed the BoundStatement setXXX(name,value) methods and wonder whether this indicates that I can have named parameters (instead of ?) in bound queries.

I cannot find any docs regarding the syntax, unfortunately.

Would it be like  "insert into users ( user_id, name) values (:userId , :name) ?

Jan

Alex Popescu

unread,
Aug 15, 2013, 2:38:56 PM8/15/13
to java-dri...@lists.datastax.com
By looking a bit through the code I think those methods allow you to set the value of a parameter in a PreparedStatement by using the column name (so not a named parameter). 

:- a)

Sylvain Lebresne

unread,
Aug 19, 2013, 4:22:51 AM8/19/13
to java-dri...@lists.datastax.com
I'll confirm Alex's answer, there is no support for name parameters in the prepared query string itself (or rather, CQL doesn't support them and the driver religiously avoid parsing/messing with the query string).

But, if you prepare "insert into users (user_id, name) values (? , ?)", you can later do something like setString("name", "someName") on the BoundStatement corresponding.

But don't get me wrong, I'm not saying named parameters wouldn't be nice. For instance, if a SELECT statement has 2 bind markers that correspond to the same column name, you do have to resort to indexes, which is slightly annoying. But as I don't like forcing clients to mess with query strings, I'd like to see if it's not something that could be fixed in the CQL side first (so in Cassandra). It's not supported at this point in any case.

--
Sylvain
Reply all
Reply to author
Forward
0 new messages