Changeset: 9ad9c8c38fe4 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/9ad9c8c38fe4
Modified Files:
        src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java
        tests/JDBC_API_Tester.java
Branch: default
Log Message:

The String types[] passed to getTables() may contain entries containing null or 
empty string "". Those are invalid table types.
Filter them out of the constructed SQL IN-list.
Also added a test with bad table types[] to test the new optimization.


diffs (68 lines):

diff --git a/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java 
b/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java
--- a/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java
+++ b/src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java
@@ -1934,25 +1934,33 @@ public final class MonetDatabaseMetaData
                }
 
                if (types != null && types.length > 0) {
+                       boolean foundType = false;
                        query.append(needWhere ? "WHERE" : " AND").append(" 
tt.\"table_type_name\" IN (");
                        for (int i = 0; i < types.length; i++) {
                                String tabletype = types[i];
-                               /* Some JDBC applications use different table 
type names.
-                                * Replace some SQL synonyms to valid MonetDB
-                                * table type names as defined in 
sys.table_types */
-                               if ("BASE TABLE".equals(tabletype)) {
-                                       tabletype = "TABLE";
-                               } else
-                               if ("GLOBAL TEMPORARY".equals(tabletype)) {
-                                       tabletype = "GLOBAL TEMPORARY TABLE";
-                               } else
-                               if ("LOCAL TEMPORARY".equals(tabletype)) {
-                                       tabletype = "LOCAL TEMPORARY TABLE";
+                               if (tabletype != null && !tabletype.isEmpty()) {
+                                       /* Some JDBC applications use different 
table type names.
+                                        * Replace some SQL synonyms to valid 
MonetDB
+                                        * table type names as defined in 
sys.table_types */
+                                       if ("BASE TABLE".equals(tabletype)) {
+                                               tabletype = "TABLE";
+                                       } else
+                                       if ("GLOBAL 
TEMPORARY".equals(tabletype)) {
+                                               tabletype = "GLOBAL TEMPORARY 
TABLE";
+                                       } else
+                                       if ("LOCAL 
TEMPORARY".equals(tabletype)) {
+                                               tabletype = "LOCAL TEMPORARY 
TABLE";
+                                       }
+                                       if (foundType) {
+                                               query.append(',');
+                                       }
+                                       
query.append('\'').append(tabletype).append('\'');
+                                       foundType = true;
                                }
-                               if (i > 0) {
-                                       query.append(',');
-                               }
-                               
query.append('\'').append(tabletype).append('\'');
+                       }
+                       if (!foundType) {
+                               // we need to have at least one literal in the 
SQL IN-list else we get a syntax error
+                               query.append("''");
                        }
                        query.append(')');
                        // for debug: System.out.println("SQL (len " + 
query.length() + "): " + query);
diff --git a/tests/JDBC_API_Tester.java b/tests/JDBC_API_Tester.java
--- a/tests/JDBC_API_Tester.java
+++ b/tests/JDBC_API_Tester.java
@@ -1168,6 +1168,12 @@ final public class JDBC_API_Tester {
                        "char(1)        varchar(1024)   varchar(1024)   
varchar(25)     varchar(1048576)        char(1) char(1) char(1) char(1) 
char(1)\n" +
                        "null   tmp     tlargechar      LOCAL TEMPORARY TABLE   
null    null    null    null    null    null\n");
 
+                       String badtabletypes[] = {null, "", null, ""};
+                       compareResultSet(dbmd.getTables(null, "tmp", 
"tlargechar", badtabletypes), "getTables(null, tmp, tlargechar, badtabletypes)",
+                       "Resultset with 10 columns\n" +
+                       "TABLE_CAT      TABLE_SCHEM     TABLE_NAME      
TABLE_TYPE      REMARKS TYPE_CAT        TYPE_SCHEM      TYPE_NAME       
SELF_REFERENCING_COL_NAME       REF_GENERATION\n" +
+                       "char(1)        varchar(1024)   varchar(1024)   
varchar(25)     varchar(1048576)        char(1) char(1) char(1) char(1) 
char(1)\n");
+
                        compareResultSet(dbmd.getTables(null, "jdbctst", 
"schemas", null), "getTables(null, jdbctst, schemas, null)",
                        "Resultset with 10 columns\n" +
                        "TABLE_CAT      TABLE_SCHEM     TABLE_NAME      
TABLE_TYPE      REMARKS TYPE_CAT        TYPE_SCHEM      TYPE_NAME       
SELF_REFERENCING_COL_NAME       REF_GENERATION\n" +
_______________________________________________
checkin-list mailing list -- checkin-list@monetdb.org
To unsubscribe send an email to checkin-list-le...@monetdb.org

Reply via email to