*************** *** 7,13 **** * * * IDENTIFICATION - - * $Header: /usr/local/devel/pglite/cvs/src/libpq/fe-exec.c,v 1.10 1996/02/24 01:22:23 jolly Exp $ * *------------------------------------------------------------------------- */ --- 7,13 ---- * * * IDENTIFICATION + * $Header: /home/jolly/POSTGRES_MASTER_CVS/src/libpq/fe-exec.c,v 1.9 1995/10/31 07:51:57 jolly Exp $ * *------------------------------------------------------------------------- */ *************** *** 18,24 **** #include "postgres.h" #include "libpq/pqcomm.h" #include "libpq-fe.h" - -#include /* the tuples array in a PGresGroup has to grow to accommodate the tuples */ /* returned. Each time, we grow by this much: */ --- 18,23 ---- #include "postgres.h" #include "libpq/pqcomm.h" #include "libpq-fe.h" /* the tuples array in a PGresGroup has to grow to accommodate the tuples */ /* returned. Each time, we grow by this much: */ *************** *** 39,45 **** static void addTuple(PGresult *res, PGresAttValue *tup); static PGresAttValue* getTuple(PGconn *conn, PGresult *res, int binary); static PGresult* makeEmptyPGresult(PGconn *conn, ExecStatusType status); - -static void fill(int length, int max, char filler, FILE *fp); /* * PQclear - --- 38,43 ---- static void addTuple(PGresult *res, PGresAttValue *tup); static PGresAttValue* getTuple(PGconn *conn, PGresult *res, int binary); static PGresult* makeEmptyPGresult(PGconn *conn, ExecStatusType status); /* * PQclear - *************** *** 607,739 **** } } - -/* simply send out max-length number of filler characters to fp */ - -static void - -fill (int length, int max, char filler, FILE *fp) - -{ - - int count; - - char filltmp[2]; - - - - filltmp[0] = filler; - - filltmp[1] = 0; - - count = max - length; - - while (count-- >= 0) - - { - - fprintf(fp, "%s", filltmp); - - } - - } - - - - - -/* - - * PQdisplayTuples() - - * - - * a better version of PQprintTuples() - - * that can optionally do padding of fields with spaces and use different - - * field separators - - */ - -void - -PQdisplayTuples(PGresult *res, - - FILE *fp, /* where to send the output */ - - int fillAlign, /* pad the fields with spaces */ - - char *fieldSep, /* field separator */ - - int printHeader, /* display headers? */ - - int quiet - - ) - -{ - -#define DEFAULT_FIELD_SEP " " - - - - char *pager; - - int i, j; - - int nFields; - - int nTuples; - - int fLength[MAX_FIELDS]; - - int usePipe = 0; - - - - if (fieldSep == NULL) - - fieldSep == DEFAULT_FIELD_SEP; - - - - if (fp == NULL) - - fp = stdout; - - if (fp == stdout) { - - /* try to pipe to the pager program if possible */ - - pager=getenv("PAGER"); - - if (pager != NULL) { - - fp = popen(pager, "w"); - - if (fp) { - - usePipe = 1; - - signal(SIGPIPE, SIG_IGN); - - } else - - fp = stdout; - - } - - } - - - - /* Get some useful info about the results */ - - nFields = PQnfields(res); - - nTuples = PQntuples(res); - - - - /* Zero the initial field lengths */ - - for (j=0 ; j < nFields; j++) { - - fLength[j] = strlen(PQfname(res,j)); - - } - - /* Find the max length of each field in the result */ - - /* will be somewhat time consuming for very large results */ - - if (fillAlign) { - - for (i=0; i < nTuples; i++) { - - for (j=0 ; j < nFields; j++) { - - if (PQgetlength(res,i,j) > fLength[j]) - - fLength[j] = PQgetlength(res,i,j); - - } - - } - - } - - - - if (printHeader) { - - /* first, print out the attribute names */ - - for (i=0; i < nFields; i++) { - - fputs(PQfname(res,i), fp); - - if (fillAlign) - - fill (strlen (PQfname(res,i)), fLength[i], ' ', fp); - - fputs(fieldSep,fp); - - } - - fprintf(fp, "\n"); - - - - /* Underline the attribute names */ - - for (i=0; i < nFields; i++) { - - if (fillAlign) - - fill (0, fLength[i], '-', fp); - - fputs(fieldSep,fp); - - } - - fprintf(fp, "\n"); - - } - - - - /* next, print out the instances */ - - for (i=0; i < nTuples; i++) { - - for (j=0 ; j < nFields; j++) { - - fprintf(fp, "%s", PQgetvalue(res,i,j)); - - if (fillAlign) - - fill (strlen (PQgetvalue(res,i,j)), fLength[j], ' ', fp); - - fputs(fieldSep,fp); - - } - - fprintf(fp, "\n"); - - } - - - - if (!quiet) - - fprintf (fp, "\nQuery returned %d row%s.\n",PQntuples(res), - - (PQntuples(res) == 1) ? "" : "s"); - - - - fflush(fp); - - if (usePipe) { - - pclose(fp); - - signal(SIGPIPE, SIG_DFL); - - } - -} - - /* - - * PQprintTuples() * * This is the routine that prints out the tuples that - - * are returned from the backend. * Right now all columns are of fixed length, * this should be changed to allow wrap around for * tuples values that are wider. --- 605,617 ---- } } /* + * print_tuples() * * This is the routine that prints out the tuples that + * are returned from the backend. * Right now all columns are of fixed length, * this should be changed to allow wrap around for * tuples values that are wider.