From 7649cd039c4ca73698403baf1bc6c3cad4af8301 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 5 Oct 2014 20:25:32 +0200 Subject: [PATCH] data: Added sdb_data_isnull(). The function determines if a datum pointer or a string or binary datum is NULL. --- src/core/data.c | 12 ++++++++++++ src/include/core/data.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/src/core/data.c b/src/core/data.c index a57c8c6..eeead55 100644 --- a/src/core/data.c +++ b/src/core/data.c @@ -334,6 +334,18 @@ sdb_data_cmp(const sdb_data_t *d1, const sdb_data_t *d2) #undef CMP_NULL } /* sdb_data_cmp */ +_Bool +sdb_data_isnull(const sdb_data_t *datum) +{ + if (! datum) + return 1; + if ((datum->type == SDB_TYPE_STRING) && (! datum->data.string)) + return 1; + if ((datum->type == SDB_TYPE_BINARY) && (! datum->data.binary.datum)) + return 1; + return 0; +} /* sdb_data_isnull */ + int sdb_data_expr_eval(int op, const sdb_data_t *d1, const sdb_data_t *d2, sdb_data_t *res) diff --git a/src/include/core/data.h b/src/include/core/data.h index 02f99c5..af4ae5a 100644 --- a/src/include/core/data.h +++ b/src/include/core/data.h @@ -115,6 +115,14 @@ sdb_data_free_datum(sdb_data_t *datum); int sdb_data_cmp(const sdb_data_t *d1, const sdb_data_t *d2); +/* + * sdb_data_isnull: + * Determine whether a datum is NULL. A datum is considered to be NULL if + * either datum is NULL or if the string or binary datum is NULL. + */ +_Bool +sdb_data_isnull(const sdb_data_t *datum); + /* * Operators supported by sdb_data_eval_expr. */ -- 2.30.2