*** ./describe.c.orig Thu Mar 28 10:36:06 2002 --- ./describe.c Thu Mar 28 10:58:27 2002 *************** *** 693,704 **** } else if (view_def) { /* Footer information about a view */ ! footers = xmalloc(2 * sizeof(*footers)); ! footers[0] = xmalloc(64 + strlen(view_def)); ! snprintf(footers[0], 64 + strlen(view_def), _("View definition: %s"), view_def); ! footers[1] = NULL; } else if (tableinfo.relkind == 'r') { --- 693,743 ---- } else if (view_def) { + PGresult *result = NULL; + int rule_count = 0; + int count_footers = 0; + + /* count rules */ + if (!error && tableinfo.hasrules) + { + sprintf(buf, + "SELECT r.rulename\n" + "FROM pg_rewrite r, pg_class c\n" + "WHERE c.relname='%s' AND c.oid = r.ev_class\n" + "AND r.rulename NOT LIKE '_RET%%'", + name); + result = PSQLexec(buf); + if (!result) + error = true; + else + rule_count = PQntuples(result); + } + /* Footer information about a view */ ! footers = xmalloc((rule_count + 2) * sizeof(*footers)); ! footers[count_footers] = xmalloc(64 + strlen(view_def)); ! snprintf(footers[count_footers], 64 + strlen(view_def), _("View definition: %s"), view_def); ! count_footers++; ! ! /* print rules */ ! for (i = 0; i < rule_count; i++) ! { ! char *s = _("Rules"); ! ! if (i == 0) ! snprintf(buf, sizeof(buf), "%s: %s", s, PQgetvalue(result, i, 0)); ! else ! snprintf(buf, sizeof(buf), "%*s %s", (int) strlen(s), "", PQgetvalue(result, i, 0)); ! if (i < rule_count - 1) ! strcat(buf, ","); ! ! footers[count_footers++] = xstrdup(buf); ! } ! PQclear(result); ! ! footers[count_footers] = NULL; ! } else if (tableinfo.relkind == 'r') {