summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8d70fa0)
raw | patch | inline | side by side (parent: 8d70fa0)
author | Sebastian Harl <sh@tokkee.org> | |
Sun, 19 Oct 2014 12:00:41 +0000 (14:00 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sun, 19 Oct 2014 12:00:41 +0000 (14:00 +0200) |
This mimics behavior in SQL and also allows for missing values to be reported
as NULL and propagate that information.
as NULL and propagate that information.
src/core/data.c | patch | blob | history | |
t/unit/core/data_test.c | patch | blob | history |
diff --git a/src/core/data.c b/src/core/data.c
index 557dfd6a5fb3011d276c22ccb31442edaaf59ff1..4840736896f55a03b4cf0716e18e3dec7cb9baec 100644 (file)
--- a/src/core/data.c
+++ b/src/core/data.c
else
return -1;
- if (s1 || s2) {
+ if (s1 && s2) {
new = malloc(len1 + len2 + 1);
if (! new)
return -1;
- }
- else
- new = NULL;
- if (len1)
- memcpy(new, s1, len1);
- if (len2)
- memcpy(new + len1, s2, len2);
- if (new)
+ if (len1)
+ memcpy(new, s1, len1);
+ if (len2)
+ memcpy(new + len1, s2, len2);
new[len1 + len2] = '\0';
+ }
+ else {
+ len1 = len2 = 0;
+ new = NULL;
+ }
res->type = d1->type;
if (res->type == SDB_TYPE_STRING) {
index a1b4caa59965c7b307dcf848d40f0011ea4ea1b8..2336c5e98d335714f510797c31f745126bb938ee 100644 (file)
--- a/t/unit/core/data_test.c
+++ b/t/unit/core/data_test.c
SDB_DATA_INIT,
SDB_DATA_INIT,
SDB_DATA_INIT,
- { SDB_TYPE_STRING, { .string = "" } },
+ { SDB_TYPE_STRING, { .string = NULL } },
},
{
{ SDB_TYPE_STRING, { .string = NULL } },
SDB_DATA_INIT,
SDB_DATA_INIT,
SDB_DATA_INIT,
- { SDB_TYPE_STRING, { .string = "" } },
+ { SDB_TYPE_STRING, { .string = NULL } },
},
{
{ SDB_TYPE_STRING, { .string = "a" } },
SDB_DATA_INIT,
SDB_DATA_INIT,
SDB_DATA_INIT,
- { SDB_TYPE_BINARY, { .binary = { 1, (unsigned char *)"a" } } },
+ { SDB_TYPE_BINARY, { .binary = { 0, NULL } } },
},
{
{ SDB_TYPE_BINARY, { .binary = { 0, NULL } } },
SDB_DATA_INIT,
SDB_DATA_INIT,
SDB_DATA_INIT,
- { SDB_TYPE_BINARY, { .binary = { 1, (unsigned char *)"a" } } },
+ { SDB_TYPE_BINARY, { .binary = { 0, NULL } } },
},
{
{