Changeset: 39b74cc688d2 for monetdb-java URL: https://dev.monetdb.org/hg/monetdb-java/rev/39b74cc688d2 Modified Files: ChangeLog src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java tests/JDBC_API_Tester.java Branch: default Log Message:
Fix a bug in DatabaseMetaData.getTables() where a provided string in the array of table types argument would contain a single quote or back slash. It was not escaped properly, resulting in an SQL syntax error. diffs (37 lines): diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ # This file is updated with Maddlog * Wed Feb 12 2025 Martin van Dinther <martin.van.dint...@monetdbsolutions.com> +- Fix a bug in DatabaseMetaData.getTables() where a provided string in the + array of table types argument would contain a single quote or back slash. + It was not escaped properly, resulting in an SQL syntax error. - Fix missing escaping of single back slashes in string data provided to PreparedStatement methods setString(), setClob(), setObject() and setURL(). 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 @@ -1956,7 +1956,7 @@ public final class MonetDatabaseMetaData if (foundType) { query.append(','); } - query.append('\'').append(tabletype).append('\''); + query.append(MonetWrapper.sq(tabletype)); foundType = true; } } 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 @@ -1324,7 +1324,7 @@ public final 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, ""}; + String badtabletypes[] = {null, "", "'", "\\'", "\"", null, "bad", "%", "% %"}; 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" + _______________________________________________ checkin-list mailing list -- checkin-list@monetdb.org To unsubscribe send an email to checkin-list-le...@monetdb.org