From: Nick Porter Date: Thu, 24 Oct 2024 07:59:40 +0000 (+0100) Subject: Better handling of SQL rcodes in xlats X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d02b1d55b1a15f91c511e24b604258f78700fef;p=thirdparty%2Ffreeradius-server.git Better handling of SQL rcodes in xlats If RLM_SQL_ALT_QUERY is treated as an error, then redundant SQL xlats will try the same query again on each database host (with the same result). To handle switching to a different query if an INSERT fails due to key contraints, then the return value of the xlat, which is the number of affected rows should be checked instead. --- diff --git a/src/modules/rlm_sql/rlm_sql.c b/src/modules/rlm_sql/rlm_sql.c index f55293081a8..3b5fc7abab6 100644 --- a/src/modules/rlm_sql/rlm_sql.c +++ b/src/modules/rlm_sql/rlm_sql.c @@ -456,12 +456,18 @@ static xlat_action_t sql_xlat_query_resume(TALLOC_CTX *ctx, fr_dcursor_t *out, x fr_assert(query_ctx->type == SQL_QUERY_OTHER); - if (query_ctx->rcode != RLM_SQL_OK) { + switch (query_ctx->rcode) { + case RLM_SQL_QUERY_INVALID: + case RLM_SQL_ERROR: + case RLM_SQL_RECONNECT: RERROR("SQL query failed: %s", fr_table_str_by_value(sql_rcode_description_table, query_ctx->rcode, "")); rlm_sql_print_error(inst, request, query_ctx, false); ret = XLAT_ACTION_FAIL; goto finish; + + default: + break; } numaffected = (inst->driver->sql_affected_rows)(query_ctx, &inst->config);