diff src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java @ 844:9ad9c8c38fe4

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.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Thu, 04 Jan 2024 19:28:31 +0100 (15 months ago)
parents e890195256ac
children 0e304689c415
line wrap: on
line diff
--- 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);