Changeset: 67ab06421412 for monetdb-java URL: https://dev.monetdb.org/hg/monetdb-java/rev/67ab06421412 Modified Files: src/main/java/org/monetdb/jdbc/MonetConnection.java src/main/java/org/monetdb/jdbc/MonetDatabaseMetaData.java src/test/java/JDBC_API_Tester.java Branch: mvn Log Message:
Merge branch 'default' into 'mvn' diffs (truncated from 340 to 300 lines): diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,11 @@ # ChangeLog file for monetdb-java # This file is updated with Maddlog +* Thu Jul 3 2025 Martin van Dinther <[email protected]> +- Corrected output of columns SEARCHABLE and AUTO_INCREMENT of method + DatabaseMetaData.getTypeInfo(). Most types are searchable with LIKE + pattern matching. AUTO_INCREMENT is no longer true for base integer types. + * Thu Feb 13 2025 Martin van Dinther <[email protected]> - Corrected the returned integer values of Statement methods getUpdateCount() and getLargeUpdateCount(). They returned -2 for diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -8,12 +8,12 @@ The master repository is: [hg monetdb-ja A read-only copy is available on: [github monetdb-java](https://github.com/MonetDB/monetdb-java). -These Java programs are designed to work only with the [MonetDB Database System](https://www.monetdb.org/). +These Java programs are designed to work with the [MonetDB Database System](https://www.monetdb.org/). They support MonetDB servers from version 11.21 (Jul2015) and higher. However only the latest MonetDB server versions are tested actively. The `MonetDB JDBC driver` allows Java programs to connect to a MonetDB -database server using standard, database independent Java code. +database server using standard, database independent Java code. It is an open source JDBC driver implementing JDBC API 4.2, written in Pure Java (Type 4), and communicates in the MonetDB native network protocol. @@ -35,46 +35,46 @@ By default debug symbols are **not** inc To include debug symbols, edit file `build.properties` change line `enable_debug=true` and rebuild. ## Tests -**Note** For the tests to succeed you first have to startup a MonetDB server (on localhost, port 50000). - To test, simply run `make test` command from a shell. -The `JdbcClient CLI program` (jdbcclient.jre8.jar) includes and uses the MonetDB JDBC driver, -so it can also be used to test connectivity and sending SQL statements to a MonetDB server. +**Note** For the tests to succeed you first have to startup a MonetDB server (on localhost, port 50000). + +## JDBC Driver +The MonetDB JDBC driver consists of one single jar file: `monetdb-jdbc-##.#.jre8.jar`. + +We recommend to always use the [latest released jar file](https://www.monetdb.org/downloads/Java/). +The latest released JDBC driver can be downloaded from [MonetDB Java Download Area](https://www.monetdb.org/downloads/Java/). -The `JdbcClient CLI program` can be started via shell commands: +See [JDBC driver info](https://www.monetdb.org/documentation/user-guide/client-interfaces/libraries-drivers/jdbc-driver/) for more info. + +## JdbcClient program +The `JdbcClient program` is an interactive program using a command-line interface (CLI), similar to the mclient program. +It consists of one single jar file: [jdbcclient.jre8.jar](https://www.monetdb.org/downloads/Java/) and includes and uses the MonetDB JDBC driver. + +The `JdbcClient program` can be started via shell commands: ``` cd jars java -jar jdbcclient.jre8.jar ``` -To get a list of JdbcClient startup options simply run: +To get a list of JdbcClient startup options simply execute: ``` java -jar jdbcclient.jre8.jar --help ``` See [JdbcClient doc](https://www.monetdb.org/documentation/user-guide/client-interfaces/jdbcclient/) for more info. -## JDBC Driver -The JDBC driver consists of one single jar file: `monetdb-jdbc-##.#.jre8.jar`. - -We recommend to always use the latest released jar file. -The latest released JDBC driver can be downloaded from [MonetDB Java Download Area](https://www.monetdb.org/downloads/Java/). - -See [JDBC driver info](https://www.monetdb.org/documentation/user-guide/client-interfaces/libraries-drivers/jdbc-driver/) for more info. - ## Reporting issues -Before reporting an issue, please check if you have used the latest released jar files. +Before reporting an issue, please check if you have used the [latest released jar files](https://www.monetdb.org/downloads/Java/). Some issues may already have been fixed in the latest released jar files. If you find a bug in the latest released jar files or have a request, please log it as an issue at: [github monetdb-java issues](https://github.com/MonetDB/monetdb-java/issues). - Include which versions of the released JDBC driver and MonetDB server you are using and on which platforms. For bugs also include a small standalone java reproduction program. -**Note** we do not accept Pull requests on Github. +**Note** we do not accept Pull requests on Github as it is a read-only copy. ## Copyright Notice SPDX-License-Identifier: MPL-2.0 @@ -86,4 +86,3 @@ file, You can obtain one at http://mozil Copyright 2024, 2025 MonetDB Foundation; Copyright August 2008 - 2023 MonetDB B.V.; Copyright 1997 - July 2008 CWI. - diff --git a/release.txt b/release.txt --- a/release.txt +++ b/release.txt @@ -13,6 +13,6 @@ See https://www.monetdb.org/ The latest MonetDB JDBC driver can be downloaded from https://www.monetdb.org/downloads/Java/ -Documentation on the MonetDB JDBC driver is avaliable from +Documentation for the MonetDB JDBC driver is available from https://www.monetdb.org/documentation/user-guide/client-interfaces/libraries-drivers/jdbc-driver/ diff --git a/src/main/java/org/monetdb/jdbc/MonetConnection.java b/src/main/java/org/monetdb/jdbc/MonetConnection.java --- a/src/main/java/org/monetdb/jdbc/MonetConnection.java +++ b/src/main/java/org/monetdb/jdbc/MonetConnection.java @@ -1963,6 +1963,63 @@ public class MonetConnection return databaseMinorVersion; } + private int databaseMicroVersion = 0; + /** + * Get the micro product version of the connected MonetDB Database Server. + * The number is extracted from the env_monet_version the first time and cached for next calls. + * It is called from: MonetDatabaseMetaData and MonetConnection + * + * @return the MonetDB Database Server minor version number. + * @throws SQLException if fetching MonetDB server version string failed + */ + int getDatabaseMicroVersion() throws SQLException { + if (databaseMicroVersion == 0) { + if (env_monet_version == null) + getEnvValues(); + if (env_monet_version != null) { + try { + // from version string such as 11.33.9 extract number: 9 + int start = env_monet_version.lastIndexOf('.'); // position of '.' or -1 + start++; + databaseMicroVersion = Integer.parseInt(env_monet_version.substring(start)); + } catch (NumberFormatException nfe) { + // ignore + } + } + } + return databaseMicroVersion; + } + + /** + * Utility method to check if connected server matches or is higher than a requested version. + * + * @param requiredMajor dbserver requiredMajor version number. + * @param requiredMinor dbserver requiredMinor version number. + * @param requiredMicro dbserver requiredMicro version nimber + * @return true when the server version is higher or equal to the requiredMajor.requiredMinor.requiredMicro else false. + */ + boolean checkMinimumDBVersion(int requiredMajor, int requiredMinor, int requiredMicro) { + try { + int serverMajor = getDatabaseMajorVersion(); + if (serverMajor > requiredMajor) + return true; + if (serverMajor < requiredMajor) + return false; + + int serverMinor = getDatabaseMinorVersion(); + if (serverMinor > requiredMinor) + return true; + if (serverMinor < requiredMinor) + return false; + + int serverMicro = getDatabaseMicroVersion(); + return serverMicro >= requiredMicro; + } catch (SQLException e) { + // is this really the best way to handle this? + return false; + } + } + /** * Utility method to check if connected server matches or is higher than a requested version. * @@ -1971,11 +2028,7 @@ public class MonetConnection * @return true when the server version is higher or equal to the major.minor else false. */ boolean checkMinimumDBVersion(int major, int minor) { - try { - if ((getDatabaseMinorVersion() >= minor) && (getDatabaseMajorVersion() == major)) - return true; - } catch (SQLException e) { /* ignore */ } - return false; + return checkMinimumDBVersion(major, minor, 0); } /** @@ -1990,6 +2043,29 @@ public class MonetConnection return checkMinimumDBVersion(11, 47); } + /** + * Older versions of MonetDB have a bug when PREPARE returns a large descriptor, + * see https://github.com/MonetDB/MonetDB/issues/7622. + * In those versions fetchSize must be set to a very large number as a workaround. + * + * @return true if the server supports arbitrarily large prepare results and does + * not need the workaround. + */ + boolean supportsLargePrepares() { + // Mar2025 has the fix starting from SP2 + if (checkMinimumDBVersion(11, 53, 4)) + return true; + // older Mar2025 release + if (checkMinimumDBVersion(11, 53, 0)) + return false; + + // Aug2024 has the fix starting from SP3 + if (checkMinimumDBVersion(11, 51, 8)) + return true; + + // anything earlier doesn't have the fix (yet, as far as we know) + return false; + } // Internal cache for determining if system table sys.privilege_codes (new as of Jul2017 release) exists on connected server private boolean queriedPrivilege_codesTable = false; 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 @@ -482,7 +482,7 @@ public final class MonetDatabaseMetaData final String wherePart = "\"mod\" IN ('mtime','timestamp')" + // include Date/Time functions which are located in 'str' module - " OR f.\"name\" IN ('localtime','localtimestamp','date_trunc')"; + " OR f.\"name\" IN ('localtime','localtimestamp','date_trunc','dayname','monthname')"; final String unionPart = // add time date functions which are not listed in sys.functions but implemented in the SQL parser (see sql/server/sql_parser.y) " UNION SELECT 'extract'" + @@ -3073,11 +3073,10 @@ public final class MonetDatabaseMetaData "cast(CASE WHEN \"systemname\" = 'oid' THEN " + DatabaseMetaData.typeNoNulls + " ELSE " + DatabaseMetaData.typeNullable + " END AS smallint) AS \"NULLABLE\", " + "CASE WHEN \"systemname\" IN ('str','json','url','xml') THEN true ELSE false END AS \"CASE_SENSITIVE\", " + - "cast(CASE WHEN \"systemname\" IN ('str','inet','json','url','uuid','xml') THEN " + DatabaseMetaData.typeSearchable + - " ELSE " + DatabaseMetaData.typePredBasic + " END AS smallint) AS \"SEARCHABLE\", " + + "cast(" + DatabaseMetaData.typeSearchable + " AS smallint) AS \"SEARCHABLE\", " + "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint','hugeint','decimal','real','double') THEN false ELSE true END AS \"UNSIGNED_ATTRIBUTE\", " + "CASE \"sqlname\" WHEN 'decimal' THEN true ELSE false END AS \"FIXED_PREC_SCALE\", " + - "CASE WHEN \"sqlname\" IN ('tinyint','smallint','int','bigint') THEN true ELSE false END AS \"AUTO_INCREMENT\", " + + "false AS \"AUTO_INCREMENT\", " + "\"systemname\" AS \"LOCAL_TYPE_NAME\", " + "cast(0 AS smallint) AS \"MINIMUM_SCALE\", " + "cast(CASE WHEN \"sqlname\" = 'decimal' THEN (CASE \"systemname\" WHEN 'int' THEN 9 WHEN 'lng' THEN 18 WHEN 'sht' THEN 4 WHEN 'hge' THEN 38 WHEN 'bte' THEN 2 ELSE 0 END)" + @@ -3113,12 +3112,12 @@ public final class MonetDatabaseMetaData "UNION ALL " + // also add the 2 serial types (like done in ODBC SQLGetTypeInfo()) "SELECT \"TYPE_NAME\", \"DATA_TYPE\", PRECISION, NULL AS LITERAL_PREFIX, NULL AS LITERAL_SUFFIX, NULL AS CREATE_PARAMS, " + - DatabaseMetaData.typeNoNulls + " AS NULLABLE, false AS CASE_SENSITIVE, " + DatabaseMetaData.typePredBasic + " AS SEARCHABLE, " + + DatabaseMetaData.typeNoNulls + " AS NULLABLE, false AS CASE_SENSITIVE, " + DatabaseMetaData.typeSearchable + " AS SEARCHABLE, " + "false AS UNSIGNED_ATTRIBUTE, false AS FIXED_PREC_SCALE, true AS \"AUTO_INCREMENT\", LOCAL_TYPE_NAME, 0 AS MINIMUM_SCALE, " + "0 AS MAXIMUM_SCALE, 0 AS SQL_DATA_TYPE, 0 AS SQL_DATETIME_SUB, 2 AS NUM_PREC_RADIX " + "FROM (VALUES" + - " ('bigserial', -5, 64, 'bigint')" + - ",('serial', 4, 32, 'int')" + + " ('bigserial', -5, 63, 'bigint')" + + ",('serial', 4, 31, 'int')" + ") AS serial_types(\"TYPE_NAME\", \"DATA_TYPE\", PRECISION, LOCAL_TYPE_NAME) " + "ORDER BY \"DATA_TYPE\", \"TYPE_NAME\""); diff --git a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java --- a/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java +++ b/src/main/java/org/monetdb/jdbc/MonetPreparedStatement.java @@ -150,8 +150,9 @@ public class MonetPreparedStatement */ final int originalFetchSize = getFetchSize(); // increase the fetchSize temporarily before sending the PREPARE statement - // we can not use -1 (unlimited), so use a high value. - setFetchSize(50*1000); + // we can not use -1 (unlimited), so use a very high value. + if (!connection.supportsLargePrepares()) + setFetchSize(50*1000 * 1000); if (!super.execute("PREPARE " + prepareQuery)) throw new SQLException("Unexpected server response", "M0M10"); diff --git a/src/test/java/JDBC_API_Tester.java b/src/test/java/JDBC_API_Tester.java --- a/src/test/java/JDBC_API_Tester.java +++ b/src/test/java/JDBC_API_Tester.java @@ -62,6 +62,7 @@ public final class JDBC_API_Tester exten private int dbmsMajorVersion; private int dbmsMinorVersion; private boolean isPostDec2023; // flag to support version specific output + private boolean isPostMar2025; private boolean skipMALoutput = Config.isSkipMalOutput(); final private static int sbInitLen = 5468; // max needed size of sb @@ -83,6 +84,7 @@ public final class JDBC_API_Tester exten // from version 11.50 on, the MonetDB server returns different metadata for // integer digits (1 less) and for clob and char columns (now return varchar). isPostDec2023 = versionIsAtLeast(11, 50); + isPostMar2025 = versionIsAtLeast(11, 54); } @BeforeEach @@ -128,7 +130,7 @@ public final class JDBC_API_Tester exten _______________________________________________ checkin-list mailing list -- [email protected] To unsubscribe send an email to [email protected]
