dovecot-1.2: Fixed dict iteration with SQL backend.
dovecot at dovecot.org
dovecot at dovecot.org
Thu Jun 12 01:35:23 EEST 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/59ec9752c3dd
changeset: 7819:59ec9752c3dd
user: Timo Sirainen <tss at iki.fi>
date: Wed Jun 11 23:48:34 2008 +0300
description:
Fixed dict iteration with SQL backend.
diffstat:
1 file changed, 26 insertions(+), 10 deletions(-)
src/lib-dict/dict-sql.c | 36 ++++++++++++++++++++++++++----------
diffs (64 lines):
diff -r a36001eb64af -r 59ec9752c3dd src/lib-dict/dict-sql.c
--- a/src/lib-dict/dict-sql.c Wed Jun 11 16:11:03 2008 +0300
+++ b/src/lib-dict/dict-sql.c Wed Jun 11 23:48:34 2008 +0300
@@ -209,7 +209,8 @@ sql_dict_iterate_init(struct dict *_dict
enum dict_iterate_flags flags)
{
struct sql_dict *dict = (struct sql_dict *)_dict;
- struct sql_dict_iterate_context *ctx;
+ struct sql_dict_iterate_context *ctx;
+ unsigned int len;
bool priv;
ctx = i_new(struct sql_dict_iterate_context, 1);
@@ -221,26 +222,41 @@ sql_dict_iterate_init(struct dict *_dict
}
T_BEGIN {
string_t *query = t_str_new(256);
- str_printfa(query, "SELECT %s, %s FROM %s "
- "WHERE %s LIKE '%s/%%'",
+ str_printfa(query, "SELECT %s, %s FROM %s WHERE ",
dict->where_field, dict->select_field,
- dict->table, dict->where_field,
- sql_escape_string(dict->db, path));
+ dict->table);
+ len = str_len(query);
+
+ if (*path != '\0') {
+ str_printfa(query, "%s LIKE '%s/%%' AND ",
+ dict->where_field,
+ sql_escape_string(dict->db, path));
+ }
if (priv) {
- str_printfa(query, " AND %s = '%s'",
+ str_printfa(query, "%s = '%s' AND ",
dict->username_field,
sql_escape_string(dict->db,
dict->username));
}
- if ((flags & DICT_ITERATE_FLAG_RECURSE) == 0) {
- str_printfa(query, " AND %s NOT LIKE '%s/%%/%%'",
+ if ((flags & DICT_ITERATE_FLAG_RECURSE) != 0) {
+ /* get everything */
+ } else if (*path == '\0') {
+ str_printfa(query, "%s NOT LIKE '%%/%%' AND ",
+ dict->where_field);
+ } else {
+ str_printfa(query, "%s NOT LIKE '%s/%%/%%' AND ",
dict->where_field,
sql_escape_string(dict->db, path));
}
+ if (str_len(query) == len)
+ str_truncate(query, str_len(query) - 6);
+ else
+ str_truncate(query, str_len(query) - 4);
+
if ((flags & DICT_ITERATE_FLAG_SORT_BY_KEY) != 0)
- str_printfa(query, " ORDER BY %s", dict->where_field);
+ str_printfa(query, "ORDER BY %s", dict->where_field);
else if ((flags & DICT_ITERATE_FLAG_SORT_BY_VALUE) != 0)
- str_printfa(query, " ORDER BY %s", dict->select_field);
+ str_printfa(query, "ORDER BY %s", dict->select_field);
ctx->result = sql_query_s(dict->db, str_c(query));
} T_END;
More information about the dovecot-cvs
mailing list