aboutsummaryrefslogtreecommitdiff
path: root/src/bin/psql/common.c
diff options
context:
space:
mode:
authorBruce Momjian <bruce@momjian.us>2003-03-20 06:43:35 +0000
committerBruce Momjian <bruce@momjian.us>2003-03-20 06:43:35 +0000
commitadd932ee91b9ca78c1a0647487cd6d2a680c4f12 (patch)
treeabb208bec97099a408ead6d6c5b0f0929c459a2d /src/bin/psql/common.c
parent1b3d4cefe8e025a40e3a795f311d4711178366e9 (diff)
downloadpostgresql-add932ee91b9ca78c1a0647487cd6d2a680c4f12.tar.gz
postgresql-add932ee91b9ca78c1a0647487cd6d2a680c4f12.zip
I'm continuing to work on cleaning up code in psql. As things appear
now, my changes seem to work. Some possible minor bugs got squished on the way but I can't be sure without more feedback from people who really put the code to the test. The new patch mostly simplifies variable handling and reduces code duplication. Changes in the command parser eliminate some redundant variables (boolean state + depth counter), replaces some "else if" constructs with switches, and so on. It is meant to be applied together with my previous patch, although I hope they don't conflict; I went back to the CVS version for this one. One more thing I thought should perhaps be changed: an IGNOREEOF value of n will ignore only n-1 EOFs. I didn't want to touch this for fear of breaking existing applications, but it does seem a tad illogical. Jeroen T. Vermeulen
Diffstat (limited to 'src/bin/psql/common.c')
-rw-r--r--src/bin/psql/common.c39
1 files changed, 23 insertions, 16 deletions
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index f3f7e809978..48405f91493 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.59 2003/03/20 06:00:12 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.60 2003/03/20 06:43:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "common.h"
@@ -368,7 +368,7 @@ PSQLexec(const char *query, bool ignore_command_ok)
{
PGresult *res = NULL;
PGresult *newres;
- const char *var;
+ int echo_hidden;
ExecStatusType rstatus;
if (!pset.db)
@@ -377,17 +377,17 @@ PSQLexec(const char *query, bool ignore_command_ok)
return NULL;
}
- var = GetVariable(pset.vars, "ECHO_HIDDEN");
- if (var)
+ echo_hidden = SwitchVariable(pset.vars, "ECHO_HIDDEN", "noexec", NULL);
+ if (echo_hidden != var_notset)
{
printf("********* QUERY **********\n"
"%s\n"
"**************************\n\n", query);
fflush(stdout);
- }
- if (var && strcmp(var, "noexec") == 0)
+ if (echo_hidden == 1)
return NULL;
+ }
/* discard any uneaten results of past queries */
while ((newres = PQgetResult(pset.db)) != NULL)
@@ -579,13 +579,13 @@ SendQuery(const char *query)
bool OK;
if (!pset.db)
- {
+ {
psql_error("You are currently not connected to a database.\n");
return false;
- }
+ }
if (GetVariableBool(pset.vars, "SINGLESTEP"))
- {
+ {
char buf[3];
printf(gettext("***(Single step mode: Verify query)*********************************************\n"
@@ -596,14 +596,9 @@ SendQuery(const char *query)
if (fgets(buf, sizeof(buf), stdin) != NULL)
if (buf[0] == 'x')
return false;
- }
- else
- {
- const char *var = GetVariable(pset.vars, "ECHO");
-
- if (var && strncmp(var, "queries", strlen(var)) == 0)
- puts(query);
}
+ else if (VariableEquals(pset.vars, "ECHO", "queries"))
+ puts(query);
SetCancelConn();
@@ -619,3 +614,15 @@ SendQuery(const char *query)
PrintNotifications();
return OK;
}
+
+
+char parse_char(char **buf)
+{
+ long l;
+
+ l = strtol(*buf, buf, 0);
+ (*buf)--;
+ return (char)l;
+}
+
+