* destructor has access to the module configuration.
*/
handle->inst = inst;
- handle->init = false;
/*
* When something frees this handle the destructor set by
}
exec_trigger(NULL, inst->cs, "modules.sql.open", false);
- handle->init = true;
return handle;
}
*************************************************************************/
int rlm_sql_query(rlm_sql_handle_t **handle, rlm_sql_t *inst, char const *query)
{
- int ret = -1;
+ int ret = RLM_SQL_ERROR;
- /*
- * If there's no query, return an error.
- */
- if (!query || !*query) {
- return -1;
- }
+ /* There's no query to run, return an error */
+ if (!query || (query[0] == '\0')) return RLM_SQL_QUERY_ERROR;
- if (!*handle || !(*handle)->conn) {
- goto sql_down;
- }
+ /* There's no handle, we need a new one */
+ if (!*handle) return RLM_SQL_RECONNECT;
+
+ /* There's a SQL handle but the connection handle has been invalidated */
+ if (!(*handle)->conn) goto sql_down;
while (true) {
DEBUG("rlm_sql (%s): Executing query: '%s'", inst->config->xlat_name, query);
case RLM_SQL_RECONNECT:
sql_down:
*handle = fr_connection_reconnect(inst->pool, *handle);
+ /* Reconnection failed */
if (!*handle) return RLM_SQL_RECONNECT;
+ /* Reconnection succeeded, try again with the new handle */
continue;
case RLM_SQL_QUERY_ERROR:
*************************************************************************/
int rlm_sql_select_query(rlm_sql_handle_t **handle, rlm_sql_t *inst, char const *query)
{
- int ret = -1;
+ int ret = RLM_SQL_ERROR;
- /*
- * If there's no query, return an error.
- */
- if (!query || !*query) return -1;
+ /* There's no query to run, return an error */
+ if (!query || (query[0] == '\0')) return RLM_SQL_QUERY_ERROR;
+
+ /* There's no handle, we need a new one */
+ if (!*handle) return RLM_SQL_RECONNECT;
- if (!*handle || !(*handle)->conn) goto sql_down;
+ /* There's a SQL handle but the connection handle has been invalidated */
+ if (!(*handle)->conn) goto sql_down;
while (true) {
DEBUG("rlm_sql (%s): Executing query: '%s'", inst->config->xlat_name, query);
*/
case RLM_SQL_RECONNECT:
sql_down:
- if (!*handle) return RLM_SQL_RECONNECT;
-
- if (!(*handle)->init) return RLM_SQL_RECONNECT;
-
*handle = fr_connection_reconnect(inst->pool, *handle);
+ /* Reconnection failed */
+ if (!*handle) return RLM_SQL_RECONNECT;
+ /* Reconnection succeeded, try again with the new handle */
continue;
+
case RLM_SQL_QUERY_ERROR:
case RLM_SQL_ERROR:
rlm_sql_query_error(*handle, inst);