[libpostgresql-jdbc-java] 05/09: Don't use pg_attrdef.adsrc to display a column's default value. This can get out of date when dependent objects are renamed. Instead decompile the adbin column to fetch up to date information.

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


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

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

commit a027641bd44249b49c869e1b6506096a59c7b40f
Author: Kris Jurka <books at ejurka.com>
Date:   Thu Mar 12 03:59:58 2009 +0000

    Don't use pg_attrdef.adsrc to display a column's default value.
    This can get out of date when dependent objects are renamed.
    Instead decompile the adbin column to fetch up to date information.
    
    Per complaint from Dickson S. Guedes and suggestion from Tom Lane
    for the fix.
---
 org/postgresql/core/Field.java                          | 11 ++++++-----
 org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java |  6 +++---
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/org/postgresql/core/Field.java b/org/postgresql/core/Field.java
index 93ac3df..e626d07 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.11 2005/12/03 21:44:08 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/Field.java,v 1.12 2008/01/08 06:56:27 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -195,10 +195,11 @@ public class Field
         PreparedStatement ps = null;
         try
         {
-            final String sql = "SELECT def.adsrc FROM pg_catalog.pg_class c " +
-                               "JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) " +
-                               "LEFT JOIN pg_catalog.pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) " +
-                               "WHERE c.oid = ? and a.attnum = ? AND def.adsrc LIKE '%nextval(%'";
+            final String sql = "SELECT 1 "
+                                + " FROM pg_catalog.pg_attrdef "
+                                + " WHERE adrelid = ? AND adnum = ? "
+                                + "  AND pg_catalog.pg_get_expr(adbin, adrelid) "
+                                + "      LIKE '%nextval(%'";
 
             ps = con.prepareStatement(sql);
 
diff --git a/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java b/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java
index 45bba7a..c2e3eda 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.44.2.1 2008/11/07 09:11:48 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.44.2.2 2009/03/12 03:34:35 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -2249,7 +2249,7 @@ public abstract class AbstractJdbc2DatabaseMetaData
         String sql;
         if (connection.haveMinimumServerVersion("7.3"))
         {
-            sql = "SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description,t.typbasetype,t.typtype " +
+            sql = "SELECT n.nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,pg_catalog.pg_get_expr(def.adbin, def.adrelid) AS adsrc,dsc.description,t.typbasetype,t.typtype " +
                   " FROM pg_catalog.pg_namespace n " +
                   " JOIN pg_catalog.pg_class c ON (c.relnamespace = n.oid) " +
                   " JOIN pg_catalog.pg_attribute a ON (a.attrelid=c.oid) " +
@@ -2266,7 +2266,7 @@ public abstract class AbstractJdbc2DatabaseMetaData
         }
         else if (connection.haveMinimumServerVersion("7.2"))
         {
-            sql = "SELECT NULL::text AS nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,def.adsrc,dsc.description,NULL::oid AS typbasetype,t.typtype " +
+            sql = "SELECT NULL::text AS nspname,c.relname,a.attname,a.atttypid,a.attnotnull,a.atttypmod,a.attlen,a.attnum,pg_get_expr(def.adbin,def.adrelid) AS adsrc,dsc.description,NULL::oid AS typbasetype,t.typtype " +
                   " FROM pg_class c " +
                   " JOIN pg_attribute a ON (a.attrelid=c.oid) " +
                   " JOIN pg_type t ON (a.atttypid = t.oid) " +

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