0001-Test-implement-of-dynamic-loadable-output-filter.patch

text/x-patch

Filename: 0001-Test-implement-of-dynamic-loadable-output-filter.patch
Type: text/x-patch
Part: 0
Message: Re: psql: add \pset true/false

Patch

Format: unified
Series: patch 0001
File+
src/bin/psql/command.c 8 0
src/bin/psql/Makefile 1 1
src/bin/psql/print.c 6 0
>From ac5e917a1bd802c37e56dc0861adb8807126d2eb Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Thu, 3 Dec 2015 14:38:03 +0900
Subject: [PATCH] Test implement of dynamic-loadable output filter.

This is a minimum implement so that psql can dynamically load output
filter module. As a test code, this can load only by slash command, no
unload or reload or preloasd feature.
---
 src/bin/psql/Makefile  | 2 +-
 src/bin/psql/command.c | 8 ++++++++
 src/bin/psql/print.c   | 6 ++++++
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/src/bin/psql/Makefile b/src/bin/psql/Makefile
index f1336d5..2fb1fd1 100644
--- a/src/bin/psql/Makefile
+++ b/src/bin/psql/Makefile
@@ -23,7 +23,7 @@ override CPPFLAGS := -I. -I$(srcdir) -I$(libpq_srcdir) -I$(top_srcdir)/src/bin/p
 OBJS=	command.o common.o help.o input.o stringutils.o mainloop.o copy.o \
 	startup.o prompt.o variables.o large_obj.o print.o describe.o \
 	tab-complete.o mbprint.o dumputils.o keywords.o kwlookup.o \
-	sql_help.o \
+	sql_help.o dlload.o\
 	$(WIN32RES)
 
 
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 438a4ec..4101d99 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -40,6 +40,7 @@
 #include "common.h"
 #include "copy.h"
 #include "describe.h"
+#include "dlload.h"
 #include "help.h"
 #include "input.h"
 #include "large_obj.h"
@@ -1001,6 +1002,13 @@ exec_command(const char *cmd,
 		free(opt2);
 	}
 
+	else if (strcmp(cmd, "load_dll") == 0)
+	{
+		char *opt1 = psql_scan_slash_option(scan_state,
+											OT_NORMAL, NULL, true);
+		expand_tilde(&opt1);
+		success = do_dlload(opt1);
+	}
 
 	/* \o -- set query output */
 	else if (strcmp(cmd, "o") == 0 || strcmp(cmd, "out") == 0)
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index ad4350e..37febb2 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -27,6 +27,7 @@
 #include "common.h"
 #include "mbprint.h"
 #include "print.h"
+#include "dlload.h"
 
 /*
  * We define the cancel_pressed flag in this file, rather than common.c where
@@ -3210,6 +3211,11 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, FILE *f
 			else
 			{
 				cell = PQgetvalue(result, r, c);
+
+				/* Call output filter if registered */
+				if (outputfilter)
+					cell = outputfilter(cell, PQftype(result, c), (&mustfree));
+
 				if (cont.aligns[c] == 'r' && opt->topt.numericLocale)
 				{
 					cell = format_numeric_locale(cell);
-- 
1.8.3.1