From: Sebastian Harl Date: Sun, 5 Oct 2014 18:23:26 +0000 (+0200) Subject: data: Format NULL values as "". X-Git-Tag: sysdb-0.5.0~11 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5756f032cd5fe89316628953ba28f42da792566f;p=sysdb.git data: Format NULL values as "". --- diff --git a/src/core/data.c b/src/core/data.c index 1188b40..a57c8c6 100644 --- a/src/core/data.c +++ b/src/core/data.c @@ -372,13 +372,15 @@ sdb_data_strlen(const sdb_data_t *datum) return 42; case SDB_TYPE_STRING: if (! datum->data.string) - return 6; /* "NULL" */ + return 8; /* "" */ /* in the worst case, each character needs to be escaped */ return 2 * strlen(datum->data.string) + 2; case SDB_TYPE_DATETIME: /* "YYYY-MM-DD HH:MM:SS +zzzz" */ return 27; case SDB_TYPE_BINARY: + if (! datum->data.binary.datum) + return 8; /* "" */ /* "\xNN" */ return 4 * datum->data.binary.length + 2; } @@ -406,7 +408,7 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted) break; case SDB_TYPE_STRING: if (! datum->data.string) - data = "NULL"; + data = ""; else { pos = 0; for (i = 0; i < strlen(datum->data.string); ++i) { @@ -448,8 +450,12 @@ sdb_data_format(const sdb_data_t *datum, char *buf, size_t buflen, int quoted) tmp[pos] = hex[byte & 0xf]; ++pos; } - tmp[pos] = '\0'; - data = tmp; + if (datum->data.binary.datum) { + tmp[pos] = '\0'; + data = tmp; + } + else + data = ""; break; } diff --git a/t/unit/core/data_test.c b/t/unit/core/data_test.c index 606eae5..6f9376f 100644 --- a/t/unit/core/data_test.c +++ b/t/unit/core/data_test.c @@ -537,7 +537,7 @@ START_TEST(test_format) }, { { SDB_TYPE_STRING, { .string = NULL } }, - "\"NULL\"", + "\"\"", }, { { SDB_TYPE_STRING, { .string = "this is a test" } }, @@ -553,7 +553,7 @@ START_TEST(test_format) }, { { SDB_TYPE_BINARY, { .binary = { 0, NULL } } }, - "\"\"", + "\"\"", }, { {