From 12e41c13545cd8f2071a3cea150cfaa97725fd94 Mon Sep 17 00:00:00 2001 From: craff Date: Tue, 22 Jul 2025 09:57:45 -1000 Subject: [PATCH 1/3] getvalue and alike returns Postgresql.null for NULL values --- lib/postgresql.mli | 8 +++++++- lib/postgresql_stubs.c | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/postgresql.mli b/lib/postgresql.mli index 0fc475a..0baff82 100644 --- a/lib/postgresql.mli +++ b/lib/postgresql.mli @@ -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. diff --git a/lib/postgresql_stubs.c b/lib/postgresql_stubs.c index df581b9..8e762ab 100644 --- a/lib/postgresql_stubs.c +++ b/lib/postgresql_stubs.c @@ -796,6 +796,7 @@ 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); @@ -892,6 +893,7 @@ 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)) From ce43cf021b2f44308890ebbf15c6c5aee41b39bd Mon Sep 17 00:00:00 2001 From: craff Date: Tue, 22 Jul 2025 10:08:42 -1000 Subject: [PATCH 2/3] ocamlformat --- lib/postgresql.mli | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/postgresql.mli b/lib/postgresql.mli index 0baff82..d72c7bd 100644 --- a/lib/postgresql.mli +++ b/lib/postgresql.mli @@ -216,8 +216,8 @@ val null : string [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. *) + 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. From 4787f637d4fc6fbcc5bea4300d0548209c640d14 Mon Sep 17 00:00:00 2001 From: craff Date: Tue, 22 Jul 2025 10:10:55 -1000 Subject: [PATCH 3/3] C formating --- lib/postgresql_stubs.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/postgresql_stubs.c b/lib/postgresql_stubs.c index 8e762ab..56ed610 100644 --- a/lib/postgresql_stubs.c +++ b/lib/postgresql_stubs.c @@ -796,7 +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); + 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); @@ -893,7 +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); + 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))