}
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
- rlm_sql_cassandra_conn_t *conn = handle->conn;
+ rlm_sql_cassandra_conn_t *conn = query_ctx->handle->conn;
if (conn->last_error.msg && (outlen >= 1)) {
out[0].msg = conn->last_error.msg;
return RLM_SQL_OK;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller will free any memory allocated in ctx.
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
char state[6];
char errbuff[1024];
SQLINTEGER err;
SQLSMALLINT rl;
- rlm_sql_db2_conn_t *conn = handle->conn;
+ rlm_sql_db2_conn_t *conn = query_ctx->handle->conn;
fr_assert(conn);
fr_assert(outlen > 0);
return 0;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller will free any memory allocated in ctx.
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
- rlm_sql_firebird_conn_t *conn = handle->conn;
+ rlm_sql_firebird_conn_t *conn = query_ctx->handle->conn;
fr_assert(conn);
fr_assert(outlen > 0);
return RLM_SQL_OK;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller will free any memory allocated in ctx.
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
- rlm_sql_freetds_conn_t *conn = handle->conn;
+ rlm_sql_freetds_conn_t *conn = query_ctx->handle->conn;
fr_assert(conn && conn->db);
fr_assert(outlen > 0);
MEM(query_ctx = fr_sql_query_alloc(NULL, handle->inst, NULL, handle, NULL, database, SQL_QUERY_OTHER));
if ((sql_query(&p_result, NULL, NULL, query_ctx) == UNLANG_ACTION_CALCULATE_RESULT) &&
(query_ctx->rcode != RLM_SQL_OK)) {
+ talloc_free(query_ctx);
goto error;
}
talloc_free(query_ctx);
if (conn->context) {
sql_log_entry_t error;
- if (sql_error(NULL, &error, 1, handle, config) > 0) ERROR("%s", error.msg);
+ if (sql_error(NULL, &error, 1, &(fr_sql_query_t){ .handle = handle }, config) > 0) ERROR("%s", error.msg);
}
return RLM_SQL_ERROR;
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param conn MySQL connection the query was run on.
* @param config rlm_sql config.
* @return
* - Number of errors written to the #sql_log_entry_t array.
* - -1 on failure.
*/
static size_t sql_warnings(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ rlm_sql_mysql_conn_t *conn, UNUSED rlm_sql_config_t const *config)
{
- rlm_sql_mysql_conn_t *conn = talloc_get_type_abort(handle->conn, rlm_sql_mysql_conn_t);
-
MYSQL_RES *result;
MYSQL_ROW row;
unsigned int num_fields;
return i;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller should free any memory allocated in ctx (talloc_free_children()).
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen,
- rlm_sql_handle_t *handle, rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, rlm_sql_config_t const *config)
{
- rlm_sql_mysql_t *inst = talloc_get_type_abort(handle->inst->driver_submodule->data, rlm_sql_mysql_t);
- rlm_sql_mysql_conn_t *conn = talloc_get_type_abort(handle->conn, rlm_sql_mysql_conn_t);
+ rlm_sql_mysql_t const *inst = talloc_get_type_abort_const(query_ctx->inst->driver_submodule->data, rlm_sql_mysql_t);
+ rlm_sql_mysql_conn_t *conn = talloc_get_type_abort(query_ctx->handle->conn, rlm_sql_mysql_conn_t);
char const *error;
size_t i = 0;
FALL_THROUGH;
case SERVER_WARNINGS_YES:
- ret = sql_warnings(ctx, out, outlen - 1, handle, config);
+ ret = sql_warnings(ctx, out, outlen - 1, conn, config);
if (ret > 0) i += ret;
break;
*
*/
static size_t sql_error(UNUSED TALLOC_CTX *ctx, UNUSED sql_log_entry_t out[], UNUSED size_t outlen,
- UNUSED rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ UNUSED fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
return 0;
}
return 0;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller will free any memory allocated in ctx.
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen,
- rlm_sql_handle_t *handle, rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, rlm_sql_config_t const *config)
{
char errbuff[512];
int ret;
fr_assert(outlen > 0);
- ret = sql_snprint_error(errbuff, sizeof(errbuff), handle, config);
+ ret = sql_snprint_error(errbuff, sizeof(errbuff), query_ctx->handle, config);
if (ret < 0) return 0;
out[0].type = L_ERR;
return 0;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller will free any memory allocated in ctx.
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
- rlm_sql_postgres_conn_t *conn = handle->conn;
+ rlm_sql_postgres_conn_t *conn = query_ctx->handle->conn;
char const *p, *q;
size_t i = 0;
return RLM_SQL_OK;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller will free any memory allocated in ctx.
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of sql_log_entrys to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(UNUSED TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
- rlm_sql_sqlite_conn_t *conn = handle->conn;
+ rlm_sql_sqlite_conn_t *conn = query_ctx->handle->conn;
char const *error;
fr_assert(outlen > 0);
return 0;
}
-/** Retrieves any errors associated with the connection handle
+/** Retrieves any errors associated with the query context
*
* @note Caller will free any memory allocated in ctx.
*
* @param ctx to allocate temporary error buffers in.
* @param out Array of #sql_log_entry_t to fill.
* @param outlen Length of out array.
- * @param handle rlm_sql connection handle.
+ * @param query_ctx Query context to retrieve error for.
* @param config rlm_sql config.
* @return number of errors written to the #sql_log_entry_t array.
*/
static size_t sql_error(TALLOC_CTX *ctx, sql_log_entry_t out[], NDEBUG_UNUSED size_t outlen,
- rlm_sql_handle_t *handle, UNUSED rlm_sql_config_t const *config)
+ fr_sql_query_t *query_ctx, UNUSED rlm_sql_config_t const *config)
{
- rlm_sql_unixodbc_conn_t *conn = handle->conn;
+ rlm_sql_unixodbc_conn_t *conn = query_ctx->handle->conn;
SQLCHAR state[256];
SQLCHAR errbuff[256];
SQLINTEGER errnum = 0;
* 0 - If no error messages are available.
* >0 - Number of log entries
*/
-typedef size_t (*sql_error_t)(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, rlm_sql_handle_t *handle,
+typedef size_t (*sql_error_t)(TALLOC_CTX *ctx, sql_log_entry_t out[], size_t outlen, fr_sql_query_t *handle,
rlm_sql_config_t const *config);
typedef struct {
unlang_action_t rlm_sql_select_query(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx);
unlang_action_t rlm_sql_query(rlm_rcode_t *p_result, int *priority, request_t *request, void *uctx);
unlang_action_t rlm_sql_fetch_row(rlm_rcode_t *p_result, UNUSED int *priority, request_t *request, void *uctx);
-void rlm_sql_print_error(rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, bool force_debug);
+void rlm_sql_print_error(rlm_sql_t const *inst, request_t *request, fr_sql_query_t *query_ctx, bool force_debug);
fr_sql_query_t *fr_sql_query_alloc(TALLOC_CTX *ctx, rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, fr_trunk_t *trunk, char const *query_str, fr_sql_query_type_t type);
/*
default:
ROPTIONAL(RERROR, ERROR, "Error fetching row");
- rlm_sql_print_error(inst, request, query_ctx->handle, false);
+ rlm_sql_print_error(inst, request, query_ctx, false);
RETURN_MODULE_FAIL;
}
}
*
* @param inst Instance of rlm_sql.
* @param request Current request, may be NULL.
- * @param handle Handle to retrieve errors for.
+ * @param query_ctx Query context to retrieve errors for.
* @param force_debug Force all errors to be logged as debug messages.
*/
-void rlm_sql_print_error(rlm_sql_t const *inst, request_t *request, rlm_sql_handle_t *handle, bool force_debug)
+void rlm_sql_print_error(rlm_sql_t const *inst, request_t *request, fr_sql_query_t *query_ctx, bool force_debug)
{
char const *driver = inst->driver_submodule->name;
sql_log_entry_t log[20];
size_t num, i;
+ TALLOC_CTX *log_ctx = talloc_new(NULL);
- num = (inst->driver->sql_error)(handle->log_ctx, log, (NUM_ELEMENTS(log)), handle, &inst->config);
+ num = (inst->driver->sql_error)(log_ctx, log, (NUM_ELEMENTS(log)), query_ctx, &inst->config);
if (num == 0) {
ROPTIONAL(RERROR, ERROR, "Unknown error");
+ talloc_free(log_ctx);
return;
}
}
}
- talloc_free_children(handle->log_ctx);
+ talloc_free(log_ctx);
}
/** Automatically run the correct `finish` function when freeing an SQL query
* These are bad and should make rlm_sql return invalid
*/
case RLM_SQL_QUERY_INVALID:
- rlm_sql_print_error(inst, request, query_ctx->handle, false);
+ rlm_sql_print_error(inst, request, query_ctx, false);
(inst->driver->sql_finish_query)(query_ctx, &inst->config);
RETURN_MODULE_INVALID;
*/
case RLM_SQL_ERROR:
if (inst->driver->flags & RLM_SQL_RCODE_FLAGS_ALT_QUERY) {
- rlm_sql_print_error(inst, request, query_ctx->handle, false);
+ rlm_sql_print_error(inst, request, query_ctx, false);
(inst->driver->sql_finish_query)(query_ctx, &inst->config);
RETURN_MODULE_FAIL;
}
* Driver suggested using an alternative query
*/
case RLM_SQL_ALT_QUERY:
- rlm_sql_print_error(inst, request, query_ctx->handle, true);
+ rlm_sql_print_error(inst, request, query_ctx, true);
(inst->driver->sql_finish_query)(query_ctx, &inst->config);
break;
case RLM_SQL_QUERY_INVALID:
case RLM_SQL_ERROR:
default:
- rlm_sql_print_error(inst, request, query_ctx->handle, false);
+ rlm_sql_print_error(inst, request, query_ctx, false);
(inst->driver->sql_finish_select_query)(query_ctx, &inst->config);
if (query_ctx->rcode == RLM_SQL_QUERY_INVALID) RETURN_MODULE_INVALID;
RETURN_MODULE_FAIL;