Mercurial > dovecot > core-2.2
changeset 19298:6bb60a869c71
dict-sql: Added support for value_type field, which deprecates value_hexblob.
value_type=string|hexblob|uint are supported now.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Tue, 13 Oct 2015 20:40:38 +0300 |
parents | c854e1b3e419 |
children | b0545670fd99 |
files | src/lib-dict/dict-sql-settings.c src/lib-dict/dict-sql-settings.h src/lib-dict/dict-sql.c |
diffstat | 3 files changed, 28 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-dict/dict-sql-settings.c Tue Oct 13 20:39:50 2015 +0300 +++ b/src/lib-dict/dict-sql-settings.c Tue Oct 13 20:40:38 2015 +0300 @@ -36,6 +36,7 @@ DEF_STR(table), DEF_STR(username_field), DEF_STR(value_field), + DEF_STR(value_type), DEF_BOOL(value_hexblob), { 0, NULL, 0 } @@ -129,6 +130,12 @@ return "Missing setting: table"; if (ctx->cur_map.value_field == NULL) return "Missing setting: value_field"; + if (ctx->cur_map.value_type != NULL) { + if (strcmp(ctx->cur_map.value_type, "string") != 0 && + strcmp(ctx->cur_map.value_type, "hexblob") != 0 && + strcmp(ctx->cur_map.value_type, "uint") != 0) + return "Invalid value in value_type"; + } if (ctx->cur_map.username_field == NULL) { /* not all queries require this */
--- a/src/lib-dict/dict-sql-settings.h Tue Oct 13 20:39:50 2015 +0300 +++ b/src/lib-dict/dict-sql-settings.h Tue Oct 13 20:40:38 2015 +0300 @@ -19,6 +19,7 @@ const char *table; const char *username_field; const char *value_field; + const char *value_type; bool value_hexblob; ARRAY(struct dict_sql_field) sql_fields;
--- a/src/lib-dict/dict-sql.c Tue Oct 13 20:39:50 2015 +0300 +++ b/src/lib-dict/dict-sql.c Tue Oct 13 20:40:38 2015 +0300 @@ -380,13 +380,26 @@ return str_c(str); } +static enum dict_sql_type +sql_dict_map_type(const struct dict_sql_map *map) +{ + if (map->value_type != NULL) { + if (strcmp(map->value_type, "string") == 0) + return DICT_SQL_TYPE_STRING; + if (strcmp(map->value_type, "hexblob") == 0) + return DICT_SQL_TYPE_HEXBLOB; + if (strcmp(map->value_type, "uint") == 0) + return DICT_SQL_TYPE_UINT; + i_unreached(); /* should have checked already at parsing */ + } + return map->value_hexblob ? DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING; +} + static const char * sql_dict_result_unescape_value(const struct dict_sql_map *map, pool_t pool, struct sql_result *result) { - enum dict_sql_type value_type = map->value_hexblob ? - DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING; - return sql_dict_result_unescape(value_type, pool, result, 0); + return sql_dict_result_unescape(sql_dict_map_type(map), pool, result, 0); } static const char * @@ -876,8 +889,8 @@ if (build->inc) str_append(suffix, fields[i].value); else { - enum dict_sql_type value_type = fields[i].map->value_hexblob ? - DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING; + enum dict_sql_type value_type = + sql_dict_map_type(fields[i].map); if (sql_dict_value_escape(suffix, dict, value_type, "value", fields[i].value, "", error_r) < 0) return -1; @@ -919,8 +932,8 @@ fields[i].map->value_field, fields[i].value); } else { - enum dict_sql_type value_type = fields[i].map->value_hexblob ? - DICT_SQL_TYPE_HEXBLOB : DICT_SQL_TYPE_STRING; + enum dict_sql_type value_type = + sql_dict_map_type(fields[i].map); if (sql_dict_value_escape(prefix, dict, value_type, "value", fields[i].value, "", error_r) < 0) return -1;