[libpostgresql-jdbc-java] 04/07: 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:18 UTC 2017


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

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

commit 197e509665f6d5122a5c2ac654a4d5eea34b37d8
Author: Kris Jurka <books at ejurka.com>
Date:   Thu Mar 12 04:00:20 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 a8259e0..0357120 100644
--- a/org/postgresql/core/Field.java
+++ b/org/postgresql/core/Field.java
@@ -3,7 +3,7 @@
 * Copyright (c) 2003-2005, PostgreSQL Global Development Group
 *
 * IDENTIFICATION
-*   $PostgreSQL: pgjdbc/org/postgresql/core/Field.java,v 1.9 2004/11/09 08:44:27 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/core/Field.java,v 1.10 2005/01/11 08:25:43 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 6d59c84..e6ccafe 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.2.4 2007/07/15 15:10:18 jurka Exp $
+*   $PostgreSQL: pgjdbc/org/postgresql/jdbc2/AbstractJdbc2DatabaseMetaData.java,v 1.24.2.5 2007/07/23 17:30:52 jurka Exp $
 *
 *-------------------------------------------------------------------------
 */
@@ -2399,7 +2399,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 " +
+            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 " +
                   " 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) " +
@@ -2415,7 +2415,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 " +
+            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 " +
                   " FROM pg_class c " +
                   " JOIN pg_attribute a ON (a.attrelid=c.oid) " +
                   " LEFT JOIN pg_attrdef def ON (a.attrelid=def.adrelid AND a.attnum = def.adnum) " +

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