pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
To: Kris Jurka <books@ejurka.com>
Cc: pg@fastcrypt.com
Cc: pgsql-jdbc <pgsql-jdbc@postgresql.org>
Subject: Re: Auto-increment serial (Postgresql JDBC driver w/
Date: 23 Sep 2004 05:08:19 +0200
Message-ID: <1095908898.30959.5.camel@lx.siec> (raw)
In-Reply-To: <Pine.BSO.4.56.0409221454160.32134@leary.csoft.net>
References: <1095725344.10857.107.camel@lx.siec>
	<Pine.BSO.4.56.0409202046080.9396@leary.csoft.net>
	<1095794747.18680.23.camel@lx.siec>
	<1095798675.1557.122.camel@localhost.localdomain>
	<1095807031.1556.129.camel@localhost.localdomain>
	<1095880271.22986.37.camel@lx.siec>
	<Pine.BSO.4.56.0409221454160.32134@leary.csoft.net>

W liście z sro, 22-09-2004, godz. 21:59, Kris Jurka pisze: 
> On Wed, 22 Sep 2004, Jaroslaw J. Pyszny wrote:
[...]

second patch

-- 
8  \\|||//  Jarosław J. Pyszny <arghil@poczta.onet.pl>
b   (o|o)    Linux admin/devel ("Vitae,non scholae,discimus")
i  --\_/--   Linux user: #96704    (http://counter.li.org)
t =->komputer(y) - daj znać jeśli chcesz się pozbyć <-=

Attachments:

jdbc_autoincrement2.patch (text/x-patch, 5.0K) download diff -crN pgjdbc/org/postgresql/core/Field.java pgjdbc.ai/org/postgresql/core/Field.java *** pgjdbc/org/postgresql/core/Field.java 2004-06-29 08:43:25.000000000 +0200 --- pgjdbc.ai/org/postgresql/core/Field.java 2004-09-23 00:47:33.000000000 +0200 *************** *** 28,33 **** --- 28,34 ---- private final String columnLabel; // Column label private String columnName; // Column name; null if undetermined private Integer nullable; // Is this column nullable? null if undetermined. + private Boolean autoIncrement; // Is this column automatically numbered? private int format = TEXT_FORMAT; // In the V3 protocol each field has a format // 0 = text, 1 = binary *************** *** 179,184 **** --- 180,227 ---- } } + public boolean getAutoIncrement(Connection con) throws SQLException + { + if (autoIncrement != null) + return autoIncrement.booleanValue(); + + if (tableOid == 0 || positionInTable == 0) { + autoIncrement = Boolean.FALSE; + return autoIncrement.booleanValue(); + } + + ResultSet res = null; + PreparedStatement ps = null; + try + { + final String sql = "SELECT def.adsrc FROM pg_catalog.pg_class c " + + "JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) " + + "LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) " + + "WHERE c.oid = ? and attnum = ? AND def.adsrc LIKE '%nextval(%'"; + + ps = con.prepareStatement(sql); + + ps.setInt(1, tableOid); + ps.setInt(2, positionInTable); + res = ps.executeQuery(); + + int nullResult = ResultSetMetaData.columnNullableUnknown; + if (res.next()) { + autoIncrement = Boolean.TRUE; + } + else { + autoIncrement = Boolean.FALSE; + } + return autoIncrement.booleanValue(); + + } finally { + if (res != null) + res.close(); + if (ps != null) + ps.close(); + } + } + public String getColumnName(Connection con) throws SQLException { if (columnName != null) diff -crN pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java pgjdbc.ai/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java *** pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2004-08-11 12:34:39.000000000 +0200 --- pgjdbc.ai/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2004-09-22 21:57:10.000000000 +0200 *************** *** 3501,3506 **** --- 3501,3507 ---- byte b9[] = connection.encodeString("9"); byte b10[] = connection.encodeString("10"); byte bf[] = connection.encodeString("f"); + byte bt[] = connection.encodeString("t"); byte bnn[] = connection.encodeString(Integer.toString(java.sql.DatabaseMetaData.typeNoNulls)); byte bts[] = connection.encodeString(Integer.toString(java.sql.DatabaseMetaData.typeSearchable)); *************** *** 3516,3527 **** tuple[8] = bts; tuple[9] = bf; // false for now - it's signed tuple[10] = bf; // false for now - must handle money ! tuple[11] = bf; // false for now - handle autoincrement // 12 - LOCAL_TYPE_NAME is null // 13 & 14 ? // 15 & 16 are unused so we return null tuple[17] = b10; // everything is base 10 v.addElement(tuple); } rs.close(); --- 3517,3556 ---- tuple[8] = bts; tuple[9] = bf; // false for now - it's signed tuple[10] = bf; // false for now - must handle money ! if ( typname.equals("int4") || typname.equals("int8") ) { ! tuple[11] = bt; ! } ! else { ! tuple[11] = bf; ! } // 12 - LOCAL_TYPE_NAME is null // 13 & 14 ? // 15 & 16 are unused so we return null tuple[17] = b10; // everything is base 10 v.addElement(tuple); + + // add pseudo-type serial, serial4, serial8, bigserial + if ( typname.equals("int4") ) { + byte[][] tuple1 = (byte[][])tuple.clone(); + byte[][] tuple2 = (byte[][])tuple.clone(); + + tuple1[0] = connection.encodeString("serial"); + tuple2[0] = connection.encodeString("serial4"); + + v.addElement(tuple1); + v.addElement(tuple2); + } + else if ( typname.equals("int8") ) { + byte[][] tuple1 = (byte[][])tuple.clone(); + byte[][] tuple2 = (byte[][])tuple.clone(); + + tuple1[0] = connection.encodeString("bigserial"); + tuple2[0] = connection.encodeString("serial8"); + + v.addElement(tuple1); + v.addElement(tuple2); + } + } rs.close(); diff -crN pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java pgjdbc.ai/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java *** pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java 2004-09-21 02:58:59.000000000 +0200 --- pgjdbc.ai/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java 2004-09-23 00:08:25.000000000 +0200 *************** *** 48,54 **** */ public boolean isAutoIncrement(int column) throws SQLException { ! return false; } /* --- 48,55 ---- */ public boolean isAutoIncrement(int column) throws SQLException { ! Field field = getField(column); ! return field.getAutoIncrement(connection); } /*

view thread (13+ messages)  latest in thread

Message-ID: <1095908898.30959.5.camel@lx.siec>
Permalink:  ../1095908898.30959.5.camel@lx.siec/
Also on:    postgresql.org/message-id/1095908898.30959.5.camel@lx.siec

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: arghil@poczta.onet.pl, books@ejurka.com, pg@fastcrypt.com
  Subject: Re: Auto-increment serial (Postgresql JDBC driver w/
  In-Reply-To: <1095908898.30959.5.camel@lx.siec>
  References: <1095725344.10857.107.camel@lx.siec> <Pine.BSO.4.56.0409202046080.9396@leary.csoft.net> <1095794747.18680.23.camel@lx.siec> <1095798675.1557.122.camel@localhost.localdomain> <1095807031.1556.129.camel@localhost.localdomain> <1095880271.22986.37.camel@lx.siec> <Pine.BSO.4.56.0409221454160.32134@leary.csoft.net> <1095908898.30959.5.camel@lx.siec>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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