|
3 | 3 | *
|
4 | 4 | * Copyright 2000 by PostgreSQL Global Development Group
|
5 | 5 | *
|
6 |
| - * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.35 2001/07/08 14:42:17 petere Exp $ |
| 6 | + * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.36 2001/08/05 22:13:46 tgl Exp $ |
7 | 7 | */
|
8 | 8 | #include"postgres_fe.h"
|
9 | 9 | #include"describe.h"
|
|
27 | 27 | */
|
28 | 28 |
|
29 | 29 | /* the maximal size of regular expression we'll accept here */
|
30 |
| -/* (it issave to just change this here) */ |
31 |
| -#defineREGEXP_CUTOFF 10 * NAMEDATALEN |
| 30 | +/* (it issafe to just change this here) */ |
| 31 | +#defineREGEXP_CUTOFF(10 * NAMEDATALEN) |
32 | 32 |
|
33 | 33 |
|
34 | 34 | /* \da
|
@@ -637,49 +637,65 @@ describeTableDetails(const char *name, bool desc)
|
637 | 637 | }
|
638 | 638 |
|
639 | 639 | /* Make footers */
|
640 |
| -/* Information about the index */ |
641 | 640 | if (tableinfo.relkind=='i')
|
642 | 641 | {
|
| 642 | +/* Footer information about an index */ |
643 | 643 | PGresult*result;
|
644 | 644 |
|
645 |
| -sprintf(buf,"SELECT i.indisunique, i.indisprimary, i.indislossy, a.amname\n" |
| 645 | +sprintf(buf,"SELECT i.indisunique, i.indisprimary, i.indislossy, a.amname,\n" |
| 646 | +" pg_get_expr(i.indpred, i.indrelid) as indpred\n" |
646 | 647 | "FROM pg_index i, pg_class c, pg_am a\n"
|
647 | 648 | "WHERE i.indexrelid = c.oid AND c.relname = '%s' AND c.relam = a.oid",
|
648 | 649 | name);
|
649 | 650 |
|
650 | 651 | result=PSQLexec(buf);
|
651 |
| -if (!result) |
| 652 | +if (!result||PQntuples(result)!=1) |
652 | 653 | error= true;
|
653 | 654 | else
|
654 | 655 | {
|
| 656 | +char*indisunique=PQgetvalue(result,0,0); |
| 657 | +char*indisprimary=PQgetvalue(result,0,1); |
| 658 | +char*indislossy=PQgetvalue(result,0,2); |
| 659 | +char*indamname=PQgetvalue(result,0,3); |
| 660 | +char*indpred=PQgetvalue(result,0,4); |
| 661 | + |
| 662 | +footers=xmalloc(3*sizeof(*footers)); |
655 | 663 | /* XXX This construction is poorly internationalized. */
|
656 |
| -footers=xmalloc(2*sizeof(*footers)); |
657 | 664 | footers[0]=xmalloc(NAMEDATALEN+128);
|
658 |
| -snprintf(footers[0],NAMEDATALEN+128,"%s%s%s", |
659 |
| -strcmp(PQgetvalue(result,0,0),"t")==0 ?_("unique ") :"", |
660 |
| -PQgetvalue(result,0,3), |
661 |
| -strcmp(PQgetvalue(result,0,2),"t")==0 ?_(" (lossy)") :"" |
662 |
| -); |
663 |
| -if (strcmp(PQgetvalue(result,0,1),"t")==0) |
| 665 | +snprintf(footers[0],NAMEDATALEN+128,"%s%s", |
| 666 | +strcmp(indisunique,"t")==0 ?_("unique ") :"", |
| 667 | +indamname); |
| 668 | +if (strcmp(indisprimary,"t")==0) |
664 | 669 | snprintf(footers[0]+strlen(footers[0]),
|
665 | 670 | NAMEDATALEN+128-strlen(footers[0]),
|
666 | 671 | _(" (primary key)"));
|
667 |
| -footers[1]=NULL; |
| 672 | +if (strcmp(indislossy,"t")==0) |
| 673 | +snprintf(footers[0]+strlen(footers[0]), |
| 674 | +NAMEDATALEN+128-strlen(footers[0]), |
| 675 | +_(" (lossy)")); |
| 676 | +if (strlen(indpred)>0) |
| 677 | +{ |
| 678 | +footers[1]=xmalloc(64+strlen(indpred)); |
| 679 | +snprintf(footers[1],64+strlen(indpred), |
| 680 | +_("Index predicate: %s"),indpred); |
| 681 | +footers[2]=NULL; |
| 682 | +} |
| 683 | +else |
| 684 | +footers[1]=NULL; |
668 | 685 | }
|
669 | 686 | }
|
670 |
| -/* Information about the view */ |
671 | 687 | elseif (view_def)
|
672 | 688 | {
|
| 689 | +/* Footer information about a view */ |
673 | 690 | footers=xmalloc(2*sizeof(*footers));
|
674 | 691 | footers[0]=xmalloc(64+strlen(view_def));
|
675 | 692 | snprintf(footers[0],64+strlen(view_def),
|
676 | 693 | _("View definition: %s"),view_def);
|
677 | 694 | footers[1]=NULL;
|
678 | 695 | }
|
679 |
| - |
680 |
| -/* Information about the table */ |
681 | 696 | elseif (tableinfo.relkind=='r')
|
682 | 697 | {
|
| 698 | +/* Footer information about a table */ |
683 | 699 | PGresult*result1=NULL,
|
684 | 700 | *result2=NULL,
|
685 | 701 | *result3=NULL,
|
|