Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize)
От | Jens Glaser |
---|---|
Тема | Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize) |
Дата | |
Msg-id | Pine.LNX.4.05.9908040227260.3810-100000@helena.jens.de обсуждение исходный текст |
Ответ на | Re: [INTERFACES] sigh .. another bug in the JDBC driver (ResultSetMetaData.getColumnDisplaySize) ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>) |
Список | 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 is2, etc. * @return the maximum width * @exception SQLException if a database access error occurs */ public int getColumnDisplaySize(intcolumn) 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" fornumeric 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 likethis: 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
В списке pgsql-interfaces по дате отправления: