From 6aa0821bcd6626162149c887a8ecda29645e1048 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 7 Feb 2001 21:30:12 +0000 Subject: [PATCH] Redo pgaccess' queries about views so that they will work in both 7.1 and prior releases --- rely on pg_views view instead of direct access to pg_class and pg_rewrite. --- src/bin/pgaccess/lib/database.tcl | 27 ++++++++++++--------------- src/bin/pgaccess/lib/mainlib.tcl | 16 +++++++--------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/bin/pgaccess/lib/database.tcl b/src/bin/pgaccess/lib/database.tcl index 828baf0992..fb4395bc2f 100644 --- a/src/bin/pgaccess/lib/database.tcl +++ b/src/bin/pgaccess/lib/database.tcl @@ -4,24 +4,21 @@ proc {getTablesList} {} { global CurrentDB PgAcVar set tlist {} if {[catch { - wpg_select $CurrentDB "select c.relname,count(c.relname) from pg_class C, pg_rewrite R where (r.ev_class = C.oid) and (r.ev_type = '1') group by relname" rec { - if {$rec(count)!=0} { - set itsaview($rec(relname)) 1 - } + # As of Postgres 7.1, testing for view-ness is not needed + # because relkind = 'r' eliminates views. But we should + # leave the code in for awhile yet, so as not to fail when + # running against older releases. + wpg_select $CurrentDB "select viewname from pg_views" rec { + set itsaview($rec(viewname)) 1 } if {! $PgAcVar(pref,systemtables)} { - wpg_select $CurrentDB "select relname from pg_class where (relname !~ '^pg_') and (relkind='r') order by relname" rec { - if {![regexp "^pga_" $rec(relname)]} then { - if {![info exists itsaview($rec(relname))]} { - lappend tlist $rec(relname) - } - } - } + set sysconstraint "and (relname !~ '^pg_') and (relname !~ '^pga_')" } else { - wpg_select $CurrentDB "select relname from pg_class where (relkind='r') order by relname" rec { - if {![info exists itsaview($rec(relname))]} { - lappend tlist $rec(relname) - } + set sysconstraint "" + } + wpg_select $CurrentDB "select relname from pg_class where (relkind='r') $sysconstraint order by relname" rec { + if {![info exists itsaview($rec(relname))]} { + lappend tlist $rec(relname) } } } gterrmsg]} { diff --git a/src/bin/pgaccess/lib/mainlib.tcl b/src/bin/pgaccess/lib/mainlib.tcl index e5c01f30af..15675b29c3 100644 --- a/src/bin/pgaccess/lib/mainlib.tcl +++ b/src/bin/pgaccess/lib/mainlib.tcl @@ -295,19 +295,17 @@ catch { } proc {cmd_Views} {} { -global CurrentDB +global CurrentDB PgAcVar setCursor CLOCK .pgaw:Main.lb delete 0 end catch { - wpg_select $CurrentDB "select c.relname,count(c.relname) from pg_class C, pg_rewrite R where (relname !~ '^pg_') and (r.ev_class = C.oid) and (r.ev_type = '1') group by relname" rec { - if {$rec(count)!=0} { - set itsaview($rec(relname)) 1 - } + if {! $PgAcVar(pref,systemtables)} { + set sysconstraint "where (viewname !~ '^pg_') and (viewname !~ '^pga_')" + } else { + set sysconstraint "" } - wpg_select $CurrentDB "select relname from pg_class where (relname !~ '^pg_') and (relkind='r') and (relhasrules) order by relname" rec { - if {[info exists itsaview($rec(relname))]} { - .pgaw:Main.lb insert end $rec(relname) - } + wpg_select $CurrentDB "select viewname from pg_views $sysconstraint order by viewname" rec { + .pgaw:Main.lb insert end $rec(viewname) } } setCursor DEFAULT -- 2.40.0