Commit 6aa0821b authored by Tom Lane's avatar Tom Lane

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.
parent 62a029b5
...@@ -4,26 +4,23 @@ proc {getTablesList} {} { ...@@ -4,26 +4,23 @@ proc {getTablesList} {} {
global CurrentDB PgAcVar global CurrentDB PgAcVar
set tlist {} set tlist {}
if {[catch { 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 { # As of Postgres 7.1, testing for view-ness is not needed
if {$rec(count)!=0} { # because relkind = 'r' eliminates views. But we should
set itsaview($rec(relname)) 1 # 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)} { if {! $PgAcVar(pref,systemtables)} {
wpg_select $CurrentDB "select relname from pg_class where (relname !~ '^pg_') and (relkind='r') order by relname" rec { set sysconstraint "and (relname !~ '^pg_') and (relname !~ '^pga_')"
if {![regexp "^pga_" $rec(relname)]} then {
if {![info exists itsaview($rec(relname))]} {
lappend tlist $rec(relname)
}
}
}
} else { } else {
wpg_select $CurrentDB "select relname from pg_class where (relkind='r') order by relname" rec { set sysconstraint ""
}
wpg_select $CurrentDB "select relname from pg_class where (relkind='r') $sysconstraint order by relname" rec {
if {![info exists itsaview($rec(relname))]} { if {![info exists itsaview($rec(relname))]} {
lappend tlist $rec(relname) lappend tlist $rec(relname)
} }
} }
}
} gterrmsg]} { } gterrmsg]} {
showError $gterrmsg showError $gterrmsg
} }
......
...@@ -295,19 +295,17 @@ catch { ...@@ -295,19 +295,17 @@ catch {
} }
proc {cmd_Views} {} { proc {cmd_Views} {} {
global CurrentDB global CurrentDB PgAcVar
setCursor CLOCK setCursor CLOCK
.pgaw:Main.lb delete 0 end .pgaw:Main.lb delete 0 end
catch { 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 {! $PgAcVar(pref,systemtables)} {
if {$rec(count)!=0} { set sysconstraint "where (viewname !~ '^pg_') and (viewname !~ '^pga_')"
set itsaview($rec(relname)) 1 } 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 setCursor DEFAULT
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment