1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#include "hs-libpq.h"
void
hs_postgresql_libpq_discard_notices(NoticeBuffer* arg, const PGresult* res) {
return;
}
void
hs_postgresql_libpq_store_notices(NoticeBuffer* arg, const PGresult* res) {
if (arg == NULL || res == NULL) return;
const char* msg = PQresultErrorMessage(res);
if (msg == NULL) return;
size_t len = strlen(msg);
PGnotice* notice = (PGnotice*)malloc(sizeof(PGnotice) + sizeof(char)*(len + 1));
notice->next = NULL;
notice->len = len;
memcpy(notice->str, msg, len+1);
if (arg->last == NULL) {
arg->first = notice;
arg->last = notice;
} else {
arg->last->next = notice;
arg->last = notice;
}
}
PGnotice *
hs_postgresql_libpq_get_notice(NoticeBuffer* arg) {
if (arg == NULL) return NULL;
PGnotice * res = arg->first;
if (res == NULL) return NULL;
PGnotice * next = res->next;
arg->first = next;
if (next == NULL) arg->last = NULL;
return res;
}
NoticeBuffer *
hs_postgresql_libpq_malloc_noticebuffer (void) {
NoticeBuffer * arg = (NoticeBuffer*)malloc(sizeof(NoticeBuffer));
if (arg == NULL) return NULL;
arg->first = NULL;
arg->last = NULL;
return arg;
}
void
hs_postgresql_libpq_free_noticebuffer (NoticeBuffer * arg) {
if (arg == NULL) return;
PGnotice * x = arg->first;
PGnotice * nx;
while (x != NULL) {
nx = x->next;
free(x);
x = nx;
}
free(arg);
}
|