changeset 966:39b74cc688d2

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.
author Martin van Dinther <martin.van.dinther@monetdbsolutions.com>
date Wed, 12 Feb 2025 22:31:08 +0100 (7 weeks ago)
parents 8aaa9964359a
children 5cc071c5c170
files ChangeLog src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java tests/JDBC_API_Tester.java
diffstat 3 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,9 @@
 # This file is updated with Maddlog
 
 * Wed Feb 12 2025 Martin van Dinther <martin.van.dinther@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().
 
--- 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;
 				}
 			}
--- 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" +