diff options
author | Bruce Momjian <bruce@momjian.us> | 1999-11-26 04:24:17 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1999-11-26 04:24:17 +0000 |
commit | 78bc83fedf7f865534c61dd14067fc80d580ed29 (patch) | |
tree | 48a574c438d31fa6bd28ec87a7f3d413e901bb8f /src/bin/psql/print.c | |
parent | c83b4d1cd8afc557b1efad71e3bf99b81c27e57a (diff) | |
download | postgresql-78bc83fedf7f865534c61dd14067fc80d580ed29.tar.gz postgresql-78bc83fedf7f865534c61dd14067fc80d580ed29.zip |
* Includes tab completion. It's not magic, but it's very cool. At any
rate
it's better than what used to be there.
* Does proper SQL "host variable" substitution as pointed out by Andreas
Zeugwetter (thanks): select * from :foo; Also some changes in how ':'
and ';' are treated (escape with \ to send to backend). This does
_not_
affect the '::' cast operator, but perhaps others that contain : or ;
(but there are none right now).
* To show description with a <something> listing, append '?' to command
name, e.g., \df?. This seemed to be the convenient and logical
solution.
Or append a '+' to see more useless information, e.g., \df+.
* Fixed fflush()'ing bug pointed out by Jan during the regression test
discussion.
* Added LastOid variable. This ought to take care of TODO item "Add a
function to return the last inserted oid, for use in psql scripts"
(under CLIENTS)
E.g.,
insert into foo values(...);
insert into bar values(..., :LastOid);
\echo $LastOid
* \d command shows constraints, rules, and triggers defined on the table
(in addition to indices)
* Various fixes, optimizations, corrections
* Documentation update as well
Note: This now requires snprintf(), which, if necessary, is taken from
src/backend/port. This is certainly a little weird, but it should
suffice
until a source tree cleanup is done.
Enjoy.
--
Peter Eisentraut Sernanders väg 10:115
Diffstat (limited to 'src/bin/psql/print.c')
-rw-r--r-- | src/bin/psql/print.c | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 90b4f59d612..481f76f343e 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -30,8 +30,8 @@ static void print_unaligned_text(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, - const char *opt_fieldsep, bool opt_barebones, - FILE *fout) + const char *opt_fieldsep, bool opt_barebones, + FILE *fout) { unsigned int col_count = 0; unsigned int i; @@ -83,8 +83,8 @@ print_unaligned_text(const char *title, const char * const * headers, static void print_unaligned_vertical(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, - const char *opt_fieldsep, bool opt_barebones, - FILE *fout) + const char *opt_fieldsep, bool opt_barebones, + FILE *fout) { unsigned int col_count = 0; unsigned int i; @@ -172,7 +172,7 @@ static void print_aligned_text(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, const char *opt_align, bool opt_barebones, unsigned short int opt_border, - FILE *fout) + FILE *fout) { unsigned int col_count = 0; unsigned int i, @@ -313,8 +313,8 @@ print_aligned_text(const char *title, const char * const * headers, static void print_aligned_vertical(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, - bool opt_barebones, unsigned short int opt_border, - FILE *fout) + bool opt_barebones, unsigned short int opt_border, + FILE *fout) { unsigned int col_count = 0; unsigned int record = 1; @@ -371,11 +371,10 @@ print_aligned_vertical(const char *title, const char * const * headers, { if (!opt_barebones) { - char *div_copy = strdup(divider); char *record_str = malloc(32); size_t record_str_len; - if (!div_copy || !record_str) + if (!record_str) { perror("malloc"); exit(EXIT_FAILURE); @@ -386,29 +385,32 @@ print_aligned_vertical(const char *title, const char * const * headers, else sprintf(record_str, "[ RECORD %d ]", record++); record_str_len = strlen(record_str); - if (record_str_len + opt_border > strlen(div_copy)) - { - void *new; - - new = realloc(div_copy, record_str_len + opt_border); - if (!new) - { - perror("realloc"); - exit(EXIT_FAILURE); - } - div_copy = new; - } - strncpy(div_copy + opt_border, record_str, record_str_len); - fprintf(fout, "%s\n", div_copy); + + if (record_str_len + opt_border > strlen(divider)) + fprintf(fout, "%.*s%s\n", opt_border, divider, record_str); + else + { + char *div_copy = strdup(divider); + + if (!div_copy) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + strncpy(div_copy + opt_border, record_str, record_str_len); + fprintf(fout, "%s\n", div_copy); + free(div_copy); + } free(record_str); - free(div_copy); } - else if (i != 0 && opt_border < 2) + else if (i != 0 || opt_border == 2) fprintf(fout, "%s\n", divider); } + if (opt_border == 2) fputs("| ", fout); fprintf(fout, "%-*s", hwidth, headers[i % col_count]); + if (opt_border > 0) fputs(" | ", fout); else @@ -479,7 +481,7 @@ print_html_text(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, const char *opt_align, bool opt_barebones, unsigned short int opt_border, const char *opt_table_attr, - FILE *fout) + FILE *fout) { unsigned int col_count = 0; unsigned int i; @@ -661,7 +663,7 @@ static void print_latex_text(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, const char *opt_align, bool opt_barebones, unsigned short int opt_border, - FILE *fout) + FILE *fout) { unsigned int col_count = 0; unsigned int i; @@ -757,7 +759,7 @@ static void print_latex_vertical(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, const char *opt_align, bool opt_barebones, unsigned short int opt_border, - FILE *fout) + FILE *fout) { unsigned int col_count = 0; unsigned int i; @@ -836,7 +838,7 @@ print_latex_vertical(const char *title, const char * const * headers, /********************************/ -/* Public functions */ +/* Public functions */ /********************************/ @@ -845,8 +847,8 @@ printTable(const char *title, const char * const * headers, const char * const * cells, const char * const * footers, - const char *align, - const printTableOpt * opt, FILE *fout) + const char *align, + const printTableOpt * opt, FILE *fout) { const char *default_footer[] = {NULL}; unsigned short int border = opt->border; @@ -968,8 +970,8 @@ printQuery(const PGresult *result, const printQueryOpt * opt, FILE *fout) int nfields; const char **headers; const char **cells; - char **footers; - char *align; + char **footers; + char *align; int i; /* extract headers */ |