]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Better handling of SQL rcodes in xlats
authorNick Porter <nick@portercomputing.co.uk>
Thu, 24 Oct 2024 07:59:40 +0000 (08:59 +0100)
committerNick Porter <nick@portercomputing.co.uk>
Thu, 24 Oct 2024 07:59:40 +0000 (08:59 +0100)
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.

src/modules/rlm_sql/rlm_sql.c

index f55293081a8afa08bc5b6cc9c0c12f85731acdea..3b5fc7abab61ef8465ea08c11046449f4016fe58 100644 (file)
@@ -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);