return success;
}
-/*
- * Data structure and functions to record notices while they are
- * emitted, so that they can be shown later.
- *
- * We need to know which result is last, which requires to extract
- * one result in advance, hence two buffers are needed.
- */
-struct t_notice_messages
-{
- PQExpBufferData messages[2];
- int current;
-};
-
-/*
- * Store notices in appropriate buffer, for later display.
- */
-static void
-AppendNoticeMessage(void *arg, const char *msg)
-{
- struct t_notice_messages *notices = arg;
-
- appendPQExpBufferStr(¬ices->messages[notices->current], msg);
-}
-
-/*
- * Show notices stored in buffer, which is then reset.
- */
-static void
-ShowNoticeMessage(struct t_notice_messages *notices)
-{
- PQExpBufferData *current = ¬ices->messages[notices->current];
-
- if (*current->data != '\0')
- pg_log_info("%s", current->data);
- resetPQExpBuffer(current);
-}
-
-
/*
* SendQuery: send the query string to the backend
* (and print out result)
instr_time before,
after;
PGresult *result;
- struct t_notice_messages notices;
if (timing)
INSTR_TIME_SET_CURRENT(before);
return 0;
}
- /* intercept notices */
- notices.current = 0;
- initPQExpBuffer(¬ices.messages[0]);
- initPQExpBuffer(¬ices.messages[1]);
- PQsetNoticeProcessor(pset.db, AppendNoticeMessage, ¬ices);
-
/* first result */
result = PQgetResult(pset.db);
*/
const char *error = PQresultErrorMessage(result);
- ShowNoticeMessage(¬ices);
if (strlen(error))
pg_log_info("%s", error);
if (result_status == PGRES_COPY_IN ||
result_status == PGRES_COPY_OUT)
{
- ShowNoticeMessage(¬ices);
-
if (is_watch)
{
ClearOrSaveAllResults();
return -1;
}
- /* use normal notice processor during COPY */
- PQsetNoticeProcessor(pset.db, NoticeProcessor, NULL);
-
success &= HandleCopyResult(&result);
-
- PQsetNoticeProcessor(pset.db, AppendNoticeMessage, ¬ices);
}
/*
* string, it will return NULL. Otherwise, we'll have other results
* to process. We need to do that to check whether this is the last.
*/
- notices.current ^= 1;
next_result = PQgetResult(pset.db);
- notices.current ^= 1;
last = (next_result == NULL);
/*
*elapsed_msec = INSTR_TIME_GET_MILLISEC(after);
}
- /* notices already shown above for copy */
- ShowNoticeMessage(¬ices);
-
/* this may or may not print something depending on settings */
if (result != NULL)
success &= PrintQueryResult(result, last, false, opt, printQueryFout);
SetResultVariables(result, true);
ClearOrSaveResult(result);
- notices.current ^= 1;
result = next_result;
if (cancel_pressed)
}
}
- /* reset notice hook */
- PQsetNoticeProcessor(pset.db, NoticeProcessor, NULL);
- termPQExpBuffer(¬ices.messages[0]);
- termPQExpBuffer(¬ices.messages[1]);
-
/* may need this to recover from conn loss during COPY */
if (!CheckConnection())
return -1;