architecture than the database server. If you pass a NULL pointer, the
column is skipped, and you can use libpq to handle it as you wish.
-I have used sigprocmask() to block the reception of certain signals
-while the program is executing SQL queries. This prevents a user
-pressing Control-C from stopping all the back ends. It blocks SIGHUP,
-SIGINT, and SIGTERM, but does not block SIGQUIT or obviously kill -9.
-If your platform does not support sigprocmask(), you can remove those
-function calls. ( Am I correct that abnormal termination can cause
-shared memory resynchronization?)
-
There is a demo program called pginsert that demonstrates how the
library can be used.
*/
#include <stdio.h>
-#include <signal.h>
#include <string.h>
#include <stdarg.h>
#include "halt.h"
#include "pginterface.h"
-static void sig_disconnect();
-static void set_signals();
-
#define NUL '\0'
/* GLOBAL VARIABLES */
static int on_error_state = ON_ERROR_STOP;
/* LOCAL VARIABLES */
-static sigset_t block_sigs,
- unblock_sigs;
static int tuple;
/*
if (PQstatus(conn) == CONNECTION_BAD)
halt("Connection to database '%s' failed.\n%s\n", dbName,
PQerrorMessage(conn));
- set_signals();
return conn;
}
if (res != NULL)
PQclear(res);
- sigprocmask(SIG_SETMASK, &block_sigs, NULL);
res = PQexec(conn, query);
- sigprocmask(SIG_SETMASK, &unblock_sigs, NULL);
if (on_error_state == ON_ERROR_STOP &&
(res == NULL ||
{
on_error_state = ON_ERROR_CONTINUE;
}
-
-/*
-**
-** sig_disconnect
-**
-*/
-static void
-sig_disconnect()
-{
- fprintf(stderr, "exiting...\n");
- PQfinish(conn);
- exit(1);
-}
-
-/*
-**
-** set_signals
-**
-*/
-static void
-set_signals()
-{
- sigemptyset(&block_sigs);
- sigemptyset(&unblock_sigs);
- sigaddset(&block_sigs, SIGTERM);
- sigaddset(&block_sigs, SIGHUP);
- sigaddset(&block_sigs, SIGINT);
-/* sigaddset(&block_sigs,SIGQUIT); no block */
- sigprocmask(SIG_SETMASK, &unblock_sigs, NULL);
- signal(SIGTERM, sig_disconnect);
- signal(SIGHUP, sig_disconnect);
- signal(SIGINT, sig_disconnect);
- signal(SIGQUIT, sig_disconnect);
-}