diff --git a/src/core/data.c b/src/core/data.c
index 557dfd6a5fb3011d276c22ccb31442edaaf59ff1..9890aafb65c80fded00ba1db13db3390908bfef9 100644 (file)
--- a/src/core/data.c
+++ b/src/core/data.c
#include "core/data.h"
#include "utils/error.h"
+#include <assert.h>
+
#include <errno.h>
#include <inttypes.h>
else
return -1;
- if (s1 || s2) {
- new = malloc(len1 + len2 + 1);
- if (! new)
- return -1;
- }
- else
- new = NULL;
+ assert(s1 && s2);
+
+ new = malloc(len1 + len2 + 1);
+ if (! new)
+ return -1;
if (len1)
memcpy(new, s1, len1);
if (len2)
memcpy(new + len1, s2, len2);
- if (new)
- new[len1 + len2] = '\0';
+ new[len1 + len2] = '\0';
res->type = d1->type;
if (res->type == SDB_TYPE_STRING) {
* public API
*/
+const sdb_data_t SDB_DATA_NULL = SDB_DATA_INIT;
+
int
sdb_data_copy(sdb_data_t *dst, const sdb_data_t *src)
{
{
if (! datum)
return 1;
+ if (datum->type == SDB_TYPE_NULL)
+ return 1;
if ((datum->type == SDB_TYPE_STRING) && (! datum->data.string))
return 1;
if ((datum->type == SDB_TYPE_BINARY) && (! datum->data.binary.datum))
{
if ((! d1) || (! d2) || (! res))
return -1;
+ if (sdb_data_isnull(d1) || sdb_data_isnull(d2)) {
+ *res = SDB_DATA_NULL;
+ return 0;
+ }
switch (op) {
case SDB_DATA_CONCAT:
return data_concat(d1, d2, res);
return 0;
} /* sdb_data_parse */
+size_t
+sdb_data_sizeof(int type)
+{
+ sdb_data_t v;
+ if (type == SDB_TYPE_INTEGER)
+ return sizeof(v.data.integer);
+ else if (type == SDB_TYPE_DECIMAL)
+ return sizeof(v.data.decimal);
+ else if (type == SDB_TYPE_STRING)
+ return sizeof(v.data.string);
+ else if (type == SDB_TYPE_DATETIME)
+ return sizeof(v.data.datetime);
+ else if (type == SDB_TYPE_BINARY)
+ return sizeof(v.data.binary);
+ else if (type == SDB_TYPE_REGEX)
+ return sizeof(v.data.re);
+ return 0;
+} /* sdb_data_sizeof */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */