summaryrefslogtreecommitdiff
path: root/src/bin/psql
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2002-09-04 20:31:48 +0000
committerBruce Momjian <bruce@momjian.us>2002-09-04 20:31:48 +0000
commite50f52a074bdf0d6a9dc384840e641c4c0b0bb1a (patch)
treeab73e8c8ec94a6ddc774c1f9c49b87aa6b93fd13 /src/bin/psql
parentc91ceec21d357d6d857163d897ac75a79c883dee (diff)
downloadpostgresql-e50f52a074bdf0d6a9dc384840e641c4c0b0bb1a.tar.gz
pgindent run.
Diffstat (limited to 'src/bin/psql')
-rw-r--r--src/bin/psql/command.c47
-rw-r--r--src/bin/psql/common.c11
-rw-r--r--src/bin/psql/copy.c20
-rw-r--r--src/bin/psql/describe.c526
-rw-r--r--src/bin/psql/help.c21
-rw-r--r--src/bin/psql/input.h24
-rw-r--r--src/bin/psql/large_obj.c4
-rw-r--r--src/bin/psql/mainloop.c8
-rw-r--r--src/bin/psql/print.h4
-rw-r--r--src/bin/psql/sprompt.c6
-rw-r--r--src/bin/psql/startup.c10
-rw-r--r--src/bin/psql/tab-complete.c50
12 files changed, 378 insertions, 353 deletions
diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 000402216a..b1e451c704 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -3,7 +3,7 @@
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.79 2002/09/02 06:11:42 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.80 2002/09/04 20:31:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "command.h"
@@ -58,7 +58,7 @@ enum option_type
};
static char *scan_option(char **string, enum option_type type,
- char *quote, bool semicolon);
+ char *quote, bool semicolon);
static char *unescape(const unsigned char *source, size_t len);
static bool do_edit(const char *filename_arg, PQExpBuffer query_buf);
@@ -246,13 +246,13 @@ exec_command(const char *cmd,
opt2q;
/*
- * Ideally we should treat the arguments as SQL identifiers. But for
- * backwards compatibility with 7.2 and older pg_dump files, we have
- * to take unquoted arguments verbatim (don't downcase them).
- * For now, double-quoted arguments may be stripped of double quotes
- * (as if SQL identifiers). By 7.4 or so, pg_dump files can be
- * expected to double-quote all mixed-case \connect arguments,
- * and then we can get rid of OT_SQLIDHACK.
+ * Ideally we should treat the arguments as SQL identifiers. But
+ * for backwards compatibility with 7.2 and older pg_dump files,
+ * we have to take unquoted arguments verbatim (don't downcase
+ * them). For now, double-quoted arguments may be stripped of
+ * double quotes (as if SQL identifiers). By 7.4 or so, pg_dump
+ * files can be expected to double-quote all mixed-case \connect
+ * arguments, and then we can get rid of OT_SQLIDHACK.
*/
opt1 = scan_option(&string, OT_SQLIDHACK, &opt1q, true);
opt2 = scan_option(&string, OT_SQLIDHACK, &opt2q, true);
@@ -723,9 +723,7 @@ exec_command(const char *cmd,
if (!quiet)
{
if (pset.timing)
- {
puts(gettext(("Timing is on.")));
- }
else
{
puts(gettext(("Timing is off.")));
@@ -733,7 +731,7 @@ exec_command(const char *cmd,
}
}
}
-
+
/* \unset */
else if (strcmp(cmd, "unset") == 0)
{
@@ -931,8 +929,8 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
/*
* Next command: treat like end of line
*
- * XXX this means we can't conveniently accept options that
- * start with a backslash; therefore, option processing that
+ * XXX this means we can't conveniently accept options that start
+ * with a backslash; therefore, option processing that
* encourages use of backslashes is rather broken.
*/
case '\\':
@@ -1088,7 +1086,8 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
*
* If we are processing the option as a SQL identifier, then
* downcase unquoted letters and remove double-quotes --- but
- * doubled double-quotes become output double-quotes, per spec.
+ * doubled double-quotes become output double-quotes, per
+ * spec.
*
* Note that a string like FOO"BAR"BAZ will be converted to
* fooBARbaz; this is somewhat inconsistent with the SQL spec,
@@ -1124,7 +1123,7 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
else
{
if (*cp != '"')
- break; /* whitespace or end of string */
+ break; /* whitespace or end of string */
if (quote)
*quote = '"';
inquotes = true;
@@ -1150,12 +1149,12 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
/* Strip any trailing semi-colons if requested */
if (semicolon)
{
- int i;
+ int i;
for (i = token_len - 1;
i >= 0 && return_val[i] == ';';
i--)
- /* skip */;
+ /* skip */ ;
if (i < 0)
{
@@ -1169,9 +1168,9 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
}
/*
- * If SQL identifier processing was requested,
- * then we strip out excess double quotes and downcase
- * unquoted letters.
+ * If SQL identifier processing was requested, then we
+ * strip out excess double quotes and downcase unquoted
+ * letters.
*/
if (type == OT_SQLID || type == OT_SQLIDHACK)
{
@@ -1189,7 +1188,7 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
}
inquotes = !inquotes;
/* Collapse out quote at *cp */
- memmove(cp, cp+1, strlen(cp));
+ memmove(cp, cp + 1, strlen(cp));
/* do not advance cp */
}
else
@@ -1550,8 +1549,8 @@ do_edit(const char *filename_arg, PQExpBuffer query_buf)
const char *tmpdirenv = getenv("TMPDIR");
snprintf(fnametmp, sizeof(fnametmp), "%s/psql.edit.%ld.%ld",
- tmpdirenv ? tmpdirenv : "/tmp",
- (long) geteuid(), (long) getpid());
+ tmpdirenv ? tmpdirenv : "/tmp",
+ (long) geteuid(), (long) getpid());
#else
GetTempFileName(".", "psql", 0, fnametmp);
#endif
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index f8bf9c9a35..0277301074 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.43 2002/08/27 20:16:48 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.44 2002/09/04 20:31:35 momjian Exp $
*/
#include "postgres_fe.h"
@@ -295,7 +295,8 @@ SendQuery(const char *query)
bool success = false;
PGresult *results;
PGnotify *notify;
- struct timeval before,after;
+ struct timeval before,
+ after;
struct timezone tz;
if (!pset.db)
@@ -327,14 +328,10 @@ SendQuery(const char *query)
cancelConn = pset.db;
if (pset.timing)
- {
gettimeofday(&before, &tz);
- }
results = PQexec(pset.db, query);
if (pset.timing)
- {
gettimeofday(&after, &tz);
- }
if (PQresultStatus(results) == PGRES_COPY_IN)
copy_in_state = true;
/* keep cancel connection for copy out state */
@@ -467,7 +464,7 @@ SendQuery(const char *query)
/* Possible microtiming output */
if (pset.timing && success)
printf(gettext("Time: %.2f ms\n"),
- ((after.tv_sec-before.tv_sec)*1000000 + after.tv_usec - before.tv_usec) / 1000.0);
+ ((after.tv_sec - before.tv_sec) * 1000000 + after.tv_usec - before.tv_usec) / 1000.0);
return success;
}
diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c
index 32f875db84..90a9006d2b 100644
--- a/src/bin/psql/copy.c
+++ b/src/bin/psql/copy.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.23 2002/06/20 16:00:44 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.24 2002/09/04 20:31:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "copy.h"
@@ -123,7 +123,10 @@ parse_slash_copy(const char *args)
error = true;
else
{
- /* Allows old COPY syntax for backward compatibility 2002-06-19 */
+ /*
+ * Allows old COPY syntax for backward compatibility
+ * 2002-06-19
+ */
if (strcasecmp(token, "with") == 0)
{
token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);
@@ -165,7 +168,10 @@ parse_slash_copy(const char *args)
token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);
if (token)
{
- /* Allows old COPY syntax for backward compatibility 2002-06-19 */
+ /*
+ * Allows old COPY syntax for backward compatibility
+ * 2002-06-19
+ */
if (strcasecmp(token, "using") == 0)
{
token = strtokx(NULL, " \t\n\r", NULL, '\\', NULL, NULL, pset.encoding);
@@ -212,10 +218,12 @@ parse_slash_copy(const char *args)
else
error = true;
}
- else error = true;
+ else
+ error = true;
}
}
- else error = true;
+ else
+ error = true;
}
free(line);
@@ -305,7 +313,7 @@ do_copy(const char *args)
/* make sure the specified file is not a directory */
fstat(fileno(copystream), &st);
- if( S_ISDIR(st.st_mode) )
+ if (S_ISDIR(st.st_mode))
{
fclose(copystream);
psql_error("%s: cannot COPY TO/FROM a directory\n",
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 4bf3b6cc49..239d984a08 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -3,7 +3,7 @@
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.67 2002/08/29 00:17:05 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.68 2002/09/04 20:31:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
@@ -21,13 +21,13 @@
#define _(x) gettext((x))
static bool describeOneTableDetails(const char *schemaname,
- const char *relationname,
- const char *oid,
- bool verbose);
+ const char *relationname,
+ const char *oid,
+ bool verbose);
static void processNamePattern(PQExpBuffer buf, const char *pattern,
- bool have_where, bool force_escape,
- const char *schemavar, const char *namevar,
- const char *altnamevar, const char *visibilityrule);
+ bool have_where, bool force_escape,
+ const char *schemavar, const char *namevar,
+ const char *altnamevar, const char *visibilityrule);
static void *
@@ -71,19 +71,19 @@ describeAggregates(const char *pattern, bool verbose)
* types and ones that work on all (denoted by input type = "any")
*/
printfPQExpBuffer(&buf,
- "SELECT n.nspname as \"%s\",\n"
- " p.proname AS \"%s\",\n"
- " CASE p.proargtypes[0]\n"
- " WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype\n"
- " THEN CAST('%s' AS pg_catalog.text)\n"
- " ELSE pg_catalog.format_type(p.proargtypes[0], NULL)\n"
- " END AS \"%s\",\n"
+ "SELECT n.nspname as \"%s\",\n"
+ " p.proname AS \"%s\",\n"
+ " CASE p.proargtypes[0]\n"
+ " WHEN 'pg_catalog.\"any\"'::pg_catalog.regtype\n"
+ " THEN CAST('%s' AS pg_catalog.text)\n"
+ " ELSE pg_catalog.format_type(p.proargtypes[0], NULL)\n"
+ " END AS \"%s\",\n"
" pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
- "FROM pg_catalog.pg_proc p\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
- "WHERE p.proisagg\n",
- _("Schema"), _("Name"), _("(all types)"),
- _("Data type"), _("Description"));
+ "FROM pg_catalog.pg_proc p\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
+ "WHERE p.proisagg\n",
+ _("Schema"), _("Name"), _("(all types)"),
+ _("Data type"), _("Description"));
processNamePattern(&buf, pattern, true, false,
"n.nspname", "p.proname", NULL,
@@ -119,38 +119,39 @@ describeFunctions(const char *pattern, bool verbose)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
- " n.nspname as \"%s\",\n"
- " p.proname as \"%s\",\n"
- " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\"",
- _("Result data type"), _("Schema"), _("Name"),
- _("Argument data types"));
+ "SELECT pg_catalog.format_type(p.prorettype, NULL) as \"%s\",\n"
+ " n.nspname as \"%s\",\n"
+ " p.proname as \"%s\",\n"
+ " pg_catalog.oidvectortypes(p.proargtypes) as \"%s\"",
+ _("Result data type"), _("Schema"), _("Name"),
+ _("Argument data types"));
if (verbose)
appendPQExpBuffer(&buf,
- ",\n u.usename as \"%s\",\n"
- " l.lanname as \"%s\",\n"
- " p.prosrc as \"%s\",\n"
- " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
- _("Owner"), _("Language"),
- _("Source code"), _("Description"));
+ ",\n u.usename as \"%s\",\n"
+ " l.lanname as \"%s\",\n"
+ " p.prosrc as \"%s\",\n"
+ " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
+ _("Owner"), _("Language"),
+ _("Source code"), _("Description"));
if (!verbose)
appendPQExpBuffer(&buf,
- "\nFROM pg_catalog.pg_proc p"
- "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
+ "\nFROM pg_catalog.pg_proc p"
+ "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
else
appendPQExpBuffer(&buf,
- "\nFROM pg_catalog.pg_proc p"
- "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace"
- "\n LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang"
- "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = p.proowner\n");
+ "\nFROM pg_catalog.pg_proc p"
+ "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace"
+ "\n LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang"
+ "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = p.proowner\n");
/*
- * we skip in/out funcs by excluding functions that take or return cstring
+ * we skip in/out funcs by excluding functions that take or return
+ * cstring
*/
appendPQExpBuffer(&buf,
- "WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
+ "WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
" AND p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
" AND NOT p.proisagg\n");
@@ -190,33 +191,34 @@ describeTypes(const char *pattern, bool verbose)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT n.nspname as \"%s\",\n"
- " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
- _("Schema"), _("Name"));
+ "SELECT n.nspname as \"%s\",\n"
+ " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
+ _("Schema"), _("Name"));
if (verbose)
appendPQExpBuffer(&buf,
- " t.typname AS \"%s\",\n"
- " CASE WHEN t.typrelid != 0\n"
- " THEN CAST('tuple' AS pg_catalog.text)\n"
- " WHEN t.typlen < 0\n"
- " THEN CAST('var' AS pg_catalog.text)\n"
- " ELSE CAST(t.typlen AS pg_catalog.text)\n"
- " END AS \"%s\",\n",
- _("Internal name"), _("Size"));
+ " t.typname AS \"%s\",\n"
+ " CASE WHEN t.typrelid != 0\n"
+ " THEN CAST('tuple' AS pg_catalog.text)\n"
+ " WHEN t.typlen < 0\n"
+ " THEN CAST('var' AS pg_catalog.text)\n"
+ " ELSE CAST(t.typlen AS pg_catalog.text)\n"
+ " END AS \"%s\",\n",
+ _("Internal name"), _("Size"));
appendPQExpBuffer(&buf,
- " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
- _("Description"));
+ " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
+ _("Description"));
appendPQExpBuffer(&buf, "FROM pg_catalog.pg_type t\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
/*
* do not include array types (start with underscore); do not include
- * complex types (typrelid!=0) unless they are standalone composite types
+ * complex types (typrelid!=0) unless they are standalone composite
+ * types
*/
appendPQExpBuffer(&buf, "WHERE (t.typrelid = 0 ");
appendPQExpBuffer(&buf, "OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c "
- "WHERE c.oid = t.typrelid)) ");
+ "WHERE c.oid = t.typrelid)) ");
appendPQExpBuffer(&buf, "AND t.typname !~ '^_'\n");
/* Match name pattern against either internal or external name */
@@ -255,18 +257,18 @@ describeOperators(const char *pattern)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT n.nspname as \"%s\",\n"
- " o.oprname AS \"%s\",\n"
- " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
- " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
- " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n"
- " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
- " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
- "FROM pg_catalog.pg_operator o\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
- _("Schema"), _("Name"),
- _("Left arg type"), _("Right arg type"),
- _("Result type"), _("Description"));
+ "SELECT n.nspname as \"%s\",\n"
+ " o.oprname AS \"%s\",\n"
+ " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
+ " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
+ " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n"
+ " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
+ " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
+ "FROM pg_catalog.pg_operator o\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
+ _("Schema"), _("Name"),
+ _("Left arg type"), _("Right arg type"),
+ _("Result type"), _("Description"));
processNamePattern(&buf, pattern, false, true,
"n.nspname", "o.oprname", NULL,
@@ -304,20 +306,20 @@ listAllDbs(bool verbose)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT d.datname as \"%s\",\n"
- " u.usename as \"%s\"",
- _("Name"), _("Owner"));
+ "SELECT d.datname as \"%s\",\n"
+ " u.usename as \"%s\"",
+ _("Name"), _("Owner"));
appendPQExpBuffer(&buf,
- ",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"",
- _("Encoding"));
+ ",\n pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\"",
+ _("Encoding"));
if (verbose)
appendPQExpBuffer(&buf,
- ",\n pg_catalog.obj_description(d.oid, 'pg_database') as \"%s\"",
- _("Description"));
+ ",\n pg_catalog.obj_description(d.oid, 'pg_database') as \"%s\"",
+ _("Description"));
appendPQExpBuffer(&buf,
"\nFROM pg_catalog.pg_database d"
- "\n LEFT JOIN pg_catalog.pg_user u ON d.datdba = u.usesysid\n"
- "ORDER BY 1;");
+ "\n LEFT JOIN pg_catalog.pg_user u ON d.datdba = u.usesysid\n"
+ "ORDER BY 1;");
res = PSQLexec(buf.data);
termPQExpBuffer(&buf);
@@ -348,26 +350,27 @@ permissionsList(const char *pattern)
initPQExpBuffer(&buf);
/*
- * we ignore indexes and toast tables since they have no meaningful rights
+ * we ignore indexes and toast tables since they have no meaningful
+ * rights
*/
printfPQExpBuffer(&buf,
- "SELECT n.nspname as \"%s\",\n"
- " c.relname as \"%s\",\n"
- " c.relacl as \"%s\"\n"
- "FROM pg_catalog.pg_class c\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
- "WHERE c.relkind IN ('r', 'v', 'S')\n",
- _("Schema"), _("Table"), _("Access privileges"));
+ "SELECT n.nspname as \"%s\",\n"
+ " c.relname as \"%s\",\n"
+ " c.relacl as \"%s\"\n"
+ "FROM pg_catalog.pg_class c\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
+ "WHERE c.relkind IN ('r', 'v', 'S')\n",
+ _("Schema"), _("Table"), _("Access privileges"));
/*
* Unless a schema pattern is specified, we suppress system and temp
- * tables, since they normally aren't very interesting from a permissions
- * point of view. You can see 'em by explicit request though,
- * eg with \z pg_catalog.*
+ * tables, since they normally aren't very interesting from a
+ * permissions point of view. You can see 'em by explicit request
+ * though, eg with \z pg_catalog.*
*/
processNamePattern(&buf, pattern, true, false,
"n.nspname", "c.relname", NULL,
- "pg_catalog.pg_table_is_visible(c.oid) AND n.nspname !~ '^pg_'");
+ "pg_catalog.pg_table_is_visible(c.oid) AND n.nspname !~ '^pg_'");
appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
@@ -409,99 +412,99 @@ objectDescription(const char *pattern)
initPQExpBuffer(&buf);
appendPQExpBuffer(&buf,
- "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
- "FROM (\n",
- _("Schema"), _("Name"), _("Object"), _("Description"));
+ "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
+ "FROM (\n",
+ _("Schema"), _("Name"), _("Object"), _("Description"));
/* Aggregate descriptions */
appendPQExpBuffer(&buf,
- " SELECT p.oid as oid, p.tableoid as tableoid,\n"
- " n.nspname as nspname,\n"
- " CAST(p.proname AS pg_catalog.text) as name,"
- " CAST('%s' AS pg_catalog.text) as object\n"
- " FROM pg_catalog.pg_proc p\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
- " WHERE p.proisagg\n",
- _("aggregate"));
+ " SELECT p.oid as oid, p.tableoid as tableoid,\n"
+ " n.nspname as nspname,\n"
+ " CAST(p.proname AS pg_catalog.text) as name,"
+ " CAST('%s' AS pg_catalog.text) as object\n"
+ " FROM pg_catalog.pg_proc p\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
+ " WHERE p.proisagg\n",
+ _("aggregate"));
processNamePattern(&buf, pattern, true, false,
"n.nspname", "p.proname", NULL,
"pg_catalog.pg_function_is_visible(p.oid)");
/* Function descriptions (except in/outs for datatypes) */
appendPQExpBuffer(&buf,
- "UNION ALL\n"
- " SELECT p.oid as oid, p.tableoid as tableoid,\n"
- " n.nspname as nspname,\n"
- " CAST(p.proname AS pg_catalog.text) as name,"
- " CAST('%s' AS pg_catalog.text) as object\n"
- " FROM pg_catalog.pg_proc p\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
-
- " WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
- " AND p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
- " AND NOT p.proisagg\n",
- _("function"));
+ "UNION ALL\n"
+ " SELECT p.oid as oid, p.tableoid as tableoid,\n"
+ " n.nspname as nspname,\n"
+ " CAST(p.proname AS pg_catalog.text) as name,"
+ " CAST('%s' AS pg_catalog.text) as object\n"
+ " FROM pg_catalog.pg_proc p\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
+
+ " WHERE p.prorettype <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
+ " AND p.proargtypes[0] <> 'pg_catalog.cstring'::pg_catalog.regtype\n"
+ " AND NOT p.proisagg\n",
+ _("function"));
processNamePattern(&buf, pattern, true, false,
"n.nspname", "p.proname", NULL,
"pg_catalog.pg_function_is_visible(p.oid)");
/* Operator descriptions (only if operator has its own comment) */
appendPQExpBuffer(&buf,
- "UNION ALL\n"
- " SELECT o.oid as oid, o.tableoid as tableoid,\n"
- " n.nspname as nspname,\n"
- " CAST(o.oprname AS pg_catalog.text) as name,"
- " CAST('%s' AS pg_catalog.text) as object\n"
- " FROM pg_catalog.pg_operator o\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
- _("operator"));
+ "UNION ALL\n"
+ " SELECT o.oid as oid, o.tableoid as tableoid,\n"
+ " n.nspname as nspname,\n"
+ " CAST(o.oprname AS pg_catalog.text) as name,"
+ " CAST('%s' AS pg_catalog.text) as object\n"
+ " FROM pg_catalog.pg_operator o\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
+ _("operator"));
processNamePattern(&buf, pattern, false, false,
"n.nspname", "o.oprname", NULL,
"pg_catalog.pg_operator_is_visible(o.oid)");
/* Type description */
appendPQExpBuffer(&buf,
- "UNION ALL\n"
- " SELECT t.oid as oid, t.tableoid as tableoid,\n"
- " n.nspname as nspname,\n"
- " pg_catalog.format_type(t.oid, NULL) as name,"
- " CAST('%s' AS pg_catalog.text) as object\n"
- " FROM pg_catalog.pg_type t\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n",
- _("data type"));
+ "UNION ALL\n"
+ " SELECT t.oid as oid, t.tableoid as tableoid,\n"
+ " n.nspname as nspname,\n"
+ " pg_catalog.format_type(t.oid, NULL) as name,"
+ " CAST('%s' AS pg_catalog.text) as object\n"
+ " FROM pg_catalog.pg_type t\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n",
+ _("data type"));
processNamePattern(&buf, pattern, false, false,
- "n.nspname", "pg_catalog.format_type(t.oid, NULL)", NULL,
+ "n.nspname", "pg_catalog.format_type(t.oid, NULL)", NULL,
"pg_catalog.pg_type_is_visible(t.oid)");
/* Relation (tables, views, indexes, sequences) descriptions */
appendPQExpBuffer(&buf,
- "UNION ALL\n"
- " SELECT c.oid as oid, c.tableoid as tableoid,\n"
- " n.nspname as nspname,\n"
- " CAST(c.relname AS pg_catalog.text) as name,\n"
- " CAST(\n"
- " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' END"
- " AS pg_catalog.text) as object\n"
- " FROM pg_catalog.pg_class c\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
- " WHERE c.relkind IN ('r', 'v', 'i', 'S')\n",
- _("table"), _("view"), _("index"), _("sequence"));
+ "UNION ALL\n"
+ " SELECT c.oid as oid, c.tableoid as tableoid,\n"
+ " n.nspname as nspname,\n"
+ " CAST(c.relname AS pg_catalog.text) as name,\n"
+ " CAST(\n"
+ " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' END"
+ " AS pg_catalog.text) as object\n"
+ " FROM pg_catalog.pg_class c\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
+ " WHERE c.relkind IN ('r', 'v', 'i', 'S')\n",
+ _("table"), _("view"), _("index"), _("sequence"));
processNamePattern(&buf, pattern, true, false,
"n.nspname", "c.relname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)");
/* Rule description (ignore rules for views) */
appendPQExpBuffer(&buf,
- "UNION ALL\n"
- " SELECT r.oid as oid, r.tableoid as tableoid,\n"
- " n.nspname as nspname,\n"
- " CAST(r.rulename AS pg_catalog.text) as name,"
- " CAST('%s' AS pg_catalog.text) as object\n"
- " FROM pg_catalog.pg_rewrite r\n"
- " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
- " WHERE r.rulename != '_RETURN'\n",
- _("rule"));
+ "UNION ALL\n"
+ " SELECT r.oid as oid, r.tableoid as tableoid,\n"
+ " n.nspname as nspname,\n"
+ " CAST(r.rulename AS pg_catalog.text) as name,"
+ " CAST('%s' AS pg_catalog.text) as object\n"
+ " FROM pg_catalog.pg_rewrite r\n"
+ " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
+ " WHERE r.rulename != '_RETURN'\n",
+ _("rule"));
/* XXX not sure what to do about visibility rule here? */
processNamePattern(&buf, pattern, true, false,
"n.nspname", "r.rulename", NULL,
@@ -509,23 +512,23 @@ objectDescription(const char *pattern)
/* Trigger description */
appendPQExpBuffer(&buf,
- "UNION ALL\n"
- " SELECT t.oid as oid, t.tableoid as tableoid,\n"
- " n.nspname as nspname,\n"
- " CAST(t.tgname AS pg_catalog.text) as name,"
- " CAST('%s' AS pg_catalog.text) as object\n"
- " FROM pg_catalog.pg_trigger t\n"
- " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
- _("trigger"));
+ "UNION ALL\n"
+ " SELECT t.oid as oid, t.tableoid as tableoid,\n"
+ " n.nspname as nspname,\n"
+ " CAST(t.tgname AS pg_catalog.text) as name,"
+ " CAST('%s' AS pg_catalog.text) as object\n"
+ " FROM pg_catalog.pg_trigger t\n"
+ " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
+ _("trigger"));
/* XXX not sure what to do about visibility rule here? */
processNamePattern(&buf, pattern, false, false,
"n.nspname", "t.tgname", NULL,
"pg_catalog.pg_table_is_visible(c.oid)");
appendPQExpBuffer(&buf,
- ") AS tt\n"
- " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid and tt.tableoid = d.classoid and d.objsubid = 0)\n");
+ ") AS tt\n"
+ " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid and tt.tableoid = d.classoid and d.objsubid = 0)\n");
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;");
@@ -561,11 +564,11 @@ describeTableDetails(const char *pattern, bool verbose)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT c.oid,\n"
- " n.nspname,\n"
- " c.relname\n"
- "FROM pg_catalog.pg_class c\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
+ "SELECT c.oid,\n"
+ " n.nspname,\n"
+ " c.relname\n"
+ "FROM pg_catalog.pg_class c\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
processNamePattern(&buf, pattern, false, false,
"n.nspname", "c.relname", NULL,
@@ -625,7 +628,7 @@ describeOneTableDetails(const char *schemaname,
PGresult *res = NULL;
printTableOpt myopt = pset.popt.topt;
int i;
- char *view_def = NULL;
+ char *view_def = NULL;
const char *headers[5];
char **cells = NULL;
char **footers = NULL;
@@ -649,7 +652,7 @@ describeOneTableDetails(const char *schemaname,
/* Get general table info */
printfPQExpBuffer(&buf,
- "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules\n"
+ "SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules\n"
"FROM pg_catalog.pg_class WHERE oid = '%s'",
oid);
res = PSQLexec(buf.data);
@@ -757,7 +760,7 @@ describeOneTableDetails(const char *schemaname,
printfPQExpBuffer(&buf,
"SELECT substring(d.adsrc for 128) FROM pg_catalog.pg_attrdef d\n"
- "WHERE d.adrelid = '%s' AND d.adnum = %s",
+ "WHERE d.adrelid = '%s' AND d.adnum = %s",
oid, PQgetvalue(res, i, 4));
result = PSQLexec(buf.data);
@@ -809,7 +812,7 @@ describeOneTableDetails(const char *schemaname,
break;
default:
printfPQExpBuffer(&title, _("?%c? \"%s.%s\""),
- tableinfo.relkind, schemaname, relationname);
+ tableinfo.relkind, schemaname, relationname);
break;
}
@@ -818,9 +821,10 @@ describeOneTableDetails(const char *schemaname,
{
/* Footer information about an index */
PGresult *result;
+
printfPQExpBuffer(&buf,
- "SELECT i.indisunique, i.indisprimary, a.amname, c2.relname,\n"
- " pg_catalog.pg_get_expr(i.indpred, i.indrelid)\n"
+ "SELECT i.indisunique, i.indisprimary, a.amname, c2.relname,\n"
+ " pg_catalog.pg_get_expr(i.indpred, i.indrelid)\n"
"FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
"WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
"AND i.indrelid = c2.oid",
@@ -878,10 +882,10 @@ describeOneTableDetails(const char *schemaname,
if (tableinfo.hasrules)
{
printfPQExpBuffer(&buf,
- "SELECT r.rulename\n"
- "FROM pg_catalog.pg_rewrite r\n"
- "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN'",
- oid);
+ "SELECT r.rulename\n"
+ "FROM pg_catalog.pg_rewrite r\n"
+ "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN'",
+ oid);
result = PSQLexec(buf.data);
if (!result)
goto error_return;
@@ -934,12 +938,12 @@ describeOneTableDetails(const char *schemaname,
if (tableinfo.hasindex)
{
printfPQExpBuffer(&buf,
- "SELECT c2.relname, i.indisprimary, i.indisunique, "
- "pg_catalog.pg_get_indexdef(i.indexrelid)\n"
- "FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
- "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
- "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
- oid);
+ "SELECT c2.relname, i.indisprimary, i.indisunique, "
+ "pg_catalog.pg_get_indexdef(i.indexrelid)\n"
+ "FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
+ "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
+ "ORDER BY i.indisprimary DESC, i.indisunique DESC, c2.relname",
+ oid);
result1 = PSQLexec(buf.data);
if (!result1)
goto error_return;
@@ -951,10 +955,10 @@ describeOneTableDetails(const char *schemaname,
if (tableinfo.checks)
{
printfPQExpBuffer(&buf,
- "SELECT consrc, conname\n"
- "FROM pg_catalog.pg_constraint r\n"
- "WHERE r.conrelid = '%s' AND r.contype = 'c'",
- oid);
+ "SELECT consrc, conname\n"
+ "FROM pg_catalog.pg_constraint r\n"
+ "WHERE r.conrelid = '%s' AND r.contype = 'c'",
+ oid);
result2 = PSQLexec(buf.data);
if (!result2)
goto error_return;
@@ -966,10 +970,10 @@ describeOneTableDetails(const char *schemaname,
if (tableinfo.hasrules)
{
printfPQExpBuffer(&buf,
- "SELECT r.rulename\n"
- "FROM pg_catalog.pg_rewrite r\n"
- "WHERE r.ev_class = '%s'",
- oid);
+ "SELECT r.rulename\n"
+ "FROM pg_catalog.pg_rewrite r\n"
+ "WHERE r.ev_class = '%s'",
+ oid);
result3 = PSQLexec(buf.data);
if (!result3)
goto error_return;
@@ -981,15 +985,15 @@ describeOneTableDetails(const char *schemaname,
if (tableinfo.triggers)
{
printfPQExpBuffer(&buf,
- "SELECT t.tgname\n"
- "FROM pg_catalog.pg_trigger t\n"
- "WHERE t.tgrelid = '%s' "
- "and (not tgisconstraint "
- " OR NOT EXISTS"
- " (SELECT 1 FROM pg_catalog.pg_depend d "
- " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
- " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))",
- oid);
+ "SELECT t.tgname\n"
+ "FROM pg_catalog.pg_trigger t\n"
+ "WHERE t.tgrelid = '%s' "
+ "and (not tgisconstraint "
+ " OR NOT EXISTS"
+ " (SELECT 1 FROM pg_catalog.pg_depend d "
+ " JOIN pg_catalog.pg_constraint c ON (d.refclassid = c.tableoid AND d.refobjid = c.oid) "
+ " WHERE d.classid = t.tableoid AND d.objid = t.oid AND d.deptype = 'i' AND c.contype = 'f'))",
+ oid);
result4 = PSQLexec(buf.data);
if (!result4)
goto error_return;
@@ -997,15 +1001,15 @@ describeOneTableDetails(const char *schemaname,
trigger_count = PQntuples(result4);
}
- /* count foreign-key constraints (there are none if no triggers) */
+ /* count foreign-key constraints (there are none if no triggers) */
if (tableinfo.triggers)
{
printfPQExpBuffer(&buf,
- "SELECT conname,\n"
- " pg_catalog.pg_get_constraintdef(oid) as condef\n"
- "FROM pg_catalog.pg_constraint r\n"
- "WHERE r.conrelid = '%s' AND r.contype = 'f'",
- oid);
+ "SELECT conname,\n"
+ " pg_catalog.pg_get_constraintdef(oid) as condef\n"
+ "FROM pg_catalog.pg_constraint r\n"
+ "WHERE r.conrelid = '%s' AND r.contype = 'f'",
+ oid);
result5 = PSQLexec(buf.data);
if (!result5)
goto error_return;
@@ -1022,7 +1026,7 @@ describeOneTableDetails(const char *schemaname,
char *s = _("Indexes");
const char *indexdef;
const char *usingpos;
-
+
if (i == 0)
printfPQExpBuffer(&buf, "%s: %s", s,
PQgetvalue(result1, i, 0));
@@ -1032,9 +1036,9 @@ describeOneTableDetails(const char *schemaname,
/* Label as primary key or unique (but not both) */
appendPQExpBuffer(&buf,
- strcmp(PQgetvalue(result1,i,1),"t") == 0
+ strcmp(PQgetvalue(result1, i, 1), "t") == 0
? _(" primary key") :
- (strcmp(PQgetvalue(result1,i,2),"t") == 0
+ (strcmp(PQgetvalue(result1, i, 2), "t") == 0
? _(" unique")
: ""));
@@ -1184,18 +1188,18 @@ describeUsers(const char *pattern)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT u.usename AS \"%s\",\n"
- " u.usesysid AS \"%s\",\n"
- " CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
- " WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n"
- " WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
- " ELSE CAST('' AS pg_catalog.text)\n"
- " END AS \"%s\"\n"
- "FROM pg_catalog.pg_user u\n",
- _("User name"), _("User ID"),
- _("superuser, create database"),
- _("superuser"), _("create database"),
- _("Attributes"));
+ "SELECT u.usename AS \"%s\",\n"
+ " u.usesysid AS \"%s\",\n"
+ " CASE WHEN u.usesuper AND u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
+ " WHEN u.usesuper THEN CAST('%s' AS pg_catalog.text)\n"
+ " WHEN u.usecreatedb THEN CAST('%s' AS pg_catalog.text)\n"
+ " ELSE CAST('' AS pg_catalog.text)\n"
+ " END AS \"%s\"\n"
+ "FROM pg_catalog.pg_user u\n",
+ _("User name"), _("User ID"),
+ _("superuser, create database"),
+ _("superuser"), _("create database"),
+ _("Attributes"));
processNamePattern(&buf, pattern, false, false,
NULL, "u.usename", NULL, NULL);
@@ -1249,32 +1253,32 @@ listTables(const char *tabtypes, const char *pattern, bool verbose)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT n.nspname as \"%s\",\n"
- " c.relname as \"%s\",\n"
- " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' WHEN 's' THEN '%s' END as \"%s\",\n"
- " u.usename as \"%s\"",
- _("Schema"), _("Name"),
- _("table"), _("view"), _("index"), _("sequence"),
- _("special"), _("Type"), _("Owner"));
+ "SELECT n.nspname as \"%s\",\n"
+ " c.relname as \"%s\",\n"
+ " CASE c.relkind WHEN 'r' THEN '%s' WHEN 'v' THEN '%s' WHEN 'i' THEN '%s' WHEN 'S' THEN '%s' WHEN 's' THEN '%s' END as \"%s\",\n"
+ " u.usename as \"%s\"",
+ _("Schema"), _("Name"),
+ _("table"), _("view"), _("index"), _("sequence"),
+ _("special"), _("Type"), _("Owner"));
if (verbose)
appendPQExpBuffer(&buf,
- ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
- _("Description"));
+ ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
+ _("Description"));
- if (showIndexes)
+ if (showIndexes)
appendPQExpBuffer(&buf,
",\n c2.relname as \"%s\""
"\nFROM pg_catalog.pg_class c"
- "\n JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
- "\n JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid"
- "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner"
+ "\n JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
+ "\n JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid"
+ "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner"
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
_("Table"));
else
appendPQExpBuffer(&buf,
"\nFROM pg_catalog.pg_class c"
- "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner"
+ "\n LEFT JOIN pg_catalog.pg_user u ON u.usesysid = c.relowner"
"\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
appendPQExpBuffer(&buf, "WHERE c.relkind IN (");
@@ -1288,12 +1292,13 @@ listTables(const char *tabtypes, const char *pattern, bool verbose)
appendPQExpBuffer(&buf, "'S',");
if (showSystem && showTables)
appendPQExpBuffer(&buf, "'s',");
- appendPQExpBuffer(&buf, "''"); /* dummy */
+ appendPQExpBuffer(&buf, "''"); /* dummy */
appendPQExpBuffer(&buf, ")\n");
/*
- * Unless showSystem is specified, we suppress system tables, ie, those
- * in pg_catalog and pg_toast. (We don't want to hide temp tables though.)
+ * Unless showSystem is specified, we suppress system tables, ie,
+ * those in pg_catalog and pg_toast. (We don't want to hide temp
+ * tables though.)
*/
if (showSystem)
processNamePattern(&buf, pattern, true, false,
@@ -1346,21 +1351,21 @@ listDomains(const char *pattern)
initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
- "SELECT n.nspname as \"%s\",\n"
- " t.typname as \"%s\",\n"
- " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
- " CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
- " WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
- " WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
- " ELSE ''\n"
- " END as \"%s\"\n"
- "FROM pg_catalog.pg_type t\n"
- " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
- "WHERE t.typtype = 'd'\n",
- _("Schema"),
- _("Name"),
- _("Type"),
- _("Modifier"));
+ "SELECT n.nspname as \"%s\",\n"
+ " t.typname as \"%s\",\n"
+ " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
+ " CASE WHEN t.typnotnull AND t.typdefault IS NOT NULL THEN 'not null default '||t.typdefault\n"
+ " WHEN t.typnotnull AND t.typdefault IS NULL THEN 'not null'\n"
+ " WHEN NOT t.typnotnull AND t.typdefault IS NOT NULL THEN 'default '||t.typdefault\n"
+ " ELSE ''\n"
+ " END as \"%s\"\n"
+ "FROM pg_catalog.pg_type t\n"
+ " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n"
+ "WHERE t.typtype = 'd'\n",
+ _("Schema"),
+ _("Name"),
+ _("Type"),
+ _("Modifier"));
processNamePattern(&buf, pattern, true, false,
"n.nspname", "t.typname", NULL,
@@ -1397,7 +1402,7 @@ listDomains(const char *pattern)
* namevar: name of WHERE variable to match against an object-name pattern.
* altnamevar: NULL, or name of an alternate variable to match against name.
* visibilityrule: clause to use if we want to restrict to visible objects
- * (for example, "pg_catalog.pg_table_is_visible(p.oid)"). Can be NULL.
+ * (for example, "pg_catalog.pg_table_is_visible(p.oid)"). Can be NULL.
*/
static void
processNamePattern(PQExpBuffer buf, const char *pattern,
@@ -1479,10 +1484,11 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
* Ordinary data character, transfer to pattern
*
* Inside double quotes, or at all times if parsing an operator
- * name, quote regexp special characters with a backslash to avoid
- * regexp errors. Outside quotes, however, let them pass through
- * as-is; this lets knowledgeable users build regexp expressions
- * that are more powerful than shell-style patterns.
+ * name, quote regexp special characters with a backslash to
+ * avoid regexp errors. Outside quotes, however, let them
+ * pass through as-is; this lets knowledgeable users build
+ * regexp expressions that are more powerful than shell-style
+ * patterns.
*/
if ((inquotes || force_escape) &&
strchr("|*+?()[]{}.^$\\", *cp))
@@ -1511,8 +1517,8 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
appendPQExpBufferChar(&schemabuf, '$');
/* Optimize away ".*$", and possibly the whole pattern */
if (schemabuf.len >= 3 &&
- strcmp(schemabuf.data + (schemabuf.len-3), ".*$") == 0)
- schemabuf.data[schemabuf.len-3] = '\0';
+ strcmp(schemabuf.data + (schemabuf.len - 3), ".*$") == 0)
+ schemabuf.data[schemabuf.len - 3] = '\0';
if (schemabuf.data[0] && schemavar)
{
@@ -1538,8 +1544,8 @@ processNamePattern(PQExpBuffer buf, const char *pattern,
appendPQExpBufferChar(&namebuf, '$');
/* Optimize away ".*$", and possibly the whole pattern */
if (namebuf.len >= 3 &&
- strcmp(namebuf.data + (namebuf.len-3), ".*$") == 0)
- namebuf.data[namebuf.len-3] = '\0';
+ strcmp(namebuf.data + (namebuf.len - 3), ".*$") == 0)
+ namebuf.data[namebuf.len - 3] = '\0';
if (namebuf.data[0])
{
diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index a224898d12..45d9c1e2f9 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.55 2002/08/27 18:28:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/help.c,v 1.56 2002/09/04 20:31:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "print.h"
@@ -70,13 +70,13 @@ usage(void)
psql_error("could not get current user name: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
-#else /* WIN32 */
+#else /* WIN32 */
char buf[128];
DWORD bufsize = sizeof(buf) - 1;
if (GetUserName(buf, &bufsize))
user = buf;
-#endif /* WIN32 */
+#endif /* WIN32 */
}
/* If this " is the start of the string then it ought to end there to fit in 80 columns >> " */
@@ -161,7 +161,8 @@ struct winsize
void
slashUsage(bool pager)
{
- FILE *output, *pagerfd = NULL;
+ FILE *output,
+ *pagerfd = NULL;
/* check whether we need / can / are supposed to use pager */
if (pager
@@ -202,10 +203,14 @@ slashUsage(bool pager)
output = stdout;
/* if you add/remove a line here, change the row test above */
- /* if this " is the start of the string then it ought to end there to fit in 80 columns >> " */
+
+ /*
+ * if this " is the start of the string then it ought to end there to
+ * fit in 80 columns >> "
+ */
fprintf(output, _(" \\a toggle between unaligned and aligned output mode\n"));
fprintf(output, _(" \\c[onnect] [DBNAME|- [USER]]\n"
- " connect to new database (currently \"%s\")\n"),
+ " connect to new database (currently \"%s\")\n"),
PQdb(pset.db));
fprintf(output, _(" \\C [STRING] set table title, or unset if none\n"));
fprintf(output, _(" \\cd [DIR] change the current working directory\n"));
@@ -234,11 +239,11 @@ slashUsage(bool pager)
fprintf(output, _(" \\i FILE execute commands from file\n"));
fprintf(output, _(" \\l list all databases\n"));
fprintf(output, _(" \\lo_export, \\lo_import, \\lo_list, \\lo_unlink\n"
- " large object operations\n"));
+ " large object operations\n"));
fprintf(output, _(" \\o FILE send all query results to file or |pipe\n"));
fprintf(output, _(" \\p show the contents of the query buffer\n"));
fprintf(output, _(" \\pset NAME [VALUE] set table output option (NAME := {format|border|expanded|\n"
- " fieldsep|null|recordsep|tuples_only|title|tableattr|pager})\n"));
+ " fieldsep|null|recordsep|tuples_only|title|tableattr|pager})\n"));
fprintf(output, _(" \\q quit psql\n"));
fprintf(output, _(" \\qecho [STRING] write string to query output stream (see \\o)\n"));
fprintf(output, _(" \\r reset (clear) the query buffer\n"));
diff --git a/src/bin/psql/input.h b/src/bin/psql/input.h
index e893b8c539..fbb52f20da 100644
--- a/src/bin/psql/input.h
+++ b/src/bin/psql/input.h
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.16 2002/04/10 22:47:03 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/input.h,v 1.17 2002/09/04 20:31:36 momjian Exp $
*/
#ifndef INPUT_H
#define INPUT_H
@@ -15,17 +15,17 @@
* USE_READLINE is the definite pointers regarding existence or not.
*/
#ifdef HAVE_LIBREADLINE
-# define USE_READLINE 1
-# if defined(HAVE_READLINE_READLINE_H)
-# include <readline/readline.h>
-# elif defined(HAVE_READLINE_H)
-# include <readline.h>
-# endif
-# if defined(HAVE_READLINE_HISTORY_H)
-# include <readline/history.h>
-# elif defined(HAVE_HISTORY_H)
-# include <history.h>
-# endif
+#define USE_READLINE 1
+#if defined(HAVE_READLINE_READLINE_H)
+#include <readline/readline.h>
+#elif defined(HAVE_READLINE_H)
+#include <readline.h>
+#endif
+#if defined(HAVE_READLINE_HISTORY_H)
+#include <readline/history.h>
+#elif defined(HAVE_HISTORY_H)
+#include <history.h>
+#endif
#endif
char *gets_interactive(char *prompt);
diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c
index 0e90fceb6c..2bca9da05e 100644
--- a/src/bin/psql/large_obj.c
+++ b/src/bin/psql/large_obj.c
@@ -3,7 +3,7 @@
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.20 2002/08/10 03:56:24 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.21 2002/09/04 20:31:36 momjian Exp $
*/
#include "postgres_fe.h"
#include "large_obj.h"
@@ -358,7 +358,7 @@ do_lo_list(void)
snprintf(buf, sizeof(buf),
"SELECT loid as \"ID\", pg_catalog.obj_description(loid, 'pg_largeobject') as \"%s\"\n"
- "FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) x\n"
+ "FROM (SELECT DISTINCT loid FROM pg_catalog.pg_largeobject) x\n"
"ORDER BY \"ID\"",
gettext("Description"));
diff --git a/src/bin/psql/mainloop.c b/src/bin/psql/mainloop.c
index d3fe2657b4..6d9367f761 100644
--- a/src/bin/psql/mainloop.c
+++ b/src/bin/psql/mainloop.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.49 2002/07/03 16:47:46 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mainloop.c,v 1.50 2002/09/04 20:31:36 momjian Exp $
*/
#include "postgres_fe.h"
#include "mainloop.h"
@@ -396,15 +396,15 @@ MainLoop(FILE *source)
if (i < len)
{
- thislen = PQmblen(line+i, pset.encoding);
+ thislen = PQmblen(line + i, pset.encoding);
goto rescan; /* reparse the just substituted */
}
}
else
{
/*
- * if the variable doesn't exist we'll leave the string as
- * is ... move on ...
+ * if the variable doesn't exist we'll leave the
+ * string as is ... move on ...
*/
}
}
diff --git a/src/bin/psql/print.h b/src/bin/psql/print.h
index bcb3495bc6..09ec685bfe 100644
--- a/src/bin/psql/print.h
+++ b/src/bin/psql/print.h
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.13 2002/07/15 01:56:25 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/print.h,v 1.14 2002/09/04 20:31:36 momjian Exp $
*/
#ifndef PRINT_H
#define PRINT_H
@@ -72,7 +72,7 @@ typedef struct _printQueryOpt
*
* It calls the printTable above with all the things set straight.
*/
-void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout);
+void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout);
#ifndef __CYGWIN__
#define DEFAULT_PAGER "more"
diff --git a/src/bin/psql/sprompt.c b/src/bin/psql/sprompt.c
index 183b8e97ed..d05b294bfa 100644
--- a/src/bin/psql/sprompt.c
+++ b/src/bin/psql/sprompt.c
@@ -3,13 +3,13 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.2 2002/07/06 20:14:58 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/Attic/sprompt.c,v 1.3 2002/09/04 20:31:36 momjian Exp $
*/
/* This file is shared by psql and pg_dump. */
-
+
/*
* simple_prompt
*
@@ -28,7 +28,7 @@
#include <termios.h>
#endif
-bool prompt_state = false;
+bool prompt_state = false;
extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
char *
diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c
index a93219d22f..ef84d9410b 100644
--- a/src/bin/psql/startup.c
+++ b/src/bin/psql/startup.c
@@ -3,7 +3,7 @@
*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.63 2002/08/27 20:16:48 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/startup.c,v 1.64 2002/09/04 20:31:36 momjian Exp $
*/
#include "postgres_fe.h"
@@ -11,7 +11,7 @@
#ifndef WIN32
#include <unistd.h>
-#else /* WIN32 */
+#else /* WIN32 */
#include <io.h>
#include <windows.h>
#include <win32.h>
@@ -541,7 +541,11 @@ parse_psql_options(int argc, char *argv[], struct adhoc_opts * options)
}
break;
#ifndef HAVE_GETOPT_LONG
- /* FreeBSD has a broken getopt that causes this test to fail. */
+
+ /*
+ * FreeBSD has a broken getopt that causes this test to
+ * fail.
+ */
case '-':
fprintf(stderr,
gettext("%s was compiled without support for long options.\n"
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index cc95a602dd..ce4a2b5a80 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -3,7 +3,7 @@
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.63 2002/09/02 06:19:38 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/tab-complete.c,v 1.64 2002/09/04 20:31:36 momjian Exp $
*/
/*----------------------------------------------------------------------
@@ -145,7 +145,8 @@ pgsql_thing_t words_after_create[] = {
{"FUNCTION", "SELECT DISTINCT proname FROM pg_catalog.pg_proc WHERE substr(proname,1,%d)='%s'"},
{"GROUP", "SELECT groname FROM pg_catalog.pg_group WHERE substr(groname,1,%d)='%s'"},
{"INDEX", Query_for_list_of_indexes},
- {"OPERATOR", NULL}, /* Querying for this is probably not such a good idea. */
+ {"OPERATOR", NULL}, /* Querying for this is probably not such
+ * a good idea. */
{"RULE", "SELECT rulename FROM pg_catalog.pg_rules WHERE substr(rulename,1,%d)='%s'"},
{"SCHEMA", "SELECT nspname FROM pg_catalog.pg_namespace WHERE substr(nspname,1,%d)='%s'"},
{"SEQUENCE", "SELECT relname FROM pg_catalog.pg_class WHERE relkind='S' and substr(relname,1,%d)='%s'"},
@@ -330,7 +331,8 @@ psql_completion(char *text, int start, int end)
}
/*
- * If we detect ALTER TABLE <name>, suggest either ADD, ALTER, or RENAME
+ * If we detect ALTER TABLE <name>, suggest either ADD, ALTER, or
+ * RENAME
*/
else if (strcasecmp(prev3_wd, "ALTER") == 0 && strcasecmp(prev2_wd, "TABLE") == 0)
{
@@ -400,8 +402,8 @@ psql_completion(char *text, int start, int end)
{
char *list_COMMENT[] =
{"DATABASE", "INDEX", "RULE", "SCHEMA", "SEQUENCE", "TABLE", "TYPE", "VIEW",
- "COLUMN", "AGGREGATE", "FUNCTION", "OPERATOR", "TRIGGER", "CONSTRAINT",
- "DOMAIN", NULL};
+ "COLUMN", "AGGREGATE", "FUNCTION", "OPERATOR", "TRIGGER", "CONSTRAINT",
+ "DOMAIN", NULL};
COMPLETE_WITH_LIST(list_COMMENT);
}
@@ -604,7 +606,7 @@ psql_completion(char *text, int start, int end)
else if (strcasecmp(prev2_wd, "INSERT") == 0 && strcasecmp(prev_wd, "INTO") == 0)
COMPLETE_WITH_QUERY(Query_for_list_of_tables);
/* Complete "INSERT INTO <table> (" with attribute names */
- else if (rl_line_buffer[start-1]=='(' && strcasecmp(prev3_wd, "INSERT") == 0 && strcasecmp(prev2_wd, "INTO") == 0)
+ else if (rl_line_buffer[start - 1] == '(' && strcasecmp(prev3_wd, "INSERT") == 0 && strcasecmp(prev2_wd, "INTO") == 0)
COMPLETE_WITH_ATTR(prev_wd);
/*
@@ -614,13 +616,15 @@ psql_completion(char *text, int start, int end)
else if (strcasecmp(prev3_wd, "INSERT") == 0 && strcasecmp(prev2_wd, "INTO") == 0)
{
char *list_INSERT[] = {"DEFAULT VALUES", "SELECT", "VALUES", NULL};
+
COMPLETE_WITH_LIST(list_INSERT);
}
/* Complete INSERT INTO <table> (attribs) with "VALUES" or "SELECT" */
else if (strcasecmp(prev4_wd, "INSERT") == 0 && strcasecmp(prev3_wd, "INTO") == 0 &&
- prev_wd[strlen(prev_wd)-1]==')')
+ prev_wd[strlen(prev_wd) - 1] == ')')
{
char *list_INSERT[] = {"SELECT", "VALUES", NULL};
+
COMPLETE_WITH_LIST(list_INSERT);
}
@@ -631,25 +635,26 @@ psql_completion(char *text, int start, int end)
/* LOCK */
/* Complete LOCK [TABLE] with a list of tables */
else if ((strcasecmp(prev_wd, "LOCK") == 0) ||
- (strcasecmp(prev_wd, "TABLE") == 0 && strcasecmp(prev2_wd, "LOCK")))
+ (strcasecmp(prev_wd, "TABLE") == 0 && strcasecmp(prev2_wd, "LOCK")))
COMPLETE_WITH_QUERY(Query_for_list_of_tables);
/* For the following, handle the case of a single table only for now */
/* Complete LOCK [TABLE] <table> with "IN" */
- else if ((strcasecmp(prev2_wd, "LOCK") == 0 && strcasecmp(prev_wd, "TABLE")) ||
+ else if ((strcasecmp(prev2_wd, "LOCK") == 0 && strcasecmp(prev_wd, "TABLE")) ||
(strcasecmp(prev2_wd, "TABLE") == 0 && strcasecmp(prev3_wd, "LOCK") == 0))
- COMPLETE_WITH_CONST("IN");
+ COMPLETE_WITH_CONST("IN");
/* Complete LOCK [TABLE] <table> IN with a lock mode */
else if (strcasecmp(prev_wd, "IN") == 0 &&
(strcasecmp(prev3_wd, "LOCK") == 0 ||
- (strcasecmp(prev3_wd, "TABLE") == 0 && strcasecmp(prev3_wd, "LOCK"))))
+ (strcasecmp(prev3_wd, "TABLE") == 0 && strcasecmp(prev3_wd, "LOCK"))))
{
- char *lock_modes[] = {"ACCESS SHARE MODE", "ROW SHARE MODE", "ROW EXCLUSIVE MODE",
- "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", "SHARE ROW EXCLUSIVE MODE",
- "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE", NULL};
- COMPLETE_WITH_LIST(lock_modes);
+ char *lock_modes[] = {"ACCESS SHARE MODE", "ROW SHARE MODE", "ROW EXCLUSIVE MODE",
+ "SHARE UPDATE EXCLUSIVE MODE", "SHARE MODE", "SHARE ROW EXCLUSIVE MODE",
+ "EXCLUSIVE MODE", "ACCESS EXCLUSIVE MODE", NULL};
+
+ COMPLETE_WITH_LIST(lock_modes);
}
/* NOTIFY */
@@ -784,7 +789,7 @@ psql_completion(char *text, int start, int end)
/* WHERE */
/* Simple case of the word before the where being the table name */
- else if (strcasecmp(prev_wd, "WHERE") == 0)
+ else if (strcasecmp(prev_wd, "WHERE") == 0)
COMPLETE_WITH_ATTR(prev2_wd);
/* ... FROM ... */
@@ -1063,7 +1068,7 @@ previous_word(int point, int skip)
int i,
start = 0,
end = -1,
- inquotes=0;
+ inquotes = 0;
char *s;
while (skip-- >= 0)
@@ -1093,11 +1098,12 @@ previous_word(int point, int skip)
* last character before any space going backwards from the end,
* or it's simply character 0
*/
- for (start = end; start > 0; start--) {
- if (rl_line_buffer[start] == '"')
- inquotes = !inquotes;
- if ((rl_line_buffer[start - 1] == ' ') && inquotes==0)
- break;
+ for (start = end; start > 0; start--)
+ {
+ if (rl_line_buffer[start] == '"')
+ inquotes = !inquotes;
+ if ((rl_line_buffer[start - 1] == ' ') && inquotes == 0)
+ break;
}
point = start;