Skip to content

getvalue and alike returns Postgresql.null for NULL values #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/postgresql.mli
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ val invalid_oid : oid
val null : string
(** [null] can be used as an element of the optional argument [parameters]
passed to the [exec] or [send_query] method to indicate a NULL value. It is
an empty string, but not physically equal to [""]. *)
an empty string, but not physically equal to [""].

[null] is also returned by [getvalue] and [get_escaped_value], [gettuple],
... for NULL values.

Remark: is you use NULL within array or other structured data, you will have
to handle NULL values according to postgresql documentation. *)

(** Class type of query results.

Expand Down
4 changes: 4 additions & 0 deletions lib/postgresql_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,8 @@ CAMLprim value PQgetvalue_stub(value v_res, intnat tup_num, intnat field_num) {
CAMLparam1(v_res);
value v_str;
PGresult *res = get_res(v_res);
if (PQgetisnull(res, tup_num, field_num))
CAMLreturn(*v_null_param);
char *str = PQgetvalue(res, tup_num, field_num);
if (PQfformat(res, field_num) == 0)
v_str = make_string(str);
Expand Down Expand Up @@ -892,6 +894,8 @@ CAMLprim value PQgetescval_stub(value v_res, intnat tup_num, intnat field_num) {
CAMLparam1(v_res);
value v_str;
PGresult *res = get_res(v_res);
if (PQgetisnull(res, tup_num, field_num))
CAMLreturn(*v_null_param);
char *str = PQgetvalue(res, tup_num, field_num);
if (PQfformat(res, field_num) == 0) {
if (str == NULL || strlen(str) < 2 || !is_bytea_hex_protocol(str))
Expand Down