Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6aa0821

Browse files
committed
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.
1 parent 62a029b commit 6aa0821

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/bin/pgaccess/lib/database.tcl

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,21 @@ proc {getTablesList} {} {
44
global CurrentDB PgAcVar
55
set tlist {}
66
if {[catch {
7-
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 {
8-
if {$rec(count)!=0} {
9-
set itsaview($rec(relname)) 1
10-
}
7+
# As of Postgres 7.1, testing for view-ness is not needed
8+
# because relkind = 'r' eliminates views. But we should
9+
# leave the code in for awhile yet, so as not to fail when
10+
# running against older releases.
11+
wpg_select $CurrentDB "select viewname from pg_views" rec {
12+
set itsaview($rec(viewname)) 1
1113
}
1214
if {! $PgAcVar(pref,systemtables)} {
13-
wpg_select $CurrentDB "select relname from pg_class where (relname !~ '^pg_') and (relkind='r') order by relname" rec {
14-
if {![regexp "^pga_" $rec(relname)]} then {
15-
if {![info exists itsaview($rec(relname))]} {
16-
lappend tlist $rec(relname)
17-
}
18-
}
19-
}
15+
set sysconstraint "and (relname !~ '^pg_') and (relname !~ '^pga_')"
2016
} else {
21-
wpg_select $CurrentDB "select relname from pg_class where (relkind='r') order by relname" rec {
22-
if {![info exists itsaview($rec(relname))]} {
23-
lappend tlist $rec(relname)
24-
}
17+
set sysconstraint ""
18+
}
19+
wpg_select $CurrentDB "select relname from pg_class where (relkind='r') $sysconstraint order by relname" rec {
20+
if {![info exists itsaview($rec(relname))]} {
21+
lappend tlist $rec(relname)
2522
}
2623
}
2724
} gterrmsg]} {

src/bin/pgaccess/lib/mainlib.tcl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,19 +295,17 @@ catch {
295295
}
296296

297297
proc {cmd_Views} {} {
298-
global CurrentDB
298+
global CurrentDB PgAcVar
299299
setCursor CLOCK
300300
.pgaw:Main.lb delete 0 end
301301
catch {
302-
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 {
303-
if {$rec(count)!=0} {
304-
set itsaview($rec(relname)) 1
305-
}
302+
if {! $PgAcVar(pref,systemtables)} {
303+
set sysconstraint "where (viewname !~ '^pg_') and (viewname !~ '^pga_')"
304+
} else {
305+
set sysconstraint ""
306306
}
307-
wpg_select $CurrentDB "select relname from pg_class where (relname !~ '^pg_') and (relkind='r') and (relhasrules) order by relname" rec {
308-
if {[info exists itsaview($rec(relname))]} {
309-
.pgaw:Main.lb insert end $rec(relname)
310-
}
307+
wpg_select $CurrentDB "select viewname from pg_views $sysconstraint order by viewname" rec {
308+
.pgaw:Main.lb insert end $rec(viewname)
311309
}
312310
}
313311
setCursor DEFAULT

0 commit comments

Comments
 (0)