Revision: a598e08834ec
Author: janblok <jan.b...@gmail.com>
Date: Wed Apr 17 05:19:27 2013
Log: Issue #78: Incorrect query fix
http://code.google.com/a/apache-extras.org/p/cassandra-jdbc/source/detail?r=a598e08834ec
Modified:
/src/main/java/org/apache/cassandra/cql/jdbc/MetadataResultSets.java
/src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java
=======================================
--- /src/main/java/org/apache/cassandra/cql/jdbc/MetadataResultSets.java
Wed Apr 17 03:26:58 2013
+++ /src/main/java/org/apache/cassandra/cql/jdbc/MetadataResultSets.java
Wed Apr 17 05:19:27 2013
@@ -267,8 +267,12 @@
{
String expr = "%s = '%s'";
query.append(" WHERE ");
- if (schemaPattern != null)
query.append(String.format(expr, "keyspace_name", schemaPattern));
- if (filterCount > 1) query.append(" AND ");
+ if (schemaPattern != null)
+ {
+ query.append(String.format(expr, "keyspace_name",
schemaPattern));
+ filterCount--;
+ if (filterCount > 0) query.append(" AND ");
+ }
if (tableNamePattern != null)
query.append(String.format(expr, "columnfamily_name", tableNamePattern));
query.append(" ALLOW FILTERING");
}
@@ -387,10 +391,18 @@
{
String expr = "%s = '%s'";
query.append(" WHERE ");
- if (schemaPattern != null)
query.append(String.format(expr, "keyspace_name", schemaPattern));
- if (filterCount > 1) query.append(" AND ");
- if (tableNamePattern != null)
query.append(String.format(expr, "columnfamily_name", tableNamePattern));
- if (filterCount > 2) query.append(" AND ");
+ if (schemaPattern != null)
+ {
+ query.append(String.format(expr, "keyspace_name",
schemaPattern));
+ filterCount--;
+ if (filterCount > 0) query.append(" AND ");
+ }
+ if (tableNamePattern != null)
+ {
+ query.append(String.format(expr, "columnfamily_name",
tableNamePattern));
+ filterCount--;
+ if (filterCount > 0) query.append(" AND ");
+ }
if (columnNamePattern != null)
query.append(String.format(expr, "column_name", columnNamePattern));
query.append(" ALLOW FILTERING");
}
@@ -596,8 +608,12 @@
{
String expr = "%s = '%s'";
query.append(" WHERE ");
- if (schema != null)
query.append(String.format(expr, "keyspace_name", schema));
- if (filterCount > 1) query.append(" AND ");
+ if (schema != null)
+ {
+ query.append(String.format(expr, "keyspace_name",
schema));
+ filterCount--;
+ if (filterCount > 0) query.append(" AND ");
+ }
if (table != null)
query.append(String.format(expr, "columnfamily_name", table));
query.append(" ALLOW FILTERING");
}
@@ -683,8 +699,12 @@
{
String expr = "%s = '%s'";
query.append(" WHERE ");
- if (schema != null)
query.append(String.format(expr, "keyspace_name", schema));
- if (filterCount > 1) query.append(" AND ");
+ if (schema != null)
+ {
+ query.append(String.format(expr, "keyspace_name",
schema));
+ filterCount--;
+ if (filterCount > 0) query.append(" AND ");
+ }
if (table != null)
query.append(String.format(expr, "columnfamily_name", table));
query.append(" ALLOW FILTERING");
}
=======================================
--- /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java
Wed Apr 17 03:26:58 2013
+++ /src/test/java/org/apache/cassandra/cql/jdbc/JdbcRegressionTest.java
Wed Apr 17 05:19:27 2013
@@ -477,6 +477,16 @@
System.out.println("Found pk via dmd : " + cn);
}
+ @Test
+ public void testIssue78() throws Exception
+ {
+ DatabaseMetaData md = con.getMetaData();
+
+ // load the columns, with no catalog and schema
+ ResultSet result = md.getColumns(null, "%", TABLE, "ivalue");
+ assertTrue("Make sure we have found an column", result.next());
+ }
+
@Test
public void isValid() throws Exception
{