Skip to content
Permalink
Browse files
Always quote names in cql queries
Patch by Jyothsna Konisa; reviewed by Marcus Eriksson, Yifan Cai for CASSANDRA-16224
  • Loading branch information
jyothsnakonisa authored and yifan-c committed Feb 2, 2021
1 parent 4c9bc4f commit c3ce22c97542eaa3b0a450168bc63ce24b4ffeaa
Showing 2 changed files with 8 additions and 7 deletions.
@@ -222,7 +222,7 @@ private PreparedStatement getKeyStatement(@NotNull KeyspaceTablePair keyspaceTab
for (String column : partitionKeyColumns)
selection = selection.column(column);

BuiltStatement select = selection.from(tableMetadata)
BuiltStatement select = selection.from(cqlizedString(tableMetadata.getKeyspace().getName()), cqlizedString(tableMetadata.getName()))
.where(gt(token(partitionKeyColumns), bindMarker()))
.and(lte(token(partitionKeyColumns), bindMarker()));

@@ -242,7 +242,7 @@ private PreparedStatement[] getFullStatement(@NotNull KeyspaceTablePair keyspace
for (String column : allColumns)
selection = selection.column(column);

Select select = selection.from(tableMetadata);
Select select = selection.from(cqlizedString(tableMetadata.getKeyspace().getName()), cqlizedString(tableMetadata.getName()));

for (String column : partitionKeyColumns)
select.where().and(eq(column, bindMarker()));
@@ -262,8 +262,8 @@ private PreparedStatement[] getFullStatement(@NotNull KeyspaceTablePair keyspace
Ordering[] reverseOrdering = new Ordering[clusteringColumns.size()];
for (int i=0; i<clusteringColumns.size(); i++) {
reverseOrdering[i] = clusteringOrders.get(i) == ClusteringOrder.ASC
? desc(clusteringColumns.get(i).getName())
: asc(clusteringColumns.get(i).getName());
? desc(columnToString(clusteringColumns.get(i).getName()))
: asc(columnToString(clusteringColumns.get(i).getName()));
}

select.orderBy(reverseOrdering);
@@ -61,10 +61,11 @@ public boolean isTokenAllowed(BigInteger token) {
}

public static String cqlizedString(final String str) {
if (str.toLowerCase().equals(str)) {
return str;
} else {
boolean shouldQuote = !str.startsWith("\"");
if (shouldQuote) {
return "\"" + str + "\"";
} else {
return str;
}
}

0 comments on commit c3ce22c

Please sign in to comment.