dovecot-2.2: dict-sql: Added support for "uint" field type.
dovecot at dovecot.org
dovecot at dovecot.org
Wed Sep 30 15:13:39 UTC 2015
details: http://hg.dovecot.org/dovecot-2.2/rev/22015b472147
changeset: 19257:22015b472147
user: Timo Sirainen <tss at iki.fi>
date: Wed Sep 30 18:11:53 2015 +0300
description:
dict-sql: Added support for "uint" field type.
diffstat:
src/lib-dict/dict-sql-settings.c | 5 +++++
src/lib-dict/dict-sql-settings.h | 1 +
src/lib-dict/dict-sql.c | 22 ++++++++++++++++++++--
3 files changed, 26 insertions(+), 2 deletions(-)
diffs (70 lines):
diff -r 6785752f1e25 -r 22015b472147 src/lib-dict/dict-sql-settings.c
--- a/src/lib-dict/dict-sql-settings.c Wed Sep 30 17:38:12 2015 +0300
+++ b/src/lib-dict/dict-sql-settings.c Wed Sep 30 18:11:53 2015 +0300
@@ -177,6 +177,11 @@
field->variable = p_strndup(ctx->pool, value + 10,
value_len-10-1);
field->sql_field.value_type = DICT_SQL_TYPE_HEXBLOB;
+ } else if (strncmp(value, "${uint:", 7) == 0 &&
+ value[value_len-1] == '}') {
+ field->variable = p_strndup(ctx->pool, value + 7,
+ value_len-7-1);
+ field->sql_field.value_type = DICT_SQL_TYPE_UINT;
} else {
field->variable = p_strdup(ctx->pool, value + 1);
}
diff -r 6785752f1e25 -r 22015b472147 src/lib-dict/dict-sql-settings.h
--- a/src/lib-dict/dict-sql-settings.h Wed Sep 30 17:38:12 2015 +0300
+++ b/src/lib-dict/dict-sql-settings.h Wed Sep 30 18:11:53 2015 +0300
@@ -3,6 +3,7 @@
enum dict_sql_type {
DICT_SQL_TYPE_STRING = 0,
+ DICT_SQL_TYPE_UINT,
DICT_SQL_TYPE_HEXBLOB
};
diff -r 6785752f1e25 -r 22015b472147 src/lib-dict/dict-sql.c
--- a/src/lib-dict/dict-sql.c Wed Sep 30 17:38:12 2015 +0300
+++ b/src/lib-dict/dict-sql.c Wed Sep 30 18:11:53 2015 +0300
@@ -218,11 +218,24 @@
const char **error_r)
{
buffer_t *buf;
+ unsigned int num;
- if (value_type == DICT_SQL_TYPE_STRING) {
+ switch (value_type) {
+ case DICT_SQL_TYPE_STRING:
str_printfa(str, "'%s%s'", sql_escape_string(dict->db, value),
value_suffix);
return 0;
+ case DICT_SQL_TYPE_UINT:
+ if (value_suffix[0] != '\0' || str_to_uint(value, &num) < 0) {
+ *error_r = t_strdup_printf(
+ "field %s value isn't unsigned integer: %s%s",
+ field_name, value, value_suffix);
+ return -1;
+ }
+ str_printfa(str, "%u", num);
+ return 0;
+ case DICT_SQL_TYPE_HEXBLOB:
+ break;
}
buf = buffer_create_dynamic(pool_datastack_create(), strlen(value)/2);
@@ -353,8 +366,13 @@
size_t size;
string_t *str;
- if (type == DICT_SQL_TYPE_STRING)
+ switch (type) {
+ case DICT_SQL_TYPE_STRING:
+ case DICT_SQL_TYPE_UINT:
return p_strdup(pool, sql_result_get_field_value(result, result_idx));
+ case DICT_SQL_TYPE_HEXBLOB:
+ break;
+ }
data = sql_result_get_field_value_binary(result, result_idx, &size);
str = str_new(pool, size*2 + 1);
More information about the dovecot-cvs
mailing list