Skip to content

Commit 4945a8f

Browse files
author
Neil Conway
committed
Teach psql's \lo slash commands to respect quiet mode, and to output
HTML in HTML mode. Patch from Jeremy Drake.
1 parent 24ac4c9 commit 4945a8f

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

doc/src/sgml/ref/psql-ref.sgml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.179 2006/12/19 01:53:36 adunstan Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/psql-ref.sgml,v 1.180 2007/01/20 16:57:31 neilc Exp $
33
PostgreSQL documentation
44
-->
55

@@ -1329,11 +1329,12 @@ Tue Oct 26 21:40:57 CEST 1999
13291329
foo=&gt; <userinput>\lo_import '/home/peter/pictures/photo.xcf' 'a picture of me'</userinput>
13301330
lo_import 152801
13311331
</programlisting>
1332-
The response indicates that the large object received object ID
1333-
152801 which one ought to remember if one wants to access the
1334-
object ever again. For that reason it is recommended to always
1335-
associate a human-readable comment with every object. Those can
1336-
then be seen with the <command>\lo_list</command> command.
1332+
The response indicates that the large object received object
1333+
ID 152801, which can be used to access the newly-created large
1334+
object in the future. For the sake of readability, it is
1335+
recommended to always associate a human-readable comment with
1336+
every object. Both OIDs and comments can be viewed with the
1337+
<command>\lo_list</command> command.
13371338
</para>
13381339

13391340
<para>

src/bin/psql/large_obj.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright (c) 2000-2007, PostgreSQL Global Development Group
55
*
6-
* $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.47 2007/01/05 22:19:49 momjian Exp $
6+
* $PostgreSQL: pgsql/src/bin/psql/large_obj.c,v 1.48 2007/01/20 16:57:31 neilc Exp $
77
*/
88
#include "postgres_fe.h"
99
#include "large_obj.h"
@@ -12,6 +12,39 @@
1212
#include "settings.h"
1313
#include "common.h"
1414

15+
static void
16+
print_lo_result(const char *fmt,...)
17+
__attribute__((format(printf, 1, 2)));
18+
19+
static void
20+
print_lo_result(const char *fmt,...)
21+
{
22+
va_list ap;
23+
24+
if (!pset.quiet)
25+
{
26+
if (pset.popt.topt.format == PRINT_HTML)
27+
fputs("<p>", pset.queryFout);
28+
29+
va_start(ap, fmt);
30+
vfprintf(pset.queryFout, fmt, ap);
31+
va_end(ap);
32+
33+
if (pset.popt.topt.format == PRINT_HTML)
34+
fputs("</p>\n", pset.queryFout);
35+
else
36+
fputs("\n", pset.queryFout);
37+
}
38+
39+
if (pset.logfile)
40+
{
41+
va_start(ap, fmt);
42+
vfprintf(pset.logfile, fmt, ap);
43+
va_end(ap);
44+
fputs("\n", pset.logfile);
45+
}
46+
}
47+
1548

1649
/*
1750
* 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)
129162
if (!finish_lo_xact("\\lo_export", own_transaction))
130163
return false;
131164

132-
fprintf(pset.queryFout, "lo_export\n");
165+
print_lo_result("lo_export");
133166

134167
return true;
135168
}
@@ -189,7 +222,8 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
189222
if (!finish_lo_xact("\\lo_import", own_transaction))
190223
return false;
191224

192-
fprintf(pset.queryFout, "lo_import %u\n", loid);
225+
print_lo_result("lo_import %u", loid);
226+
193227
sprintf(oidbuf, "%u", loid);
194228
SetVariable(pset.vars, "LASTOID", oidbuf);
195229

@@ -225,7 +259,7 @@ do_lo_unlink(const char *loid_arg)
225259
if (!finish_lo_xact("\\lo_unlink", own_transaction))
226260
return false;
227261

228-
fprintf(pset.queryFout, "lo_unlink %u\n", loid);
262+
print_lo_result("lo_unlink %u", loid);
229263

230264
return true;
231265
}

0 commit comments

Comments
 (0)