pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
JDBC getDatabaseProductVersion() patch
2+ messages / 2 participants
[nested] [flat]

* JDBC getDatabaseProductVersion() patch
@ 2000-09-13 19:28  Anders Bengtsson <anders@lecando.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Anders Bengtsson @ 2000-09-13 19:28 UTC (permalink / raw)
  To: pgsql-interfaces

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

Attachments: download all (2 files, .tar.gz)

productversion1.patch (text/plain, 1.3K) download 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. * - * <p>Note that PostgreSQL 6.3 has a system catalog called pg_version - - * however, select * from pg_version on any database retrieves - * no rows. - * - * <p>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; } /**
productversion2.patch (text/plain, 1.3K) download 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. * - * <p>Note that PostgreSQL 6.3 has a system catalog called pg_version - - * however, select * from pg_version on any database retrieves - * no rows. - * - * <p>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; } /**
^ permalink raw reply [nested|flat] 2+ messages in thread

* Re: JDBC getDatabaseProductVersion() patch
@ 2000-09-14 01:27  Peter Mount <peter@retep.org.uk>
  parent: Anders Bengtsson <anders@lecando.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Peter Mount @ 2000-09-14 01:27 UTC (permalink / raw)
  To: Anders Bengtsson <anders@lecando.com>; +Cc: pgsql-interfaces



On Wed, 13 Sep 2000, Anders Bengtsson wrote:

> 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.

I'll check it against both. Hopefully the output from the backend doesnt
change it's format...

> (By the way, has anyone tried to merge the identical parts of the jdbc1
> and jdbc2 code?).

I have thought about it, but now isn't a good time as it would then
involve undoing it later. I've got plans on rewriting the jdbc2 ResultSet
to allow cursor support, and some of the duplicated areas would be
affected.

Peter




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2000-09-14 01:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2000-09-13 19:28 JDBC getDatabaseProductVersion() patch Anders Bengtsson <anders@lecando.com>
2000-09-14 01:27 ` Peter Mount <peter@retep.org.uk>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox