Skip to content

Commit 80a704b

Browse files
authored
Merge pull request #56 from craff/main
getvalue and alike returns Postgresql.null for NULL values
2 parents 25beb88 + 4787f63 commit 80a704b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/postgresql.mli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,13 @@ val invalid_oid : oid
211211
val null : string
212212
(** [null] can be used as an element of the optional argument [parameters]
213213
passed to the [exec] or [send_query] method to indicate a NULL value. It is
214-
an empty string, but not physically equal to [""]. *)
214+
an empty string, but not physically equal to [""].
215+
216+
[null] is also returned by [getvalue] and [get_escaped_value], [gettuple],
217+
... for NULL values.
218+
219+
Remark: is you use NULL within array or other structured data, you will have
220+
to handle NULL values according to postgresql documentation. *)
215221

216222
(** Class type of query results.
217223

lib/postgresql_stubs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,8 @@ CAMLprim value PQgetvalue_stub(value v_res, intnat tup_num, intnat field_num) {
796796
CAMLparam1(v_res);
797797
value v_str;
798798
PGresult *res = get_res(v_res);
799+
if (PQgetisnull(res, tup_num, field_num))
800+
CAMLreturn(*v_null_param);
799801
char *str = PQgetvalue(res, tup_num, field_num);
800802
if (PQfformat(res, field_num) == 0)
801803
v_str = make_string(str);
@@ -892,6 +894,8 @@ CAMLprim value PQgetescval_stub(value v_res, intnat tup_num, intnat field_num) {
892894
CAMLparam1(v_res);
893895
value v_str;
894896
PGresult *res = get_res(v_res);
897+
if (PQgetisnull(res, tup_num, field_num))
898+
CAMLreturn(*v_null_param);
895899
char *str = PQgetvalue(res, tup_num, field_num);
896900
if (PQfformat(res, field_num) == 0) {
897901
if (str == NULL || strlen(str) < 2 || !is_bytea_hex_protocol(str))

0 commit comments

Comments
 (0)