Skip to content

Commit 2e811de

Browse files
committed
Merge pull request apache#358 from datastax/java688
JAVA-688 : QueryBuilder doesn't serialize raw strings
2 parents b4a6e18 + 23eb07d commit 2e811de

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

driver-core/src/main/java/com/datastax/driver/core/querybuilder/Utils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,14 @@ static StringBuilder joinAndAppendValues(StringBuilder sb, String separator, Lis
5959
return sb;
6060
}
6161

62-
// Returns null if it's not really serializable (function call, bind markers, ...)
62+
// Returns false if it's not really serializable (function call, bind markers, ...)
6363
static boolean isSerializable(Object value) {
6464
if (value instanceof BindMarker || value instanceof FCall || value instanceof CName)
6565
return false;
6666

67+
if (value instanceof RawString)
68+
return false;
69+
6770
// We also don't serialize fixed size number types. The reason is that if we do it, we will
6871
// force a particular size (4 bytes for ints, ...) and for the query builder, we don't want
6972
// users to have to bother with that.

driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.math.BigDecimal;
1919
import java.math.BigInteger;
2020
import java.net.InetAddress;
21+
import java.nio.ByteBuffer;
2122
import java.util.*;
2223

2324
import com.google.common.collect.ImmutableList;
@@ -769,4 +770,11 @@ public void should_handle_nested_collections() {
769770
statement = update("foo").with(prependAll("l", list)).where(eq("k", 1));
770771
assertThat(statement.toString()).isEqualTo(query);
771772
}
773+
774+
@Test(groups = "unit")
775+
public void should_not_serialize_raw_query_values() {
776+
RegularStatement select = select().from("test").where(gt("i", raw("1")));
777+
assertThat(select.getQueryString()).doesNotContain("?");
778+
assertThat(select.getValues(ProtocolVersion.V3)).isNull();
779+
}
772780
}

0 commit comments

Comments
 (0)