]> granicus.if.org Git - postgresql/commitdiff
Here is a patch for DatabaseMetaData to show precision properly. It is
authorBruce Momjian <bruce@momjian.us>
Wed, 24 Oct 2001 17:44:28 +0000 (17:44 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 24 Oct 2001 17:44:28 +0000 (17:44 +0000)
from Mark Lillywhite.  I am adding to the patch queue.

src/interfaces/jdbc/org/postgresql/jdbc2/DatabaseMetaData.java

index 6cb522466cf14de78f6dccfd1e38f1109b07c0f7..44ed49a2c613bf268de16a4a117df007888477d0 100644 (file)
@@ -13,7 +13,7 @@ import org.postgresql.util.PSQLException;
 /**
  * This class provides information about the database as a whole.
  *
- * $Id: DatabaseMetaData.java,v 1.38 2001/10/24 04:31:50 barry Exp $
+ * $Id: DatabaseMetaData.java,v 1.39 2001/10/24 17:44:28 momjian Exp $
  *
  * <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
@@ -1999,7 +1999,18 @@ public class DatabaseMetaData implements java.sql.DatabaseMetaData
                }
 
                tuple[7] = null;                                                // Buffer length
-               tuple[8] = "0".getBytes();                              // Decimal Digits - how to get this?
+        // Decimal digits = scale
+        // From the source (see e.g. backend/utils/adt/numeric.c, 
+        // function numeric()) the scale and precision can be calculated
+        // from the typmod value. mark@plasticsoftware.com.au
+        if (typname.equals("numeric") || typname.equals("decimal")) 
+        { 
+          int attypmod = r.getInt(8);
+          tuple[8] =
+            Integer.toString((attypmod & 0xffff) - VARHDRSZ).getBytes();
+        }
+        else
+          tuple[8] = "0".getBytes();
                tuple[9] = "10".getBytes();                             // Num Prec Radix - assume decimal
                tuple[10] = Integer.toString(nullFlag.equals("f") ?
                        java.sql.DatabaseMetaData.columnNullable :