# HG changeset patch # User Timo Sirainen # Date 1502797570 -10800 # Node ID c9ddf11490a60bc4ade6efb21a6a4788e658b566 # Parent 9bb9e436a6423a114b9e2018e14fce93c84bbc15 dict-sql: Initial change to use sql_statement API sql_statement_bind_*() will be followed by later changes. diff -r 9bb9e436a642 -r c9ddf11490a6 src/lib-dict/dict-sql.c --- a/src/lib-dict/dict-sql.c Tue Aug 15 16:44:27 2017 +0300 +++ b/src/lib-dict/dict-sql.c Tue Aug 15 14:46:10 2017 +0300 @@ -447,8 +447,10 @@ *value_r = NULL; return -1; } - result = sql_query_s(dict->db, str_c(query)); + struct sql_statement *stmt = + sql_statement_init(dict->db, str_c(query)); + result = sql_statement_query_s(&stmt); ret = sql_result_next_row(result); if (ret <= 0) { if (ret < 0) { @@ -518,8 +520,9 @@ ctx->callback = callback; ctx->context = context; ctx->map = map; - sql_query(dict->db, str_c(query), - sql_dict_lookup_async_callback, ctx); + struct sql_statement *stmt = + sql_statement_init(dict->db, str_c(query)); + sql_statement_query(&stmt, sql_dict_lookup_async_callback, ctx); } } @@ -656,15 +659,20 @@ /* failed */ i_error("sql dict iterate failed for %s: %s", ctx->paths[path_idx], error); + return -1; } else if (ret == 0) { /* this is expected error */ - } else if ((ctx->flags & DICT_ITERATE_FLAG_ASYNC) == 0) { - ctx->result = sql_query_s(dict->db, str_c(query)); + return 0; + } + + struct sql_statement *stmt = + sql_statement_init(dict->db, str_c(query)); + if ((ctx->flags & DICT_ITERATE_FLAG_ASYNC) == 0) { + ctx->result = sql_statement_query_s(&stmt); } else { i_assert(ctx->result == NULL); ctx->synchronous_result = TRUE; - sql_query(dict->db, str_c(query), - sql_dict_iterate_callback, ctx); + sql_statement_query(&stmt, sql_dict_iterate_callback, ctx); ctx->synchronous_result = FALSE; } return ret; @@ -1087,7 +1095,9 @@ key, value, error); ctx->failed = TRUE; } else { - sql_update(ctx->sql_ctx, query); + struct sql_statement *stmt = + sql_statement_init(dict->db, query); + sql_update_stmt(ctx->sql_ctx, &stmt); } } @@ -1121,7 +1131,9 @@ i_error("dict-sql: Failed to delete %s: %s", key, error); ctx->failed = TRUE; } else { - sql_update(ctx->sql_ctx, str_c(query)); + struct sql_statement *stmt = + sql_statement_init(dict->db, str_c(query)); + sql_update_stmt(ctx->sql_ctx, &stmt); } } @@ -1179,8 +1191,10 @@ i_error("dict-sql: Failed to increase %s: %s", key, error); ctx->failed = TRUE; } else { - sql_update_get_rows(ctx->sql_ctx, query, - sql_dict_next_inc_row(ctx)); + struct sql_statement *stmt = + sql_statement_init(dict->db, query); + sql_update_stmt_get_rows(ctx->sql_ctx, &stmt, + sql_dict_next_inc_row(ctx)); } } @@ -1289,7 +1303,9 @@ i_error("dict-sql: Failed to set %s: %s", key, error); ctx->failed = TRUE; } else { - sql_update(ctx->sql_ctx, query); + struct sql_statement *stmt = + sql_statement_init(dict->db, query); + sql_update_stmt(ctx->sql_ctx, &stmt); } i_free_and_null(ctx->prev_set_value); i_free_and_null(ctx->prev_set_key); @@ -1348,8 +1364,10 @@ i_error("dict-sql: Failed to increase %s: %s", key, error); ctx->failed = TRUE; } else { - sql_update_get_rows(ctx->sql_ctx, query, - sql_dict_next_inc_row(ctx)); + struct sql_statement *stmt = + sql_statement_init(dict->db, query); + sql_update_stmt_get_rows(ctx->sql_ctx, &stmt, + sql_dict_next_inc_row(ctx)); } i_free_and_null(ctx->prev_inc_key);