[libpostgresql-jdbc-java] 08/15: If a domain has a not null constraint, report that information in the metadata for both DatabaseMetaData.getColumns and ResultSetMetaData.isNullable.

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


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

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

commit 2fcd5ec6f92b267a43f41ba17cefc5de2f9e13c5
Author: Kris Jurka <books at ejurka.com>
Date:   Sat Oct 23 07:31:00 2010 +0000

    If a domain has a not null constraint, report that information
    in the metadata for both DatabaseMetaData.getColumns and
    ResultSetMetaData.isNullable.
    
    Reported by Thomas Kellerer
---
 org/postgresql/core/Field.java                     |  4 ++--
 .../jdbc2/AbstractJdbc2DatabaseMetaData.java       |  4 ++--
 .../test/jdbc2/DatabaseMetaDataTest.java           | 24 +++++++++++++++++++++-
 3 files changed, 27 insertions(+), 5 deletions(-)

diff --git a/org/postgresql/core/Field.java b/org/postgresql/core/Field.java
index e626d07..f783819 100644
--- a/org/postgresql/core/Field.java
+++ b/org/postgresql/core/Field.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2003-2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/Field.java,v 1.12 2008/01/08 06:56:27 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/Field.java,v 1.13 2009/03/12 03:59:50 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -159,7 +159,7 @@ public class Field
         PreparedStatement ps = null;
         try
         {
-            ps = con.prepareStatement("SELECT attnotnull FROM pg_catalog.pg_attribute WHERE attrelid = ? AND attnum = ?;");
+            ps = con.prepareStatement("SELECT a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) FROM pg_catalog.pg_attribute a JOIN pg_catalog.pg_type t ON (a.atttypid = t.oid) WHERE a.attrelid = ? AND a.attnum = ?;");
             ps.setInt(1, tableOid);
             ps.setInt(2, positionInTable);
             res = ps.executeQuery();
diff --git a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
index 08ad0e6..58e7a63 100644
--- a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
+++ b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.51.2.5 2010/08/10 19:46:19 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.51.2.6 2010/10/16 00:39:14 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -2281,7 +2281,7 @@ public abstract class AbstractJdbc2DatabaseMetaData
             else
                 sql = "";
 
-            sql += "SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,";
+            sql += "SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull OR (t.typtype = 'd' AND t.typnotnull) AS attnotnull,a.atttypmod,a.attlen,";
             
             if (connection.haveMinimumServerVersion("8.4"))
                 sql += "row_number() OVER (PARTITION BY a.attrelid ORDER BY a.attnum) AS attnum, ";
diff --git a/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java b/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
index 7dd072c..07c5369 100644
--- a/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
+++ b/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2004-2008, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java,v 1.44.2.2 2009/12/09 01:06:41 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/test/jdbc2/DatabaseMetaDataTest.java,v 1.44.2.3 2010/10/16 00:39:14 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -55,6 +55,11 @@ public class DatabaseMetaDataTest extends TestCase
             stmt.execute("CREATE OR REPLACE FUNCTION f3(IN a int, INOUT b varchar, OUT c timestamptz) AS $f$ BEGIN b := 'a'; c := now(); return; END; $f$ LANGUAGE 'plpgsql'");
         }
         stmt.execute("CREATE OR REPLACE FUNCTION f4(int) RETURNS testmetadata AS 'SELECT 1, ''a''::text, now(), ''c''::text, ''q''::text' LANGUAGE 'SQL'");
+
+        if (TestUtil.haveMinimumServerVersion(con, "7.3")) {
+            stmt.execute("CREATE DOMAIN nndom AS int not null");
+            stmt.execute("CREATE TABLE domaintable (id nndom)");
+        }
         stmt.close();
     }
 
@@ -80,6 +85,10 @@ public class DatabaseMetaDataTest extends TestCase
         if (TestUtil.haveMinimumServerVersion(con, "8.1")) {
             stmt.execute("DROP FUNCTION f3(int, varchar)");
         }
+        if (TestUtil.haveMinimumServerVersion(con, "7.3")) {
+            stmt.execute("DROP TABLE domaintable");
+            stmt.execute("DROP DOMAIN nndom");
+        }
 
         TestUtil.closeDB( con );
     }
@@ -1016,4 +1025,17 @@ public class DatabaseMetaDataTest extends TestCase
         assertTrue(!rs.next());
     }
 
+    public void testNotNullDomainColumn() throws SQLException
+    {
+        if (!TestUtil.haveMinimumServerVersion(con, "7.3"))
+            return;
+
+        DatabaseMetaData dbmd = con.getMetaData();
+        ResultSet rs = dbmd.getColumns("", "", "domaintable", "");
+        assertTrue(rs.next());
+        assertEquals("id", rs.getString("COLUMN_NAME"));
+        assertEquals("NO", rs.getString("IS_NULLABLE"));
+        assertTrue(!rs.next());
+    }
+
 }

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