[libpostgresql-jdbc-java] 05/14: Add scale information for time/timestamp/interval to DatabaseMetaData.getColumns. Include knowledge of interval in ResultSetMetaData.

Emmanuel Bourg ebourg-guest at moszumanska.debian.org
Mon Jan 9 10:19:50 UTC 2017


This is an automated email from the git hooks/post-receive script.

ebourg-guest pushed a commit to tag REL8_1_405
in repository libpostgresql-jdbc-java.

commit 5c996c34ec81019e718c51117a059ac3cbd7c46f
Author: Kris Jurka <books at ejurka.com>
Date:   Sun Dec 4 20:23:00 2005 +0000

    Add scale information for time/timestamp/interval to
    DatabaseMetaData.getColumns.  Include knowledge of interval
    in ResultSetMetaData.
    
    As reported by Thomas Okken.
---
 .../jdbc2/AbstractJdbc2DatabaseMetaData.java       | 18 +++++-
 .../jdbc2/AbstractJdbc2ResultSetMetaData.java      | 66 +++++++++++++++-------
 2 files changed, 62 insertions(+), 22 deletions(-)

diff --git a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
index 97e95b5..0f28ce5 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.24 2005/09/14 19:08:50 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.24.2.1 2005/11/29 06:02:16 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -2506,6 +2506,22 @@ public abstract class AbstractJdbc2DatabaseMetaData
                 tuple[6] = rs.getBytes("atttypmod");
                 tuple[9] = connection.encodeString("2");
             }
+            else if (pgType.equals("time") || pgType.equals("timetz") || pgType.equals("timestamp") || pgType.equals("timestamptz")) {
+                int scale = rs.getInt("atttypmod");
+                if (scale == -1)
+                    scale = 6;
+                tuple[8] = connection.encodeString(Integer.toString(scale));
+                tuple[6] = rs.getBytes("attlen");
+            }
+            else if (pgType.equals("interval")) {
+                int scale = rs.getInt("atttypmod");
+                if (scale == -1)
+                        scale = 6;
+                else
+                        scale = scale & 0xFFFF;
+                tuple[8] = connection.encodeString(Integer.toString(scale));
+                tuple[6] = rs.getBytes("attlen");
+            }
             else
             {
                 tuple[6] = rs.getBytes("attlen");
diff --git a/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java b/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
index 56fc4c5..207acff 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java,v 1.18 2005/09/29 23:04:45 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSetMetaData.java,v 1.18.2.1 2005/11/23 21:54:02 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -364,6 +364,7 @@ public abstract class AbstractJdbc2ResultSetMetaData implements PGResultSetMetaD
     public int getPrecision(int column) throws SQLException
     {
         int sql_type = getSQLType(column);
+        Field field;
 
         switch (sql_type)
         {
@@ -371,24 +372,35 @@ public abstract class AbstractJdbc2ResultSetMetaData implements PGResultSetMetaD
             return 5;
         case Types.INTEGER:
             return 10;
+        case Types.BIGINT:
+            return 19;
         case Types.REAL:
             return 8;
         case Types.FLOAT:
             return 16;
         case Types.DOUBLE:
             return 16;
+        case Types.CHAR:
         case Types.VARCHAR:
-            return 0;
+            field = getField(column);
+            int typmod = -1;
+            if (field != null)
+            {
+                typmod = field.getMod();
+            }
+            if (typmod == -1)
+                return 0;
+            return field.getMod() - 4;
         case Types.NUMERIC:
-            Field f = getField(column);
-            if (f != null)
+            field = getField(column);
+            if (field != null)
             {
                 // no specified precision or scale
-                if (f.getMod() == -1)
+                if (field.getMod() == -1)
                 {
                     return -1;
                 }
-                return ((0xFFFF0000)&f.getMod()) >> 16;
+                return ((0xFFFF0000)&field.getMod()) >> 16;
             }
             else
             {
@@ -411,30 +423,27 @@ public abstract class AbstractJdbc2ResultSetMetaData implements PGResultSetMetaD
     {
         int sql_type = getSQLType(column);
 
+        Field field;
+        int typmod;
+
         switch (sql_type)
         {
-        case Types.SMALLINT:
-            return 0;
-        case Types.INTEGER:
-            return 0;
         case Types.REAL:
             return 8;
         case Types.FLOAT:
             return 16;
         case Types.DOUBLE:
             return 16;
-        case Types.VARCHAR:
-            return 0;
         case Types.NUMERIC:
-            Field f = getField(column);
-            if (f != null)
+            field = getField(column);
+            if (field != null)
             {
                 // no specified precision or scale
-                if (f.getMod() == -1)
+                if (field.getMod() == -1)
                 {
                     return -1;
                 }
-                return (((0x0000FFFF)&f.getMod()) - 4);
+                return (((0x0000FFFF)&field.getMod()) - 4);
             }
             else
             {
@@ -442,16 +451,31 @@ public abstract class AbstractJdbc2ResultSetMetaData implements PGResultSetMetaD
             }
         case Types.TIME:
         case Types.TIMESTAMP:
-            int typmod = -1;
-
-            Field fld = getField(column);
-            if (fld != null)
-                typmod = fld.getMod();
+            typmod = -1;
+            field = getField(column);
+            if (field != null)
+                typmod = field.getMod();
 
             if (typmod == -1)
                 return 6;
 
             return typmod;
+        case Types.OTHER:
+            String type = getColumnTypeName(column);
+
+            if ("interval".equals(type)) {
+                typmod = -1;
+                field = getField(column);
+                if (field != null)
+                    typmod = field.getMod();
+
+                if (typmod == -1)
+                    return 6;
+
+                return typmod & 0xFFFF;
+            }
+
+            return 0;
         default:
             return 0;
         }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/libpostgresql-jdbc-java.git



More information about the pkg-java-commits mailing list