diff options
author | Neil Conway <neilc@samurai.com> | 2007-01-20 16:57:31 +0000 |
---|---|---|
committer | Neil Conway <neilc@samurai.com> | 2007-01-20 16:57:31 +0000 |
commit | 4945a8fad4efd34b79826f28836c40e294518f43 (patch) | |
tree | 8355ec1ad5c81bfecf2af2fbe35704eb12a0d2c2 /src | |
parent | 24ac4c968c413e2c762dba9596dd6009b02337a7 (diff) | |
download | postgresql-4945a8fad4efd34b79826f28836c40e294518f43.tar.gz postgresql-4945a8fad4efd34b79826f28836c40e294518f43.zip |
Teach psql's \lo slash commands to respect quiet mode, and to output
HTML in HTML mode. Patch from Jeremy Drake.
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/psql/large_obj.c | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c index a55b3af4b11..87918a8850f 100644 --- a/src/bin/psql/large_obj.c +++ b/src/bin/psql/large_obj.c @@ -3,7 +3,7 @@ * * Copyright (c) 2000-2007, PostgreSQL Global Development Group * - * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.47 2007/01/05 22:19:49 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.48 2007/01/20 16:57:31 neilc Exp $ */ #include "postgres_fe.h" #include "large_obj.h" @@ -12,6 +12,39 @@ #include "settings.h" #include "common.h" +static void +print_lo_result(const char *fmt,...) +__attribute__((format(printf, 1, 2))); + +static void +print_lo_result(const char *fmt,...) +{ + va_list ap; + + if (!pset.quiet) + { + if (pset.popt.topt.format == PRINT_HTML) + fputs("<p>", pset.queryFout); + + va_start(ap, fmt); + vfprintf(pset.queryFout, fmt, ap); + va_end(ap); + + if (pset.popt.topt.format == PRINT_HTML) + fputs("</p>\n", pset.queryFout); + else + fputs("\n", pset.queryFout); + } + + if (pset.logfile) + { + va_start(ap, fmt); + vfprintf(pset.logfile, fmt, ap); + va_end(ap); + fputs("\n", pset.logfile); + } +} + /* * Prepare to do a large-object operation. We *must* be inside a transaction @@ -129,7 +162,7 @@ do_lo_export(const char *loid_arg, const char *filename_arg) if (!finish_lo_xact("\\lo_export", own_transaction)) return false; - fprintf(pset.queryFout, "lo_export\n"); + print_lo_result("lo_export"); return true; } @@ -189,7 +222,8 @@ do_lo_import(const char *filename_arg, const char *comment_arg) if (!finish_lo_xact("\\lo_import", own_transaction)) return false; - fprintf(pset.queryFout, "lo_import %u\n", loid); + print_lo_result("lo_import %u", loid); + sprintf(oidbuf, "%u", loid); SetVariable(pset.vars, "LASTOID", oidbuf); @@ -225,7 +259,7 @@ do_lo_unlink(const char *loid_arg) if (!finish_lo_xact("\\lo_unlink", own_transaction)) return false; - fprintf(pset.queryFout, "lo_unlink %u\n", loid); + print_lo_result("lo_unlink %u", loid); return true; } |