From: Sebastian Harl Date: Sun, 5 Oct 2014 18:49:19 +0000 (+0200) Subject: store_lookup: Compare attribute string values on type mismatch. X-Git-Tag: sysdb-0.5.0~7 X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=commitdiff_plain;h=5c63464689b66b8b77a2583978ee701fd3246904 store_lookup: Compare attribute string values on type mismatch. Given that we don't support any schema for attribute values, this sounds like a better option than assuming that those values never match no matter which comparison operator is used. --- diff --git a/src/core/store_lookup.c b/src/core/store_lookup.c index 9176592..3027367 100644 --- a/src/core/store_lookup.c +++ b/src/core/store_lookup.c @@ -121,7 +121,7 @@ attr_cmp(sdb_store_obj_t *obj, sdb_store_cond_t *cond, if (! attr) status = INT_MAX; else if (attr->value.type != value.type) - status = INT_MAX; + status = sdb_data_strcmp(&attr->value, &value); else status = sdb_data_cmp(&attr->value, &value); sdb_data_free_datum(&value); diff --git a/t/unit/core/store_lookup_test.c b/t/unit/core/store_lookup_test.c index 13861bb..a2b1595 100644 --- a/t/unit/core/store_lookup_test.c +++ b/t/unit/core/store_lookup_test.c @@ -287,6 +287,7 @@ START_TEST(test_attr_cond) { "k1", { SDB_TYPE_STRING, { .string = "v1" } }, 0, 1, 1, 1, 0 }, { "k1", { SDB_TYPE_STRING, { .string = "v2" } }, 1, 1, 0, 0, 0 }, { "k1", { SDB_TYPE_STRING, { .string = "v0" } }, 0, 0, 0, 1, 1 }, + { "k1", { SDB_TYPE_STRING, { .string = "0" } }, 0, 0, 0, 1, 1 }, { "k2", { SDB_TYPE_INTEGER, { .integer = 123 } }, 0, 1, 1, 1, 0 }, { "k2", { SDB_TYPE_INTEGER, { .integer = 124 } }, 1, 1, 0, 0, 0 }, { "k2", { SDB_TYPE_INTEGER, { .integer = 122 } }, 0, 0, 0, 1, 1 }, @@ -295,8 +296,8 @@ START_TEST(test_attr_cond) { "k3", { SDB_TYPE_STRING, { .string = "123" } }, 0, 0, 0, 0, 0 }, { "k3", { SDB_TYPE_INTEGER, { .integer = 123 } }, 0, 0, 0, 0, 0 }, /* type mismatch */ - { "k1", { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 0, 0 }, - { "k2", { SDB_TYPE_STRING, { .string = "123" } }, 0, 0, 0, 0, 0 }, + { "k1", { SDB_TYPE_INTEGER, { .integer = 0 } }, 0, 0, 0, 1, 1 }, + { "k2", { SDB_TYPE_STRING, { .string = "123" } }, 0, 1, 1, 1, 0 }, }; int status;