summaryrefslogtreecommitdiff
path: root/src/bin/psql/large_obj.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/large_obj.c
parent1b3d4cefe8e025a40e3a795f311d4711178366e9 (diff)
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/large_obj.c')
-rw-r--r--src/bin/psql/large_obj.c36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/bin/psql/large_obj.c b/src/bin/psql/large_obj.c
index fbe8a32a183..f76f8dea5b9 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.23 2002/10/15 02:24:16 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.24 2003/03/20 06:43:35 momjian Exp $
*/
#include "postgres_fe.h"
#include "large_obj.h"
@@ -40,15 +40,20 @@ _my_notice_handler(void *arg, const char *message)
static bool
handle_transaction(void)
{
- const char *var = GetVariable(pset.vars, "LO_TRANSACTION");
PGresult *res;
- bool commit;
+ bool commit = false;
PQnoticeProcessor old_notice_hook;
- if (var && strcmp(var, "nothing") == 0)
+ switch (SwitchVariable(pset.vars, "LO_TRANSACTION",
+ "nothing",
+ "commit",
+ NULL))
+ {
+ case 1:
return true;
-
- commit = (var && strcmp(var, "commit") == 0);
+ case 2:
+ commit = true;
+ }
notice[0] = '\0';
old_notice_hook = PQsetNoticeProcessor(pset.db, _my_notice_handler, NULL);
@@ -87,11 +92,9 @@ do_lo_export(const char *loid_arg, const char *filename_arg)
{
PGresult *res;
int status;
- bool own_transaction = true;
- const char *var = GetVariable(pset.vars, "LO_TRANSACTION");
+ bool own_transaction;
- if (var && strcmp(var, "nothing") == 0)
- own_transaction = false;
+ own_transaction = VariableEquals(pset.vars, "LO_TRANSACTION", "nothing");
if (!pset.db)
{
@@ -154,11 +157,9 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
Oid loid;
char oidbuf[32];
unsigned int i;
- bool own_transaction = true;
- const char *var = GetVariable(pset.vars, "LO_TRANSACTION");
+ bool own_transaction;
- if (var && strcmp(var, "nothing") == 0)
- own_transaction = false;
+ own_transaction = VariableEquals(pset.vars, "LO_TRANSACTION", "nothing");
if (!pset.db)
{
@@ -271,11 +272,10 @@ do_lo_unlink(const char *loid_arg)
int status;
Oid loid = atooid(loid_arg);
char buf[256];
- bool own_transaction = true;
- const char *var = GetVariable(pset.vars, "LO_TRANSACTION");
- if (var && strcmp(var, "nothing") == 0)
- own_transaction = false;
+ bool own_transaction;
+
+ own_transaction = VariableEquals(pset.vars, "LO_TRANSACTION", "nothing");
if (!pset.db)
{