Commit 521017c5 authored by Dave Cramer's avatar Dave Cramer

patch from Vicktor to fix Numeric decimal digits in getColumns

parent fef790cc
...@@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException; ...@@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException;
/* /*
* This class provides information about the database as a whole. * This class provides information about the database as a whole.
* *
* $Id: DatabaseMetaData.java,v 1.42 2002/02/22 02:40:09 davec Exp $ * $Id: DatabaseMetaData.java,v 1.43 2002/03/05 02:14:06 davec Exp $
* *
* <p>Many of the methods here return lists of information in ResultSets. You * <p>Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to * can use the normal ResultSet methods such as getString and getInt to
...@@ -2017,14 +2017,17 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData ...@@ -2017,14 +2017,17 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
// from the typmod value. // from the typmod value.
if (typname.equals("numeric") || typname.equals("decimal")) if (typname.equals("numeric") || typname.equals("decimal"))
{ {
int attypmod = r.getInt(8); int attypmod = r.getInt(8) - VARHDRSZ;
tuple[8] = tuple[8] =
Integer.toString((attypmod - VARHDRSZ) & 0xffff).getBytes(); Integer.toString(attypmod & 0xffff).getBytes();
tuple[9] =
Integer.toString( ( attypmod >> 16 ) & 0xffff ).getBytes();
} }
else else
{
tuple[8] = "0".getBytes(); tuple[8] = "0".getBytes();
tuple[9] = "10".getBytes(); // Num Prec Radix - assume decimal
tuple[9] = "10".getBytes(); // Num Prec Radix - assume decimal }
tuple[10] = Integer.toString(nullFlag.equals("f") ? tuple[10] = Integer.toString(nullFlag.equals("f") ?
java.sql.DatabaseMetaData.columnNullable : java.sql.DatabaseMetaData.columnNullable :
java.sql.DatabaseMetaData.columnNoNulls).getBytes(); // Nullable java.sql.DatabaseMetaData.columnNoNulls).getBytes(); // Nullable
......
...@@ -15,7 +15,7 @@ import org.postgresql.util.PSQLException; ...@@ -15,7 +15,7 @@ import org.postgresql.util.PSQLException;
/* /*
* This class provides information about the database as a whole. * This class provides information about the database as a whole.
* *
* $Id: DatabaseMetaData.java,v 1.49 2002/02/22 02:17:13 davec Exp $ * $Id: DatabaseMetaData.java,v 1.50 2002/03/05 02:14:08 davec Exp $
* *
* <p>Many of the methods here return lists of information in ResultSets. You * <p>Many of the methods here return lists of information in ResultSets. You
* can use the normal ResultSet methods such as getString and getInt to * can use the normal ResultSet methods such as getString and getInt to
...@@ -2046,17 +2046,17 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData ...@@ -2046,17 +2046,17 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
if ((tableNamePattern != null) && ! tableNamePattern.equals("%")) if ((tableNamePattern != null) && ! tableNamePattern.equals("%"))
{ {
sql.append(" and c.relname like \'" + tableNamePattern + "\'"); sql.append(" and c.relname like \'" + tableNamePattern + "\'");
} }
if ((columnNamePattern != null) && ! columnNamePattern.equals("%")) if ((columnNamePattern != null) && ! columnNamePattern.equals("%"))
{ {
sql.append(" and a.attname like \'" + columnNamePattern + "\'"); sql.append(" and a.attname like \'" + columnNamePattern + "\'");
} }
sql.append( sql.append(
" and a.attnum > 0" + " and a.attnum > 0" +
" )" + " )" +
" ) inner join pg_type t on" + " ) inner join pg_type t on" +
" (" + " (" +
" t.oid = a.atttypid" + " t.oid = a.atttypid" +
...@@ -2112,18 +2112,22 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData ...@@ -2112,18 +2112,22 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[7] = null; // Buffer length tuple[7] = null; // Buffer length
// Decimal digits = scale // Decimal digits = scale
// From the source (see e.g. backend/utils/adt/numeric.c, // From the source (see e.g. backend/utils/adt/format_type.c,
// function numeric()) the scale and precision can be calculated // function numeric()) the scale and precision can be calculated
// from the typmod value. // from the typmod value.
if (typname.equals("numeric") || typname.equals("decimal")) if (typname.equals("numeric") || typname.equals("decimal"))
{ {
int attypmod = r.getInt(8); int attypmod = r.getInt(8) - VARHDRSZ;
tuple[8] = tuple[8] =
Integer.toString((attypmod - VARHDRSZ) & 0xffff).getBytes(); Integer.toString( attypmod & 0xffff ).getBytes();
tuple[9] =
Integer.toString( ( attypmod >> 16 ) & 0xffff ).getBytes();
} }
else else
{
tuple[8] = "0".getBytes(); tuple[8] = "0".getBytes();
tuple[9] = "10".getBytes(); // Num Prec Radix - assume decimal tuple[9] = "10".getBytes(); // Num Prec Radix - assume decimal
}
tuple[10] = Integer.toString(nullFlag.equals("f") ? tuple[10] = Integer.toString(nullFlag.equals("f") ?
java.sql.DatabaseMetaData.columnNullable : java.sql.DatabaseMetaData.columnNullable :
java.sql.DatabaseMetaData.columnNoNulls).getBytes(); // Nullable java.sql.DatabaseMetaData.columnNoNulls).getBytes(); // Nullable
...@@ -2135,7 +2139,6 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData ...@@ -2135,7 +2139,6 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
tuple[16] = r.getBytes(5); // ordinal position tuple[16] = r.getBytes(5); // ordinal position
tuple[17] = (nullFlag.equals("f") ? "YES" : "NO").getBytes(); // Is nullable tuple[17] = (nullFlag.equals("f") ? "YES" : "NO").getBytes(); // Is nullable
v.addElement(tuple);
} }
r.close(); r.close();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment