pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Auto-increment serial (Postgresql JDBC driver w/ OpenOffice.org ;) )
13+ messages / 3 participants
[nested] [flat]

* Auto-increment serial (Postgresql JDBC driver w/ OpenOffice.org ;) )
@ 2004-09-21 00:09  Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  0 siblings, 1 reply; 13+ messages in thread

From: Jaroslaw J. Pyszny @ 2004-09-21 00:09 UTC (permalink / raw)
  To: pgsql-jdbc

Hi,

<comment>
I know my English is very strange ;)
</comment>

Under OO 'serial' columns don't work, because OO doesn't see
'serial' as auto-increment type. I know it's pseuso-type, but
we can detect it. What do you think, about add this feature 
to driver?

This patch is my simple implementation.

Best regards
Jarek

-- 
8  \\|||//  Jaroslaw 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 =->computer - daj znac jesli chcesz sie pozbyc <-=

Attachments:

jdbc_autoincrement.patch (text/x-patch, 3.4K) download diff -urN pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java java/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java --- pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2004-08-11 12:34:39.000000000 +0200 +++ java/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2004-09-18 23:36:21.000000000 +0200 @@ -3501,6 +3501,7 @@ 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,7 +3517,12 @@ 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 + 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 diff -urN pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java java/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java --- pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java 2004-08-05 12:01:21.000000000 +0200 +++ java/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java 2004-09-19 01:11:00.000000000 +0200 @@ -15,7 +15,8 @@ private Hashtable tableNameCache; private Hashtable schemaNameCache; - + private Hashtable autoIncrementNameCache; + /* * Initialise for a result with a tuple set and * a field descriptor set @@ -42,6 +43,7 @@ /* * Is the column automatically numbered (and thus read-only) * I believe that PostgreSQL does not support this feature. + * It's serial in PostgreSQL * * @param column the first column is 1, the second is 2... * @return true if so @@ -49,7 +51,59 @@ */ public boolean isAutoIncrement(int column) throws SQLException { - return false; + Field field = getField(column); + int tableOID = field.getTableOid(); + + if (field.getTableOid() == 0) + { + return false; + } + + String tabID = Integer.toString(tableOID) + "_" + Integer.toString(column); + + if (autoIncrementNameCache == null) + { + autoIncrementNameCache = new Hashtable(); + } + + Boolean autoIncrementVal = (Boolean) autoIncrementNameCache.get(tabID); + + if (autoIncrementVal != null) + { + return autoIncrementVal.booleanValue(); + } + else + { + ResultSet res = null; + PreparedStatement ps = null; + try + { + 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 = ((Connection)connection).prepareStatement(sql); + ps.setInt(1, tableOID); + ps.setInt(2, column); + res = ps.executeQuery(); + if (res.next()) + { + autoIncrementNameCache.put(tabID, Boolean.TRUE); + return true; + } + else + { + autoIncrementNameCache.put(tabID, Boolean.FALSE); + return false; + } + } finally + { + if (res != null) + res.close(); + if (ps != null) + ps.close(); + } + } } /*
^ permalink raw reply [nested|flat] 13+ messages in thread

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-21 01:50  Kris Jurka <books@ejurka.com>
  parent: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  0 siblings, 2 replies; 13+ messages in thread

From: Kris Jurka @ 2004-09-21 01:50 UTC (permalink / raw)
  To: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>; +Cc: pgsql-jdbc



On Mon, 21 Sep 2004, Jaroslaw J. Pyszny wrote:

> Under OO 'serial' columns don't work, because OO doesn't see
> 'serial' as auto-increment type. I know it's pseuso-type, but
> we can detect it. What do you think, about add this feature 
> to driver?
> 

The basic idea looks good to me, but you've made a mistake in the 
isAutoIncrement() method.  You are using the column number from the 
ResultSet to look up the default when you need to actually use that 
column's position in the table.  In fact it looks like the whole method 
body should be moved into the Field class much like the isNullable method 
does.  This also avoid the contrived hash key value.

Finally we prefer patches in context diff format (diff -c).

Kris Jurka



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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-21 12:33  Dave Cramer <pg@fastcrypt.com>
  parent: Kris Jurka <books@ejurka.com>
  1 sibling, 0 replies; 13+ messages in thread

From: Dave Cramer @ 2004-09-21 12:33 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>; pgsql-jdbc

Can you pull the sql string out into a final static ? It's never going
to change. Also is there a way to do this using the information schema ?

Dave
On Mon, 2004-09-20 at 21:50, Kris Jurka wrote:
> On Mon, 21 Sep 2004, Jaroslaw J. Pyszny wrote:
> 
> > Under OO 'serial' columns don't work, because OO doesn't see
> > 'serial' as auto-increment type. I know it's pseuso-type, but
> > we can detect it. What do you think, about add this feature 
> > to driver?
> > 
> 
> The basic idea looks good to me, but you've made a mistake in the 
> isAutoIncrement() method.  You are using the column number from the 
> ResultSet to look up the default when you need to actually use that 
> column's position in the table.  In fact it looks like the whole method 
> body should be moved into the Field class much like the isNullable method 
> does.  This also avoid the contrived hash key value.
> 
> Finally we prefer patches in context diff format (diff -c).
> 
> Kris Jurka
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 8: explain analyze is your friend
-- 
Dave Cramer
519 939 0336
ICQ # 14675561
www.postgresintl.com




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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-21 19:25  Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  parent: Kris Jurka <books@ejurka.com>
  1 sibling, 1 reply; 13+ messages in thread

From: Jaroslaw J. Pyszny @ 2004-09-21 19:25 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pgsql-jdbc

W liście z wto, 21-09-2004, godz. 03:50, Kris Jurka pisze: 
> On Mon, 21 Sep 2004, Jaroslaw J. Pyszny wrote:
> 

> The basic idea looks good to me, but you've made a mistake in the 
> isAutoIncrement() method.  You are using the column number from the 
> ResultSet to look up the default when you need to actually use that 
> column's position in the table.  In fact it looks like the whole method 
> body should be moved into the Field class much like the isNullable method 
> does.  This also avoid the contrived hash key value.
> 
> Finally we prefer patches in context diff format (diff -c).
Thanks :)
I'll try fix it.

Jarek
-- 
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 =->computers - let me know if you want to get rid of it <-=




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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-21 20:31  Dave Cramer <pg@fastcrypt.com>
  parent: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  0 siblings, 1 reply; 13+ messages in thread

From: Dave Cramer @ 2004-09-21 20:31 UTC (permalink / raw)
  To: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>; +Cc: Kris Jurka <books@ejurka.com>; pgsql-jdbc

This is probably a much more portable way to get the same information.

 select column_default from information_schema.columns where table_name
= 'xyz';

Dave
On Tue, 2004-09-21 at 15:25, Jaroslaw J. Pyszny wrote:
> W liście z wto, 21-09-2004, godz. 03:50, Kris Jurka pisze: 
> > On Mon, 21 Sep 2004, Jaroslaw J. Pyszny wrote:
> > 
> 
> > The basic idea looks good to me, but you've made a mistake in the 
> > isAutoIncrement() method.  You are using the column number from the 
> > ResultSet to look up the default when you need to actually use that 
> > column's position in the table.  In fact it looks like the whole method 
> > body should be moved into the Field class much like the isNullable method 
> > does.  This also avoid the contrived hash key value.
> > 
> > Finally we prefer patches in context diff format (diff -c).
> Thanks :)
> I'll try fix it.
> 
> Jarek
-- 
Dave Cramer
519 939 0336
ICQ # 14675561
www.postgresintl.com




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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-21 22:50  Dave Cramer <pg@fastcrypt.com>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Dave Cramer @ 2004-09-21 22:50 UTC (permalink / raw)
  To: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>; +Cc: Kris Jurka <books@ejurka.com>; pgsql-jdbc

Sorry, missed one more where clause.

select column_default from information_schema.columns where table_name =
'xyz' and column_name = 'id';

This assumes a table defined like create table xyz (id serial);

Dave
On Tue, 2004-09-21 at 16:31, Dave Cramer wrote:
> This is probably a much more portable way to get the same information.
> 
>  select column_default from information_schema.columns where table_name
> = 'xyz';
> 
> Dave
> On Tue, 2004-09-21 at 15:25, Jaroslaw J. Pyszny wrote:
> > W liście z wto, 21-09-2004, godz. 03:50, Kris Jurka pisze: 
> > > On Mon, 21 Sep 2004, Jaroslaw J. Pyszny wrote:
> > > 
> > 
> > > The basic idea looks good to me, but you've made a mistake in the 
> > > isAutoIncrement() method.  You are using the column number from the 
> > > ResultSet to look up the default when you need to actually use that 
> > > column's position in the table.  In fact it looks like the whole method 
> > > body should be moved into the Field class much like the isNullable method 
> > > does.  This also avoid the contrived hash key value.
> > > 
> > > Finally we prefer patches in context diff format (diff -c).
> > Thanks :)
> > I'll try fix it.
> > 
> > Jarek
-- 
Dave Cramer
519 939 0336
ICQ # 14675561
www.postgresintl.com




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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-22 19:11  Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  parent: Dave Cramer <pg@fastcrypt.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Jaroslaw J. Pyszny @ 2004-09-22 19:11 UTC (permalink / raw)
  To: pg@fastcrypt.com; +Cc: pgsql-jdbc

W liście z sro, 22-09-2004, godz. 00:50, Dave Cramer pisze: 
> Sorry, missed one more where clause.
> 
> select column_default from information_schema.columns where table_name =
> 'xyz' and column_name = 'id';
> 
> This assumes a table defined like create table xyz (id serial);
It's works but only for the owner of the table
or I do something wrong ;)

Jarek
-- 
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ć <-=




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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-22 19:59  Kris Jurka <books@ejurka.com>
  parent: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  0 siblings, 1 reply; 13+ messages in thread

From: Kris Jurka @ 2004-09-22 19:59 UTC (permalink / raw)
  To: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>; +Cc: pg@fastcrypt.com; pgsql-jdbc



On Wed, 22 Sep 2004, Jaroslaw J. Pyszny wrote:

> W liście z sro, 22-09-2004, godz. 00:50, Dave Cramer pisze: 
> > Sorry, missed one more where clause.
> > 
> > select column_default from information_schema.columns where table_name =
> > 'xyz' and column_name = 'id';
> > 
> > This assumes a table defined like create table xyz (id serial);
> It's works but only for the owner of the table
> or I do something wrong ;)
> 

The information_schema takes into account permissions on objects and 
doesn't show things you can't access.  So in this case a GRANT SELECT ON 
<table> TO <user> would make it show up.  This seems OK because to get a 
ResultSet you clearly have to be able to query the table.

The problem I came across was that if you only grant access to the table
it doesn't propagate to the underlying sequence.  So if a user doesn't
have permissions to use the sequence it doesn't show up as the default in
the information_schema view.  I'm leaning towards believing this is a bug 
in the information_schema, but it just seems safer to use the direct 
catalog access method you wrote.

Kris Jurka




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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-23 03:08  Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Jaroslaw J. Pyszny @ 2004-09-23 03:08 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pg@fastcrypt.com; pgsql-jdbc

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); } /*
^ permalink raw reply [nested|flat] 13+ messages in thread

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-23 05:40  Kris Jurka <books@ejurka.com>
  parent: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  0 siblings, 1 reply; 13+ messages in thread

From: Kris Jurka @ 2004-09-23 05:40 UTC (permalink / raw)
  To: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>; +Cc: pg@fastcrypt.com; pgsql-jdbc



On Wed, 23 Sep 2004, Jaroslaw J. Pyszny wrote:

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

I've applied the ResultSetMetaData.isAutoIncrement part of this patch, but
you changed what you were doing in DatabaseMetaData and I wanted to
discuss that first.  Now you are adding the serial pseudotypes to the
getTypeInfo results.

1) With the addition of the new types, should we only return true for 
AUTO_INCREMENT on the serial types and not the integer types?

2) Is it necessary to return all four versions of the types (serial, 
serial4, bigserial, and serial8)?  To me this seems to just add confusion 
and perhaps we should just pick a pair of these to use.

3) If we are going to add these as valid types, it seems we should alter 
DatabaseMetaData.getColumns to return "serial" for the TYPE_NAME column as 
well.

Kris Jurka



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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-28 15:37  Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  parent: Kris Jurka <books@ejurka.com>
  0 siblings, 1 reply; 13+ messages in thread

From: Jaroslaw J. Pyszny @ 2004-09-28 15:37 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pg@fastcrypt.com; pgsql-jdbc

W liscie z czw, 23-09-2004, godz. 07:40, Kris Jurka pisze: 
> > 

> 1) With the addition of the new types, should we only return true for 
> AUTO_INCREMENT on the serial types and not the integer types?
OK

> 2) Is it necessary to return all four versions of the types (serial, 
> serial4, bigserial, and serial8)?  To me this seems to just add confusion 
> and perhaps we should just pick a pair of these to use.
Only serial and bigserial ?

> 3) If we are going to add these as valid types, it seems we should alter 
> DatabaseMetaData.getColumns to return "serial" for the TYPE_NAME column as 
> well.
Ok

Jarek
-- 
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 =->computers - let me know if you want to get rid of it <-=




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

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-30 05:05  Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  parent: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  0 siblings, 1 reply; 13+ messages in thread

From: Jaroslaw J. Pyszny @ 2004-09-30 05:05 UTC (permalink / raw)
  To: Kris Jurka <books@ejurka.com>; +Cc: pg@fastcrypt.com; pgsql-jdbc

W liście z wto, 28-09-2004, godz. 17:37, Jaroslaw J. Pyszny pisze: 
Hi,
 3rd patch: (getColumns returns serial or bigserial)

 What do you think about it?

Jarek
-- 
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 =->computers - let me know if you want to get rid of it <-=

Attachments:

jdbc_autoincrement3.patch (text/x-patch, 2.8K) download diff -crN pgjdbc-30.09/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java pgjdbc.ai/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java *** pgjdbc-30.09/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2004-08-11 12:34:39.000000000 +0200 --- pgjdbc.ai/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java 2004-09-30 06:58:03.000000000 +0200 *************** *** 2342,2347 **** --- 2342,2360 ---- String pgType = connection.getPGType(typeOid); tuple[5] = connection.encodeString(pgType); // Type name + String defval = rs.getString("adsrc"); + + if ( defval != null ) { + if ( pgType.equals("int4") ) { + if (defval.indexOf("nextval(") != -1) + tuple[5] = connection.encodeString("serial"); // Type name == serial + } + else if ( pgType.equals("int8") ) { + if (defval.indexOf("nextval(") != -1) + tuple[5] = connection.encodeString("bigserial"); // Type name == bigserial + } + } + // by default no decimal_digits // if the type is numeric or decimal we will // overwrite later. *************** *** 3501,3506 **** --- 3514,3520 ---- 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(); --- 3530,3559 ---- 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 - it isn't 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); + + // add pseudo-type serial, bigserial + if ( typname.equals("int4") ) { + byte[][] tuple1 = (byte[][])tuple.clone(); + + tuple1[0] = connection.encodeString("serial"); + tuple1[11] = bt; + v.addElement(tuple1); + } + else if ( typname.equals("int8") ) { + byte[][] tuple1 = (byte[][])tuple.clone(); + + tuple1[0] = connection.encodeString("bigserial"); + tuple1[11] = bt; + v.addElement(tuple1); + } + } rs.close();
^ permalink raw reply [nested|flat] 13+ messages in thread

* Re: Auto-increment serial (Postgresql JDBC driver w/
@ 2004-09-30 08:12  Kris Jurka <books@ejurka.com>
  parent: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
  0 siblings, 0 replies; 13+ messages in thread

From: Kris Jurka @ 2004-09-30 08:12 UTC (permalink / raw)
  To: Jaroslaw J. Pyszny <arghil@poczta.onet.pl>; +Cc: pg@fastcrypt.com; pgsql-jdbc



On Thu, 30 Sep 2004, Jaroslaw J. Pyszny wrote:

> W li¶cie z wto, 28-09-2004, godz. 17:37, Jaroslaw J. Pyszny pisze: 
> Hi,
>  3rd patch: (getColumns returns serial or bigserial)
> 

Applied.  Thanks.

Kris Jurka




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


end of thread, other threads:[~2004-09-30 08:12 UTC | newest]

Thread overview: 13+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-09-21 00:09 Auto-increment serial (Postgresql JDBC driver w/ OpenOffice.org ;) ) Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
2004-09-21 01:50 ` Re: Auto-increment serial (Postgresql JDBC driver w/ Kris Jurka <books@ejurka.com>
2004-09-21 12:33   ` Re: Auto-increment serial (Postgresql JDBC driver w/ Dave Cramer <pg@fastcrypt.com>
2004-09-21 19:25   ` Re: Auto-increment serial (Postgresql JDBC driver w/ Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
2004-09-21 20:31     ` Re: Auto-increment serial (Postgresql JDBC driver w/ Dave Cramer <pg@fastcrypt.com>
2004-09-21 22:50       ` Re: Auto-increment serial (Postgresql JDBC driver w/ Dave Cramer <pg@fastcrypt.com>
2004-09-22 19:11         ` Re: Auto-increment serial (Postgresql JDBC driver w/ Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
2004-09-22 19:59           ` Re: Auto-increment serial (Postgresql JDBC driver w/ Kris Jurka <books@ejurka.com>
2004-09-23 03:08             ` Re: Auto-increment serial (Postgresql JDBC driver w/ Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
2004-09-23 05:40               ` Re: Auto-increment serial (Postgresql JDBC driver w/ Kris Jurka <books@ejurka.com>
2004-09-28 15:37                 ` Re: Auto-increment serial (Postgresql JDBC driver w/ Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
2004-09-30 05:05                   ` Re: Auto-increment serial (Postgresql JDBC driver w/ Jaroslaw J. Pyszny <arghil@poczta.onet.pl>
2004-09-30 08:12                     ` Re: Auto-increment serial (Postgresql JDBC driver w/ Kris Jurka <books@ejurka.com>

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