Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)

From: Jens Glaser <jens(at)helena(dot)jens(dot)de>
To: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
Date: 1999-08-04 02:33:08
Message-ID: Pine.LNX.4.05.9908040227260.3810-100000@helena.jens.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

Hi,

On Mon, 2 Aug 1999, Ross J. Reedstrom wrote:
> > Sorry, I don't have a fix right now, maybe I get around writing one today
> > or so ..
>
> Let me know how you solve it, I'll need to take a crack at it for mine
> as well.

I've put together a patch, which you can find on my website:
http://www.jens.de/kontor/.

Here's the new routine:

/**
* What is the column's normal maximum width in characters?
*
* @param column the first column is 1, the second is 2, etc.
* @return the maximum width
* @exception SQLException if a database access error occurs
*/
public int getColumnDisplaySize(int column) throws SQLException
{
Field f = getField(column);
String type_name = f.getTypeName();
int sql_type = f.getSQLType();
int typmod = f.mod;

// I looked at other JDBC implementations and couldn't find a consistent
// interpretation of the "display size" for numeric values, so this is our's
// FIXME: currently, only types with a SQL92 or SQL3 pendant are implemented - jens(at)jens(dot)de

// fixed length data types
if (type_name.equals( "int2" )) return 6; // -32768 to +32768 (5 digits and a sign)
if (type_name.equals( "int4" )
|| type_name.equals( "oid" )) return 11; // -2147483648 to +2147483647
if (type_name.equals( "int8" )) return 20; // -9223372036854775808 to +9223372036854775807
if (type_name.equals( "money" )) return 12; // MONEY=DECIMAL(9,2)
if (type_name.equals( "float4" )) return 11; // I checked it out and wasn't able to produce more than 11 digits
if (type_name.equals( "float8" )) return 20; // dito, 20
if (type_name.equals( "char" )) return 1;
if (type_name.equals( "bool" )) return 1;
if (type_name.equals( "date" )) return 14; // "01/01/4713 BC" - "31/12/32767 AD"
if (type_name.equals( "time" )) return 8; // 00:00:00-23:59:59
if (type_name.equals( "timestamp" )) return 22; // hhmmm ... the output looks like this: 1999-08-03 22:22:08+02

// variable length fields
typmod -= 4;
if (type_name.equals( "bpchar" )
|| type_name.equals( "varchar" )) return typmod; // VARHDRSZ=sizeof(int32)=4
if (type_name.equals( "numeric" )) return ( (typmod >>16) & 0xffff)
+ 1 + ( typmod & 0xffff); // DECIMAL(p,s) = (p digits).(s digits)

// if we don't know better
return f.length;
}

--
Jens Glaser Am Holderstrauch 13, 36041 Fulda, 0661/9429507 jens(at)jens(dot)de

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Constantin Teodorescu 1999-08-04 11:46:26 Win32 dll's for PgAccess for Pg 6.5.1 , Tcl/Tk 8.0 and 8.1 AVAILABLE NOW
Previous Message Nicolas Aragon 1999-08-03 15:41:01 [INTERFACES] embedded sql