diff options
author | Tom Lane | 2005-08-15 21:02:26 +0000 |
---|---|---|
committer | Tom Lane | 2005-08-15 21:02:26 +0000 |
commit | 9a9328003d65f2b5f1a9598ea423db37952976ca (patch) | |
tree | 2ef0e0c10d89fd8be56e2cccb489bf548ef54633 /src/bin/scripts/common.c | |
parent | 866ffc2fe35f63b06fb6ed63ef1f531a741d920e (diff) |
Make createlang and droplang proof against weird search_path settings
by forcing search_path to be just pg_catalog.
Diffstat (limited to 'src/bin/scripts/common.c')
-rw-r--r-- | src/bin/scripts/common.c | 54 |
1 files changed, 46 insertions, 8 deletions
diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c index 4bffa5003f8..7036ef1b1c5 100644 --- a/src/bin/scripts/common.c +++ b/src/bin/scripts/common.c @@ -1,22 +1,28 @@ /*------------------------------------------------------------------------- * - * Miscellaneous shared code + * common.c + * Common support routines for bin/scripts/ + * * * Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * - * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.17 2005/02/22 04:41:30 momjian Exp $ + * $PostgreSQL: pgsql/src/bin/scripts/common.c,v 1.18 2005/08/15 21:02:26 tgl Exp $ * *------------------------------------------------------------------------- */ #include "postgres_fe.h" -#include "common.h" -#include "libpq-fe.h" #include <pwd.h> #include <unistd.h> +#include "common.h" + +#ifndef HAVE_INT_OPTRESET +int optreset; +#endif + /* * Returns the current user name. @@ -55,7 +61,8 @@ get_user_name(const char *progname) * options. */ void -handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, help_handler hlp) +handle_help_version_opts(int argc, char *argv[], + const char *fixed_progname, help_handler hlp) { if (argc > 1) { @@ -79,7 +86,8 @@ handle_help_version_opts(int argc, char *argv[], const char *fixed_progname, hel */ PGconn * connectDatabase(const char *dbname, const char *pghost, const char *pgport, - const char *pguser, bool require_password, const char *progname) + const char *pguser, bool require_password, + const char *progname) { PGconn *conn; char *password = NULL; @@ -146,8 +154,10 @@ executeQuery(PGconn *conn, const char *query, const char *progname, bool echo) if (!res || PQresultStatus(res) != PGRES_TUPLES_OK) { - fprintf(stderr, _("%s: query failed: %s"), progname, PQerrorMessage(conn)); - fprintf(stderr, _("%s: query was: %s\n"), progname, query); + fprintf(stderr, _("%s: query failed: %s"), + progname, PQerrorMessage(conn)); + fprintf(stderr, _("%s: query was: %s\n"), + progname, query); PQfinish(conn); exit(1); } @@ -157,6 +167,34 @@ executeQuery(PGconn *conn, const char *query, const char *progname, bool echo) /* + * As above for a SQL command (which returns nothing). + */ +void +executeCommand(PGconn *conn, const char *query, + const char *progname, bool echo) +{ + PGresult *res; + + if (echo) + printf("%s\n", query); + + res = PQexec(conn, query); + if (!res || + PQresultStatus(res) != PGRES_COMMAND_OK) + { + fprintf(stderr, _("%s: query failed: %s"), + progname, PQerrorMessage(conn)); + fprintf(stderr, _("%s: query was: %s\n"), + progname, query); + PQfinish(conn); + exit(1); + } + + PQclear(res); +} + + +/* * Check yes/no answer in a localized way. 1=yes, 0=no, -1=neither. */ |