Received: from sensenet.localdomain (IDENT:mail@c193.150.216.78.cm-upc.chello.se [193.150.216.78]) by hub.org (8.10.1/8.10.1) with ESMTP id e8DJSOs27236 for ; Wed, 13 Sep 2000 15:28:24 -0400 (EDT) Received: from sensenet.localdomain ([127.0.0.1] helo=lecando.com ident=anders) by sensenet.localdomain with esmtp (Exim 3.16 #1) id 13ZICd-0000F0-00 for pgsql-interfaces@postgresql.org; Wed, 13 Sep 2000 21:28:15 +0200 Message-ID: <39BFD54E.48D0E627@lecando.com> Date: Wed, 13 Sep 2000 21:28:14 +0200 From: Anders Bengtsson X-Mailer: Mozilla 4.75 [en] (X11; U; Linux 2.2.16-3 i586) X-Accept-Language: sv-SE, sv, en MIME-Version: 1.0 To: pgsql-interfaces@postgresql.org Subject: JDBC getDatabaseProductVersion() patch Content-Type: multipart/mixed; boundary="------------D5C50A5FE69C20A754327C9A" X-Archive-Number: 200009/48 This is a multi-part message in MIME format. --------------D5C50A5FE69C20A754327C9A Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Hello, I don't know if this list is the correct way to contribute patches, but here we go: I've implemented getDatabaseProductVersion() for DatabaseMetaData so that it retreives tha version number from the database server, instead of using a hard coded constant in the driver. Attached are patches for jdbc1 and jdbc2. I've only been able to test the jdbc2 driver, but I hope someone can check that the jdbc1 version works. (By the way, has anyone tried to merge the identical parts of the jdbc1 and jdbc2 code?). /Anders _____________________________________________________________________ A n d e r s B e n g t s s o n anders@lecando.com Stockholm, Sweden --------------D5C50A5FE69C20A754327C9A Content-Type: text/plain; charset=us-ascii; name="productversion1.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="productversion1.patch" diff -u -r1.6 DatabaseMetaData.java --- src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java 2000/09/12 18:56:03 1.6 +++ src/interfaces/jdbc/org/postgresql/jdbc1/DatabaseMetaData.java 2000/09/13 19:14:53 @@ -167,19 +167,23 @@ /** * What is the version of this database product. * - *

Note that PostgreSQL 6.3 has a system catalog called pg_version - - * however, select * from pg_version on any database retrieves - * no rows. - * - *

For now, we will return the version 6.3 (in the hope that we change - * this driver as often as we change the database) - * * @return the database version * @exception SQLException if a database access error occurs */ public String getDatabaseProductVersion() throws SQLException { - return ("7.0.2"); + /* The function "version()" has had the format "PostgreSQL X.Y.Z on ..." + * since at least 6.5.x, so this should be a safe assumption. + */ + + java.sql.ResultSet resultSet = connection.ExecSQL("select version()"); + resultSet.next(); + + StringTokenizer versionParts = new StringTokenizer(resultSet.getString(1)); + versionParts.nextToken(); /* "PostgreSQL" */ + String versionNumber = versionParts.nextToken(); /* "X.Y.Z" */ + + return versionNumber; } /** --------------D5C50A5FE69C20A754327C9A Content-Type: text/plain; charset=us-ascii; name="productversion2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="productversion2.patch" diff -u -r1.6 DatabaseMetaData.java --- src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java 2000/09/12 18:56:04 1.6 +++ src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java 2000/09/13 19:15:06 @@ -167,19 +167,23 @@ /** * What is the version of this database product. * - *

Note that PostgreSQL 6.3 has a system catalog called pg_version - - * however, select * from pg_version on any database retrieves - * no rows. - * - *

For now, we will return the version 6.3 (in the hope that we change - * this driver as often as we change the database) - * * @return the database version * @exception SQLException if a database access error occurs */ public String getDatabaseProductVersion() throws SQLException { - return ("7.0.2"); + /* The function "version()" has had the format "PostgreSQL X.Y.Z on ..." + * since at least 6.5.x, so this should be a safe assumption. + */ + + java.sql.ResultSet resultSet = connection.ExecSQL("select version()"); + resultSet.next(); + + StringTokenizer versionParts = new StringTokenizer(resultSet.getString(1)); + versionParts.nextToken(); /* "PostgreSQL" */ + String versionNumber = versionParts.nextToken(); /* "X.Y.Z" */ + + return versionNumber; } /** --------------D5C50A5FE69C20A754327C9A--