Mercurial > hg > monetdb-java
changeset 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 | d7ffef8faf38 |
files | src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java tests/JDBC_API_Tester.java |
diffstat | 2 files changed, 29 insertions(+), 15 deletions(-) [+] |
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);
--- 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" +