|
3 | 3 | *
|
4 | 4 | * Copyright 2000 by PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.47 2002/03/20 19:44:45 tgl Exp $ |
| 6 | + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.48 2002/04/05 11:52:38 momjian Exp $ |
7 | 7 | */
|
8 | 8 | #include "postgres_fe.h"
|
9 | 9 | #include "describe.h"
|
@@ -692,12 +692,51 @@ describeTableDetails(const char *name, bool desc)
|
692 | 692 | }
|
693 | 693 | else if (view_def)
|
694 | 694 | {
|
| 695 | + PGresult *result = NULL; |
| 696 | + int rule_count = 0; |
| 697 | + int count_footers = 0; |
| 698 | + |
| 699 | + /* count rules */ |
| 700 | + if (!error && tableinfo.hasrules) |
| 701 | + { |
| 702 | + sprintf(buf, |
| 703 | + "SELECT r.rulename\n" |
| 704 | + "FROM pg_rewrite r, pg_class c\n" |
| 705 | + "WHERE c.relname='%s' AND c.oid = r.ev_class\n" |
| 706 | + "AND r.rulename NOT LIKE '_RET%%'", |
| 707 | + name); |
| 708 | + result = PSQLexec(buf); |
| 709 | + if (!result) |
| 710 | + error = true; |
| 711 | + else |
| 712 | + rule_count = PQntuples(result); |
| 713 | + } |
| 714 | + |
695 | 715 | /* Footer information about a view */
|
696 |
| - footers = xmalloc(2 * sizeof(*footers)); |
697 |
| - footers[0] = xmalloc(64 + strlen(view_def)); |
698 |
| - snprintf(footers[0], 64 + strlen(view_def), |
| 716 | + footers = xmalloc((rule_count + 2) * sizeof(*footers)); |
| 717 | + footers[count_footers] = xmalloc(64 + strlen(view_def)); |
| 718 | + snprintf(footers[count_footers], 64 + strlen(view_def), |
699 | 719 | _("View definition: %s"), view_def);
|
700 |
| - footers[1] = NULL; |
| 720 | + count_footers++; |
| 721 | + |
| 722 | + /* print rules */ |
| 723 | + for (i = 0; i < rule_count; i++) |
| 724 | + { |
| 725 | + char *s = _("Rules"); |
| 726 | + |
| 727 | + if (i == 0) |
| 728 | + snprintf(buf, sizeof(buf), "%s: %s", s, PQgetvalue(result, i, 0)); |
| 729 | + else |
| 730 | + snprintf(buf, sizeof(buf), "%*s %s", (int) strlen(s), "", PQgetvalue(result, i, 0)); |
| 731 | + if (i < rule_count - 1) |
| 732 | + strcat(buf, ","); |
| 733 | + |
| 734 | + footers[count_footers++] = xstrdup(buf); |
| 735 | + } |
| 736 | + PQclear(result); |
| 737 | + |
| 738 | + footers[count_footers] = NULL; |
| 739 | + |
701 | 740 | }
|
702 | 741 | else if (tableinfo.relkind == 'r')
|
703 | 742 | {
|
|
0 commit comments