summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ca70642)
raw | patch | inline | side by side (parent: ca70642)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 20 Feb 2014 20:27:38 +0000 (21:27 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 20 Feb 2014 20:27:38 +0000 (21:27 +0100) |
src/core/data.c | patch | blob | history | |
t/core/data_test.c | patch | blob | history |
diff --git a/src/core/data.c b/src/core/data.c
index 500a62293dbbdc44f53a1db64534554ea91540c0..81b511b6c48fda961b51e9d770f13da415cabfac 100644 (file)
--- a/src/core/data.c
+++ b/src/core/data.c
sdb_strbuf_append(buf, "%a", datum->data.decimal);
break;
case SDB_TYPE_STRING:
+ if (! datum->data.string) {
+ sdb_strbuf_append(buf, "\"NULL\"");
+ return 0;
+ }
/* TODO: escape special characters */
sdb_strbuf_append(buf, "\"%s\"", datum->data.string);
break;
diff --git a/t/core/data_test.c b/t/core/data_test.c
index ebff6845df196a702870b781820f88e1050240db..a16d7fef891a287cec3444d0e5d74872097376f8 100644 (file)
--- a/t/core/data_test.c
+++ b/t/core/data_test.c
"sdb_data_format() used wrong format: %s; expected: %s",
string, expected);
+ datum.data.string = NULL;
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(STRING) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "\"NULL\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
+
datum.type = SDB_TYPE_DATETIME;
datum.data.datetime = 471147114711471100;
sdb_strbuf_clear(buf);
fail_unless(! strcmp(string, expected),
"sdb_data_format() used wrong format: %s; expected: %s",
string, expected);
+
+ datum.data.binary.datum = NULL;
+ datum.data.binary.length = 0;
+ sdb_strbuf_clear(buf);
+ check = sdb_data_format(&datum, buf);
+ fail_unless(! check,
+ "sdb_data_format(BINARY) = %d; expected: 0", check);
+ string = sdb_strbuf_string(buf);
+ expected = "\"\"";
+ fail_unless(! strcmp(string, expected),
+ "sdb_data_format() used wrong format: %s; expected: %s",
+ string, expected);
}
END_TEST