68 #define add1(str, value) \ 69 if (value != NULL && octstr_len(value) > 0) { \ 70 tmp = octstr_format(str, value); \ 71 octstr_append(cs, tmp); \ 72 octstr_destroy(tmp); \ 76 static void *pgsql_open_conn(
const DBConf *db_conf)
87 add1(
" host=%S", conf->
host);
99 add1(
" password=%S", conf->
password);
115 if (PQstatus(conn) == CONNECTION_BAD) {
117 panic(0,
"PGSQL: %s", PQerrorMessage(conn));
131 static void pgsql_close_conn(
void *conn)
141 static int pgsql_check_conn(
void *conn)
146 if (PQstatus(conn) == CONNECTION_BAD) {
147 error(0,
"PGSQL: Database check failed!");
148 error(0,
"PGSQL: %s", PQerrorMessage(conn));
156 static void pgsql_conf_destroy(
DBConf *db_conf)
170 static int pgsql_update(
void *theconn,
const Octstr *sql,
List *binds)
173 PGresult *res = NULL;
174 PGconn *conn = (PGconn*) theconn;
180 switch (PQresultStatus(res)) {
181 case PGRES_BAD_RESPONSE:
182 case PGRES_NONFATAL_ERROR:
183 case PGRES_FATAL_ERROR:
185 error(0,
"PGSQL: %s", PQresultErrorMessage(res));
191 rows = atoi(PQcmdTuples(res));
198 static int pgsql_select(
void *theconn,
const Octstr *sql,
List *binds,
List **list)
200 int nTuples, nFields, row_loop, field_loop;
201 PGresult *res = NULL;
203 PGconn *conn = (PGconn*) theconn;
212 switch (PQresultStatus(res)) {
213 case PGRES_EMPTY_QUERY:
214 case PGRES_BAD_RESPONSE:
215 case PGRES_NONFATAL_ERROR:
216 case PGRES_FATAL_ERROR:
218 error(0,
"PGSQL: %s", PQresultErrorMessage(res));
225 nTuples = PQntuples(res);
226 nFields = PQnfields(res);
228 for (row_loop = 0; row_loop < nTuples; row_loop++) {
230 for (field_loop = 0; field_loop < nFields; field_loop++) {
231 if (PQgetisnull(res, row_loop, field_loop))
244 static struct db_ops pgsql_ops = {
245 .
open = pgsql_open_conn,
246 .close = pgsql_close_conn,
247 .check = pgsql_check_conn,
248 .conf_destroy = pgsql_conf_destroy,
249 .update = pgsql_update,
250 .select = pgsql_select
void error(int err, const char *fmt,...)
void info(int err, const char *fmt,...)
gw_assert(wtls_machine->packet_to_send !=NULL)
void gwlist_produce(List *list, void *item)
void octstr_append_cstr(Octstr *ostr, const char *cstr)
#define octstr_get_cstr(ostr)
void octstr_destroy(Octstr *ostr)
#define octstr_create(cstr)
void octstr_append_decimal(Octstr *ostr, long value)
void *(* open)(const DBConf *conf)