aboutsummaryrefslogtreecommitdiff
path: root/src/interfaces
diff options
context:
space:
mode:
Diffstat (limited to 'src/interfaces')
-rw-r--r--src/interfaces/libpq++/pgdatabase.cc10
-rw-r--r--src/interfaces/libpq/fe-misc.c56
-rw-r--r--src/interfaces/libpq/fe-print.c417
-rw-r--r--src/interfaces/libpq/libpq-fe.h78
4 files changed, 270 insertions, 291 deletions
diff --git a/src/interfaces/libpq++/pgdatabase.cc b/src/interfaces/libpq++/pgdatabase.cc
index f34354be416..545c71c08d3 100644
--- a/src/interfaces/libpq++/pgdatabase.cc
+++ b/src/interfaces/libpq++/pgdatabase.cc
@@ -10,7 +10,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.8 1999/10/13 16:46:28 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq++/Attic/pgdatabase.cc,v 1.9 2000/01/29 16:58:52 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -26,9 +26,9 @@ void PgDatabase::DisplayTuples(FILE *out, int fillAlign,
memset(&po,0,sizeof(po));
- po.align = (pqbool)fillAlign;
+ po.align = fillAlign;
po.fieldSep = (char *)fieldSep;
- po.header = (pqbool)printHeader;
+ po.header = printHeader;
PQprint(out,pgResult,&po);
}
@@ -43,12 +43,12 @@ void PgDatabase::PrintTuples(FILE *out, int printAttName, int terseOutput,
memset(&po,0,sizeof(po));
- po.align = (pqbool)width;
+ po.align = width;
if(terseOutput) po.fieldSep = strdup("|");
else po.fieldSep = "";
- po.header = (pqbool)printAttName;
+ po.header = printAttName;
PQprint(out,pgResult,&po);
}
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index 074c1249d38..ff6acefea8f 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -25,7 +25,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.37 2000/01/26 05:58:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.38 2000/01/29 16:58:51 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -51,6 +51,11 @@
#include "libpq-int.h"
#include "pqsignal.h"
+#ifdef MULTIBYTE
+#include "miscadmin.h"
+#include "mb/pg_wchar.h"
+#endif
+
#define DONOTICE(conn,message) \
((*(conn)->noticeHook) ((conn)->noticeArg, (message)))
@@ -737,3 +742,52 @@ pqWait(int forRead, int forWrite, PGconn *conn)
return 0;
}
+
+
+
+/*
+ * A couple of "miscellaneous" multibyte related functions. They used
+ * to be in fe-print.c but that file is doomed.
+ */
+
+#ifdef MULTIBYTE
+/*
+ * returns the byte length of the word beginning s, using the
+ * specified encoding.
+ */
+int
+PQmblen(const unsigned char *s, int encoding)
+{
+ return (pg_encoding_mblen(encoding, s));
+}
+
+/*
+ * Get encoding id from environment variable PGCLIENTENCODING.
+ */
+int
+PQenv2encoding(void)
+{
+ char *str;
+ int encoding = SQL_ASCII;
+
+ str = getenv("PGCLIENTENCODING");
+ if (str && *str != '\0')
+ encoding = pg_char_to_encoding(str);
+ return(encoding);
+}
+
+#else
+
+/* Provide a default definition in case someone calls it anyway */
+int
+PQmblen(const unsigned char *s, int encoding)
+{
+ return 1;
+}
+int
+PQenv2encoding(void)
+{
+ return 0;
+}
+
+#endif /* MULTIBYTE */
diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c
index 6bf778d5a30..7c0e655f2a8 100644
--- a/src/interfaces/libpq/fe-print.c
+++ b/src/interfaces/libpq/fe-print.c
@@ -10,13 +10,13 @@
* didn't really belong there.
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.32 2000/01/26 05:58:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.33 2000/01/29 16:58:51 petere Exp $
*
*-------------------------------------------------------------------------
*/
-#include <signal.h>
+#include <postgres.h>
-#include "postgres.h"
+#include <signal.h>
#include "libpq-fe.h"
#include "libpq-int.h"
#include "pqsignal.h"
@@ -36,21 +36,14 @@
#endif
#endif
-#ifdef MULTIBYTE
-#include "miscadmin.h"
-#include "mb/pg_wchar.h"
-#endif
-
#ifdef TIOCGWINSZ
static struct winsize screen_size;
-
#else
static struct winsize
{
int ws_row;
int ws_col;
} screen_size;
-
#endif
@@ -66,7 +59,6 @@ static char *do_header(FILE *fout, const PQprintOpt *po, const int nFields,
static void output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
unsigned char *fieldNotNum, int *fieldMax, char *border,
const int row_index);
-static void fill(int length, int max, char filler, FILE *fp);
/*
@@ -78,7 +70,9 @@ static void fill(int length, int max, char filler, FILE *fp);
* various flags and options. consult libpq-fe.h for
* details
*
- * Obsoletes PQprintTuples.
+ * This function should probably be removed sometime since psql
+ * doesn't use it anymore. It is unclear to what extend this is used
+ * by external clients, however.
*/
void
@@ -315,229 +309,6 @@ PQprint(FILE *fout,
}
-/*
- * PQdisplayTuples()
- * kept for backward compatibility
- */
-
-void
-PQdisplayTuples(const PGresult *res,
- FILE *fp, /* where to send the output */
- int fillAlign, /* pad the fields with spaces */
- const char *fieldSep, /* field separator */
- int printHeader,/* display headers? */
- int quiet
-)
-{
-#define DEFAULT_FIELD_SEP " "
-
- int i,
- j;
- int nFields;
- int nTuples;
- int *fLength = NULL;
-
- if (fieldSep == NULL)
- fieldSep = DEFAULT_FIELD_SEP;
-
- /* Get some useful info about the results */
- nFields = PQnfields(res);
- nTuples = PQntuples(res);
-
- if (fp == NULL)
- fp = stdout;
-
- /* Figure the field lengths to align to */
- /* will be somewhat time consuming for very large results */
- if (fillAlign)
- {
- fLength = (int *) malloc(nFields * sizeof(int));
- for (j = 0; j < nFields; j++)
- {
- fLength[j] = strlen(PQfname(res, j));
- for (i = 0; i < nTuples; i++)
- {
- int flen = PQgetlength(res, i, j);
- if (flen > fLength[j])
- fLength[j] = flen;
- }
- }
- }
-
- 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 (fLength)
- free(fLength);
-}
-
-
-
-/*
- * PQprintTuples()
- *
- * kept for backward compatibility
- *
- */
-void
-PQprintTuples(const PGresult *res,
- FILE *fout, /* output stream */
- int PrintAttNames,/* print attribute names or not */
- int TerseOutput, /* delimiter bars or not? */
- int colWidth /* width of column, if 0, use variable
- * width */
-)
-{
- int nFields;
- int nTups;
- int i,
- j;
- char formatString[80];
-
- char *tborder = NULL;
-
- nFields = PQnfields(res);
- nTups = PQntuples(res);
-
- if (colWidth > 0)
- sprintf(formatString, "%%s %%-%ds", colWidth);
- else
- sprintf(formatString, "%%s %%s");
-
- if (nFields > 0)
- { /* only print rows with at least 1 field. */
-
- if (!TerseOutput)
- {
- int width;
-
- width = nFields * 14;
- tborder = malloc(width + 1);
- for (i = 0; i <= width; i++)
- tborder[i] = '-';
- tborder[i] = '\0';
- fprintf(fout, "%s\n", tborder);
- }
-
- for (i = 0; i < nFields; i++)
- {
- if (PrintAttNames)
- {
- fprintf(fout, formatString,
- TerseOutput ? "" : "|",
- PQfname(res, i));
- }
- }
-
- if (PrintAttNames)
- {
- if (TerseOutput)
- fprintf(fout, "\n");
- else
- fprintf(fout, "|\n%s\n", tborder);
- }
-
- for (i = 0; i < nTups; i++)
- {
- for (j = 0; j < nFields; j++)
- {
- const char *pval = PQgetvalue(res, i, j);
-
- fprintf(fout, formatString,
- TerseOutput ? "" : "|",
- pval ? pval : "");
- }
- if (TerseOutput)
- fprintf(fout, "\n");
- else
- fprintf(fout, "|\n%s\n", tborder);
- }
- }
-}
-
-#ifdef MULTIBYTE
-/*
- * returns the byte length of the word beginning s.
- * Client side encoding is determined by the environment variable
- * "PGCLIENTENCODING".
- * if this variable is not defined, the same encoding as
- * the backend is assumed.
- */
-int
-PQmblen(const unsigned char *s, int encoding)
-{
- return (pg_encoding_mblen(encoding, s));
-}
-
-/*
- * Get encoding id from environment variable PGCLIENTENCODING.
- */
-int
-PQenv2encoding(void)
-{
- char *str;
- int encoding = SQL_ASCII;
-
- str = getenv("PGCLIENTENCODING");
- if (str && *str != '\0')
- encoding = pg_char_to_encoding(str);
- return(encoding);
-}
-
-#else
-
-/* Provide a default definition in case someone calls it anyway */
-int
-PQmblen(const unsigned char *s, int encoding)
-{
- return 1;
-}
-int
-PQenv2encoding(void)
-{
- return 0;
-}
-
-#endif /* MULTIBYTE */
-
static void
do_field(const PQprintOpt *po, const PGresult *res,
const int i, const int j, const int fs_len,
@@ -785,14 +556,176 @@ output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
}
-/* simply send out max-length number of filler characters to fp */
-static void
-fill(int length, int max, char filler, FILE *fp)
+#if 0
+/*
+ * really old printing routines
+ */
+
+void
+PQdisplayTuples(const PGresult *res,
+ FILE *fp, /* where to send the output */
+ int fillAlign, /* pad the fields with spaces */
+ const char *fieldSep, /* field separator */
+ int printHeader,/* display headers? */
+ int quiet
+)
+{
+#define DEFAULT_FIELD_SEP " "
+
+ int i,
+ j;
+ int nFields;
+ int nTuples;
+ int *fLength = NULL;
+
+ if (fieldSep == NULL)
+ fieldSep = DEFAULT_FIELD_SEP;
+
+ /* Get some useful info about the results */
+ nFields = PQnfields(res);
+ nTuples = PQntuples(res);
+
+ if (fp == NULL)
+ fp = stdout;
+
+ /* Figure the field lengths to align to */
+ /* will be somewhat time consuming for very large results */
+ if (fillAlign)
+ {
+ fLength = (int *) malloc(nFields * sizeof(int));
+ for (j = 0; j < nFields; j++)
+ {
+ fLength[j] = strlen(PQfname(res, j));
+ for (i = 0; i < nTuples; i++)
+ {
+ int flen = PQgetlength(res, i, j);
+ if (flen > fLength[j])
+ fLength[j] = flen;
+ }
+ }
+ }
+
+ 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 (fLength)
+ free(fLength);
+}
+
+
+
+void
+PQprintTuples(const PGresult *res,
+ FILE *fout, /* output stream */
+ int PrintAttNames,/* print attribute names or not */
+ int TerseOutput, /* delimiter bars or not? */
+ int colWidth /* width of column, if 0, use variable
+ * width */
+)
{
- int count;
+ int nFields;
+ int nTups;
+ int i,
+ j;
+ char formatString[80];
+
+ char *tborder = NULL;
+
+ nFields = PQnfields(res);
+ nTups = PQntuples(res);
+
+ if (colWidth > 0)
+ sprintf(formatString, "%%s %%-%ds", colWidth);
+ else
+ sprintf(formatString, "%%s %%s");
+
+ if (nFields > 0)
+ { /* only print rows with at least 1 field. */
+
+ if (!TerseOutput)
+ {
+ int width;
+
+ width = nFields * 14;
+ tborder = malloc(width + 1);
+ for (i = 0; i <= width; i++)
+ tborder[i] = '-';
+ tborder[i] = '\0';
+ fprintf(fout, "%s\n", tborder);
+ }
+
+ for (i = 0; i < nFields; i++)
+ {
+ if (PrintAttNames)
+ {
+ fprintf(fout, formatString,
+ TerseOutput ? "" : "|",
+ PQfname(res, i));
+ }
+ }
+
+ if (PrintAttNames)
+ {
+ if (TerseOutput)
+ fprintf(fout, "\n");
+ else
+ fprintf(fout, "|\n%s\n", tborder);
+ }
+
+ for (i = 0; i < nTups; i++)
+ {
+ for (j = 0; j < nFields; j++)
+ {
+ const char *pval = PQgetvalue(res, i, j);
- count = max - length;
- while (count-- >= 0)
- putc(filler, fp);
+ fprintf(fout, formatString,
+ TerseOutput ? "" : "|",
+ pval ? pval : "");
+ }
+ if (TerseOutput)
+ fprintf(fout, "\n");
+ else
+ fprintf(fout, "|\n%s\n", tborder);
+ }
+ }
}
+#endif
diff --git a/src/interfaces/libpq/libpq-fe.h b/src/interfaces/libpq/libpq-fe.h
index d8915b11d39..35bbb6eff3f 100644
--- a/src/interfaces/libpq/libpq-fe.h
+++ b/src/interfaces/libpq/libpq-fe.h
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: libpq-fe.h,v 1.57 2000/01/26 05:58:46 momjian Exp $
+ * $Id: libpq-fe.h,v 1.58 2000/01/29 16:58:51 petere Exp $
*
*-------------------------------------------------------------------------
*/
@@ -116,22 +116,15 @@ extern "C"
/* Print options for PQprint() */
- /*
- * We can't use the conventional "bool", because we are designed to be
- * included in a user's program, and user may already have that type
- * defined. Pqbool, on the other hand, is unlikely to be used.
- */
- typedef char pqbool;
-
typedef struct _PQprintOpt
{
- pqbool header; /* print output field headings and row
+ int header; /* print output field headings and row
* count */
- pqbool align; /* fill align the fields */
- pqbool standard; /* old brain dead format */
- pqbool html3; /* output html tables */
- pqbool expanded; /* expand tables */
- pqbool pager; /* use pager for output if needed */
+ int align; /* fill align the fields */
+ int standard; /* old brain dead format */
+ int html3; /* output html tables */
+ int expanded; /* expand tables */
+ int pager; /* use pager for output if needed */
char *fieldSep; /* field separator */
char *tableOpt; /* insert to HTML <table ...> */
char *caption; /* HTML <caption> */
@@ -296,8 +289,8 @@ extern "C"
extern int PQfsize(const PGresult *res, int field_num);
extern int PQfmod(const PGresult *res, int field_num);
extern const char *PQcmdStatus(const PGresult *res);
- extern const char *PQoidStatus(const PGresult *res); /* old and ugly */
- extern Oid PQoidValue(const PGresult *res); /* new and improved */
+ extern const char *PQoidStatus(const PGresult *res); /* old and ugly */
+ extern Oid PQoidValue(const PGresult *res); /* new and improved */
extern const char *PQcmdTuples(const PGresult *res);
extern const char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
extern int PQgetlength(const PGresult *res, int tup_num, int field_num);
@@ -319,33 +312,24 @@ extern "C"
const PGresult *res,
const PQprintOpt *ps); /* option structure */
- /*
- * PQdisplayTuples() is a better version of PQprintTuples(), but both
- * are obsoleted by PQprint().
- */
- extern void PQdisplayTuples(const PGresult *res,
- FILE *fp, /* where to send the
- * output */
- int fillAlign, /* pad the fields with
- * spaces */
- const char *fieldSep, /* field separator */
- int printHeader, /* display headers? */
- int quiet);
-
- extern void PQprintTuples(const PGresult *res,
- FILE *fout, /* output stream */
- int printAttName, /* print attribute names
- * or not */
- int terseOutput, /* delimiter bars or
- * not? */
- int width); /* width of column, if
- * 0, use variable width */
-
- /* Determine length of multibyte encoded char at *s */
- extern int PQmblen(const unsigned char *s, int encoding);
-
- /* Get encoding id from environment variable PGCLIENTENCODING */
- int PQenv2encoding(void);
+#if 0
+ /*
+ * really old printing routines
+ */
+ extern void PQdisplayTuples(const PGresult *res,
+ FILE *fp, /* where to send the output */
+ int fillAlign, /* pad the fields with spaces */
+ const char *fieldSep, /* field separator */
+ int printHeader, /* display headers? */
+ int quiet);
+
+ extern void PQprintTuples(const PGresult *res,
+ FILE *fout, /* output stream */
+ int printAttName, /* print attribute names */
+ int terseOutput, /* delimiter bars */
+ int width); /* width of column, if
+ * 0, use variable width */
+#endif
/* === in fe-lobj.c === */
@@ -361,6 +345,14 @@ extern "C"
extern Oid lo_import(PGconn *conn, const char *filename);
extern int lo_export(PGconn *conn, Oid lobjId, const char *filename);
+/* === in fe-misc.c === */
+
+ /* Determine length of multibyte encoded char at *s */
+ extern int PQmblen(const unsigned char *s, int encoding);
+
+ /* Get encoding id from environment variable PGCLIENTENCODING */
+ extern int PQenv2encoding(void);
+
#ifdef __cplusplus
};