pgpool2.git / summary / log / commit / refs

commit    ee7b628f9f6a06147bf8f013f3caa23480b515b7
Author:   Tatsuo Ishii <ishii at sraoss.co.jp>
Date:     Mon Sep 06 02:39:18 2010 +0000

    Add pgpool_regclass function. This is an alternative for regclassin.
    Problem is, regclassin throws an error if invalid table name is
    specified and pgpool's internal query fails.
    Someday we might have such a builtin function but until that day
    we use pgpool_regclass instead...


sql/pgpool-regclass/Makefile | 20 ++++++++++ sql/pgpool-regclass/pgpool-regclass.c | 63 ++++++++++++++++++++++++++++++ sql/pgpool-regclass/pgpool-regclass.sql.in | 4 ++ 3 files changed, 87 insertions(+) diff --git a/sql/pgpool-regclass/Makefile b/sql/pgpool-regclass/Makefile new file mode 100644 index 000000000..f283b8c73 --- /dev/null +++ b/sql/pgpool-regclass/Makefile @@ -0,0 +1,20 @@ +MODULES = pgpool-regclass +DATA_built = pgpool-regclass.sql + +# if you are using PostgreSQL 8.0 or later, +# using pg_config is recommended. +# if you are not, comment out following line and... +USE_PGXS = true +# set top_builddir to the PostgreSQL build source tree top. +# (for example /usr/local/src/postgresql-8.4) +top_builddir = ../.. + +ifdef USE_PGXS +PGXS = $(shell pg_config --pgxs) +include $(PGXS) +else +subdir = contrib/pgpool-regclass +#top_builddir = ../.. +include $(top_builddir)/src/Makefile.global +include $(top_srcdir)/contrib/contrib-global.mk +endif diff --git a/sql/pgpool-regclass/pgpool-regclass.c b/sql/pgpool-regclass/pgpool-regclass.c new file mode 100644 index 000000000..9e98fff7d --- /dev/null +++ b/sql/pgpool-regclass/pgpool-regclass.c @@ -0,0 +1,63 @@ +/* -*-pgsql-c-*- */ +/* + * $Header$ + * + * Copyright (c) 2003-2010 PgPool Global Development Group + * + * Permission to use, copy, modify, and distribute this software and + * its documentation for any purpose and without fee is hereby + * granted, provided that the above copyright notice appear in all + * copies and that both that copyright notice and this permission + * notice appear in supporting documentation, and that the name of the + * author not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior + * permission. The author makes no representations about the + * suitability of this software for any purpose. It is provided "as + * is" without express or implied warranty. + * + * pgpool-regclass.c is similar to PostgreSQL builtin function + * reglcass but do not throw exception. + * If something goes wrong, it returns InvalidOid. + * + * CAUTION: This function uses PG_TRY() and related family macros which + * are only available on 8.0 or later. + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> +#include "postgres.h" +#include "utils/builtins.h" +#include "utils/elog.h" +#include "fmgr.h" +#include "funcapi.h" + +#include <stdlib.h> + +#ifdef PG_MODULE_MAGIC +PG_MODULE_MAGIC; +#endif + +PG_FUNCTION_INFO_V1(pgpool_regclass); + +extern Datum pgpool_regclass(PG_FUNCTION_ARGS); + +Datum +pgpool_regclass(PG_FUNCTION_ARGS) +{ + char *pro_name_or_oid = PG_GETARG_CSTRING(0); + Oid result; + + PG_TRY(); + { + result = DirectFunctionCall1(regclassin, + CStringGetDatum(pro_name_or_oid)); + } + PG_CATCH(); + { + result = InvalidOid; + } + PG_END_TRY(); + + PG_RETURN_OID(result); +} diff --git a/sql/pgpool-regclass/pgpool-regclass.sql.in b/sql/pgpool-regclass/pgpool-regclass.sql.in new file mode 100644 index 000000000..b7b2be2cb --- /dev/null +++ b/sql/pgpool-regclass/pgpool-regclass.sql.in @@ -0,0 +1,4 @@ +CREATE OR REPLACE FUNCTION pgpool_regclass(cstring) +RETURNS oid +AS 'MODULE_PATHNAME', 'pgpool_regclass' +LANGUAGE C STRICT; [parent: 62a79f01dbf8]