Reputation: 90
I have a table userset
create table IF NOT EXISTS userset (id int primary key, name set, phone set, emails list);
Now I am executing an insert statement through datastax java driver : cassandra-driver-core-3.1.0.jar. Now I have a java.util.List of String say listString
List<String> listString = new ArrayList<String>();
listString.add("NewName");
boundStatement.setList(1, listString);
Here boundStatement is an instance of com.datastax.driver.core.BoundStatement. On index 1 i am setting the value of name in userset.
Even though the backend type of name is set and I am using BoundStatement-> setList it still executes without any errors and inputs the value in the name correctly. Is this a functionality of BoundStatement in datastax driver.
Why doesn't it throw an error when I try to setList for a parameter which is a set in the backend server?
Upvotes: 0
Views: 1093
Reputation: 12850
You can say it's a bug in the datastax driver.
When you bind data with boundStatement.setList
or boundStatement.setSet
both method uses lookupCodec
method to find the codec with the column type and don't validate the value.
But If you use statement.bind
to bind data, it uses findCodec
method to find the codec with column type and it's validate with the given value
if ((cqlType == null || cqlType.getName() == LIST) && value instanceof List) {
//...........
}
if ((cqlType == null || cqlType.getName() == SET) && value instanceof Set) {
//............
}
Upvotes: 1