return conn;
}
-/* throw away response from backend */
-static void
-discard_response(CState *state)
-{
- PGresult *res;
-
- do
- {
- res = PQgetResult(state->con);
- if (res)
- PQclear(res);
- } while (res);
-}
-
/* qsort comparator for Variable array */
static int
compareVariableNames(const void *v1, const void *v2)
readCommandResponse(CState *st, char *varprefix)
{
PGresult *res;
+ PGresult *next_res;
int qrynum = 0;
res = PQgetResult(st->con);
while (res != NULL)
{
/* look now at the next result to know whether it is the last */
- PGresult *next_res = PQgetResult(st->con);
+ next_res = PQgetResult(st->con);
bool is_last = (next_res == NULL);
switch (PQresultStatus(res))
fprintf(stderr,
"client %d script %d command %d query %d: expected one row, got %d\n",
st->id, st->use_file, st->command, qrynum, 0);
- st->ecnt++;
- return false;
+ goto error;
}
break;
fprintf(stderr,
"client %d script %d command %d query %d: expected one row, got %d\n",
st->id, st->use_file, st->command, qrynum, PQntuples(res));
- st->ecnt++;
- PQclear(res);
- discard_response(st);
- return false;
+ goto error;
}
/* store results into variables */
"client %d script %d command %d query %d: error storing into variable %s\n",
st->id, st->use_file, st->command, qrynum,
varname);
- st->ecnt++;
- PQclear(res);
- discard_response(st);
- return false;
+ goto error;
}
if (*varprefix != '\0')
"client %d script %d aborted in command %d query %d: %s",
st->id, st->use_file, st->command, qrynum,
PQerrorMessage(st->con));
- st->ecnt++;
- PQclear(res);
- discard_response(st);
- return false;
+ goto error;
}
PQclear(res);
}
return true;
-}
+error:
+ st->ecnt++;
+ PQclear(res);
+ PQclear(next_res);
+ do
+ {
+ res = PQgetResult(st->con);
+ PQclear(res);
+ } while (res);
+
+ return false;
+}
/*
* Parse the argument to a \sleep command, and return the requested amount