*
* Copyright 2000 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.46 2002/10/03 17:09:41 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.47 2002/10/15 02:24:16 tgl Exp $
*/
#include "postgres_fe.h"
*
* This is the way to send "backdoor" queries (those not directly entered
* by the user). It is subject to -E but not -e.
+ *
+ * If the given querystring generates multiple PGresults, normally the last
+ * one is returned to the caller. However, if ignore_command_ok is TRUE,
+ * then PGresults with status PGRES_COMMAND_OK are ignored. This is intended
+ * mainly to allow locutions such as "begin; select ...; commit".
*/
PGresult *
-PSQLexec(const char *query)
+PSQLexec(const char *query, bool ignore_command_ok)
{
- PGresult *res;
+ PGresult *res = NULL;
+ PGresult *newres;
const char *var;
+ ExecStatusType rstatus;
if (!pset.db)
{
return NULL;
cancelConn = pset.db;
- res = PQexec(pset.db, query);
- if (PQresultStatus(res) == PGRES_COPY_IN)
- copy_in_state = true;
+ if (PQsendQuery(pset.db, query))
+ {
+ while ((newres = PQgetResult(pset.db)) != NULL)
+ {
+ if (ignore_command_ok &&
+ PQresultStatus(newres) == PGRES_COMMAND_OK)
+ {
+ PQclear(newres);
+ continue;
+ }
+ PQclear(res);
+ res = newres;
+ }
+ }
+ rstatus = PQresultStatus(res);
/* keep cancel connection for copy out state */
- if (PQresultStatus(res) != PGRES_COPY_OUT)
+ if (rstatus != PGRES_COPY_OUT)
cancelConn = NULL;
+ if (rstatus == PGRES_COPY_IN)
+ copy_in_state = true;
- if (res && (PQresultStatus(res) == PGRES_COMMAND_OK ||
- PQresultStatus(res) == PGRES_TUPLES_OK ||
- PQresultStatus(res) == PGRES_COPY_IN ||
- PQresultStatus(res) == PGRES_COPY_OUT)
- )
+ if (res && (rstatus == PGRES_COMMAND_OK ||
+ rstatus == PGRES_TUPLES_OK ||
+ rstatus == PGRES_COPY_IN ||
+ rstatus == PGRES_COPY_OUT))
return res;
else
{
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.69 2002/09/22 20:44:22 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/describe.c,v 1.70 2002/10/15 02:24:16 tgl Exp $
*/
#include "postgres_fe.h"
#include "describe.h"
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
appendPQExpBuffer(&buf, "ORDER BY 2, 3, 1, 4;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3, 4;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
"\n LEFT JOIN pg_catalog.pg_user u ON d.datdba = u.usesysid\n"
"ORDER BY 1;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
if (!res)
{
termPQExpBuffer(&buf);
appendPQExpBuffer(&buf, "ORDER BY 1, 2, 3;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
appendPQExpBuffer(&buf, "ORDER BY 2, 3;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
"SELECT relhasindex, relkind, relchecks, reltriggers, relhasrules\n"
"FROM pg_catalog.pg_class WHERE oid = '%s'",
oid);
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
if (!res)
goto error_return;
appendPQExpBuffer(&buf, " AND a.attrelid = i.indexrelid");
appendPQExpBuffer(&buf, "\nORDER BY a.attnum");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
if (!res)
goto error_return;
PGresult *result;
printfPQExpBuffer(&buf, "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid)", oid);
- result = PSQLexec(buf.data);
+ result = PSQLexec(buf.data, false);
if (!result)
goto error_return;
"WHERE d.adrelid = '%s' AND d.adnum = %s",
oid, PQgetvalue(res, i, 4));
- result = PSQLexec(buf.data);
+ result = PSQLexec(buf.data, false);
if (cells[i * cols + 2][0])
strcat(cells[i * cols + 2], " ");
"AND i.indrelid = c2.oid",
oid);
- result = PSQLexec(buf.data);
+ result = PSQLexec(buf.data, false);
if (!result)
goto error_return;
else if (PQntuples(result) != 1)
"FROM pg_catalog.pg_rewrite r\n"
"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN'",
oid);
- result = PSQLexec(buf.data);
+ result = PSQLexec(buf.data, false);
if (!result)
goto error_return;
else
"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);
+ result1 = PSQLexec(buf.data, false);
if (!result1)
goto error_return;
else
"FROM pg_catalog.pg_constraint r\n"
"WHERE r.conrelid = '%s' AND r.contype = 'c'",
oid);
- result2 = PSQLexec(buf.data);
+ result2 = PSQLexec(buf.data, false);
if (!result2)
goto error_return;
else
"FROM pg_catalog.pg_rewrite r\n"
"WHERE r.ev_class = '%s'",
oid);
- result3 = PSQLexec(buf.data);
+ result3 = PSQLexec(buf.data, false);
if (!result3)
goto error_return;
else
" 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);
+ result4 = PSQLexec(buf.data, false);
if (!result4)
goto error_return;
else
"FROM pg_catalog.pg_constraint r\n"
"WHERE r.conrelid = '%s' AND r.contype = 'f'",
oid);
- result5 = PSQLexec(buf.data);
+ result5 = PSQLexec(buf.data, false);
if (!result5)
goto error_return;
else
appendPQExpBuffer(&buf, "ORDER BY 1;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
appendPQExpBuffer(&buf, "ORDER BY 1,2;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
appendPQExpBuffer(&buf, "ORDER BY 1, 2;");
- res = PSQLexec(buf.data);
+ res = PSQLexec(buf.data, false);
termPQExpBuffer(&buf);
if (!res)
return false;
*
* Copyright 2000-2002 by PostgreSQL Global Development Group
*
- * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.22 2002/10/03 17:09:41 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.23 2002/10/15 02:24:16 tgl Exp $
*/
#include "postgres_fe.h"
#include "large_obj.h"
notice[0] = '\0';
old_notice_hook = PQsetNoticeProcessor(pset.db, _my_notice_handler, NULL);
- res = PSQLexec(commit ? "COMMIT" : "ROLLBACK");
+ res = PSQLexec(commit ? "COMMIT" : "ROLLBACK", false);
if (!res)
return false;
if (!handle_transaction())
return false;
- if (!(res = PSQLexec("BEGIN")))
+ if (!(res = PSQLexec("BEGIN", false)))
return false;
PQclear(res);
if (own_transaction)
{
- if (!(res = PSQLexec("COMMIT")))
+ if (!(res = PSQLexec("COMMIT", false)))
{
res = PQexec(pset.db, "ROLLBACK");
PQclear(res);
if (!handle_transaction())
return false;
- if (!(res = PSQLexec("BEGIN")))
+ if (!(res = PSQLexec("BEGIN", false)))
return false;
PQclear(res);
}
strcpy(bufptr, "')");
- if (!(res = PSQLexec(cmdbuf)))
+ if (!(res = PSQLexec(cmdbuf, false)))
{
if (own_transaction)
{
if (own_transaction)
{
- if (!(res = PSQLexec("COMMIT")))
+ if (!(res = PSQLexec("COMMIT", false)))
{
res = PQexec(pset.db, "ROLLBACK");
PQclear(res);
if (!handle_transaction())
return false;
- if (!(res = PSQLexec("BEGIN")))
+ if (!(res = PSQLexec("BEGIN", false)))
return false;
PQclear(res);
sprintf(buf, "DELETE FROM pg_catalog.pg_description WHERE objoid = '%u' "
"AND classoid = 'pg_catalog.pg_largeobject'::regclass",
loid);
- if (!(res = PSQLexec(buf)))
+ if (!(res = PSQLexec(buf, false)))
{
if (own_transaction)
{
if (own_transaction)
{
- if (!(res = PSQLexec("COMMIT")))
+ if (!(res = PSQLexec("COMMIT", false)))
{
res = PQexec(pset.db, "ROLLBACK");
PQclear(res);
"ORDER BY \"ID\"",
gettext("Description"));
- res = PSQLexec(buf);
+ res = PSQLexec(buf, false);
if (!res)
return false;