Skip to content

Commit

Permalink
Better handling of SQL rcodes in xlats
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ndptech committed Oct 24, 2024
1 parent 223af39 commit 5d02b1d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/modules/rlm_sql/rlm_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<INVALID>"));
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);
Expand Down

0 comments on commit 5d02b1d

Please sign in to comment.