pg.ddx.io  pgsql-interfaces@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
5+ messages / 4 participants
[nested] [flat]

* Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
@ 1999-08-02 18:12  Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>
  parent: Jens Glaser <jens@helena.jens.de>
  1 sibling, 2 replies; 5+ messages in thread

From: Ross J. Reedstrom @ 1999-08-02 18:12 UTC (permalink / raw)
  To: jens@jens.de; +Cc: pgsql-interfaces

On Mon, Aug 02, 1999 at 07:23:07PM +0000, Jens Glaser wrote:
> Hi,
> 
> here's just another annoying bug in the JDBC driver:
> 
> ResultSetMetaData.getColumnDisplaySize() returns the length of the
> *column label*, but it is expected to return the max width of the column!
> 

Hmm, the Zope Python interface suffers from the same problem (and the
same work around): lack of column width info, substituting the column
label length.

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

Ross
-- 
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu> 
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St.,  Houston, TX 77005



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

* Re: sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
@ 1999-08-02 18:51  Peter Mount <peter@retep.org.uk>
  parent: Jens Glaser <jens@helena.jens.de>
  1 sibling, 0 replies; 5+ messages in thread

From: Peter Mount @ 1999-08-02 18:51 UTC (permalink / raw)
  To: jens@jens.de; +Cc: pgsql-interfaces

On Mon, 2 Aug 1999, Jens Glaser wrote:

> Hi,
> 
> here's just another annoying bug in the JDBC driver:
> 
> ResultSetMetaData.getColumnDisplaySize() returns the length of the
> *column label*, but it is expected to return the max width of the column!

It's already on my list of things for 6.6.

--
       Peter T Mount peter@retep.org.uk
      Main Homepage: http://www.retep.org.uk
PostgreSQL JDBC Faq: http://www.retep.org.uk/postgres
 Java PDF Generator: http://www.retep.org.uk/pdf




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

* sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
@ 1999-08-02 19:23  Jens Glaser <jens@helena.jens.de>
  0 siblings, 2 replies; 5+ messages in thread

From: Jens Glaser @ 1999-08-02 19:23 UTC (permalink / raw)
  To: peter@retep.org.uk; +Cc: pgsql-interfaces

Hi,

here's just another annoying bug in the JDBC driver:

ResultSetMetaData.getColumnDisplaySize() returns the length of the
*column label*, but it is expected to return the max width of the column!

Sorry, I don't have a fix right now, maybe I get around writing one today
or so ..

kind regards,

-- 
Jens Glaser     Am Holderstrauch 13, 36041 Fulda, 0661/9429507    jens@jens.de




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

* Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
@ 1999-08-03 07:43  Hannu Krosing <hannu@trust.ee>
  parent: Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>
  1 sibling, 0 replies; 5+ messages in thread

From: Hannu Krosing @ 1999-08-03 07:43 UTC (permalink / raw)
  To: Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>; +Cc: jens@jens.de; pgsql-interfaces

"Ross J. Reedstrom" wrote:
> 
> On Mon, Aug 02, 1999 at 07:23:07PM +0000, Jens Glaser wrote:
> > Hi,
> >
> > here's just another annoying bug in the JDBC driver:
> >
> > ResultSetMetaData.getColumnDisplaySize() returns the length of the
> > *column label*, but it is expected to return the max width of the column!
> >
> 
> Hmm, the Zope Python interface suffers from the same problem (and the
> same work around): lack of column width info, substituting the column
> label length.

I'm not sure that this info is available through libpq but it appeared
at 
least to protocol level in about 6.4 for variable length fields (it has 
always been there for fixed width of course). At least ODBC drivers do
use it.

-------
 Hannu



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

* Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
@ 1999-08-04 02:33  Jens Glaser <jens@helena.jens.de>
  parent: Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>
  1 sibling, 0 replies; 5+ messages in thread

From: Jens Glaser @ 1999-08-04 02:33 UTC (permalink / raw)
  To: Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>; +Cc: 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@jens.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@jens.de




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


end of thread, other threads:[~1999-08-04 02:33 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-08-02 19:23 sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize) Jens Glaser <jens@helena.jens.de>
1999-08-02 18:12 ` Ross J. Reedstrom <reedstrm@wallace.ece.rice.edu>
1999-08-03 07:43   ` Hannu Krosing <hannu@trust.ee>
1999-08-04 02:33   ` Jens Glaser <jens@helena.jens.de>
1999-08-02 18:51 ` 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