comparison 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 (16 months ago)
parents e890195256ac
children 0e304689c415
comparison
equal deleted inserted replaced
833:e890195256ac 844:9ad9c8c38fe4
1932 needWhere = false; 1932 needWhere = false;
1933 } 1933 }
1934 } 1934 }
1935 1935
1936 if (types != null && types.length > 0) { 1936 if (types != null && types.length > 0) {
1937 boolean foundType = false;
1937 query.append(needWhere ? "WHERE" : " AND").append(" tt.\"table_type_name\" IN ("); 1938 query.append(needWhere ? "WHERE" : " AND").append(" tt.\"table_type_name\" IN (");
1938 for (int i = 0; i < types.length; i++) { 1939 for (int i = 0; i < types.length; i++) {
1939 String tabletype = types[i]; 1940 String tabletype = types[i];
1940 /* Some JDBC applications use different table type names. 1941 if (tabletype != null && !tabletype.isEmpty()) {
1941 * Replace some SQL synonyms to valid MonetDB 1942 /* Some JDBC applications use different table type names.
1942 * table type names as defined in sys.table_types */ 1943 * Replace some SQL synonyms to valid MonetDB
1943 if ("BASE TABLE".equals(tabletype)) { 1944 * table type names as defined in sys.table_types */
1944 tabletype = "TABLE"; 1945 if ("BASE TABLE".equals(tabletype)) {
1945 } else 1946 tabletype = "TABLE";
1946 if ("GLOBAL TEMPORARY".equals(tabletype)) { 1947 } else
1947 tabletype = "GLOBAL TEMPORARY TABLE"; 1948 if ("GLOBAL TEMPORARY".equals(tabletype)) {
1948 } else 1949 tabletype = "GLOBAL TEMPORARY TABLE";
1949 if ("LOCAL TEMPORARY".equals(tabletype)) { 1950 } else
1950 tabletype = "LOCAL TEMPORARY TABLE"; 1951 if ("LOCAL TEMPORARY".equals(tabletype)) {
1952 tabletype = "LOCAL TEMPORARY TABLE";
1953 }
1954 if (foundType) {
1955 query.append(',');
1956 }
1957 query.append('\'').append(tabletype).append('\'');
1958 foundType = true;
1951 } 1959 }
1952 if (i > 0) { 1960 }
1953 query.append(','); 1961 if (!foundType) {
1954 } 1962 // we need to have at least one literal in the SQL IN-list else we get a syntax error
1955 query.append('\'').append(tabletype).append('\''); 1963 query.append("''");
1956 } 1964 }
1957 query.append(')'); 1965 query.append(')');
1958 // for debug: System.out.println("SQL (len " + query.length() + "): " + query); 1966 // for debug: System.out.println("SQL (len " + query.length() + "): " + query);
1959 } 1967 }
1960 1968