res_config_odbc: Prevent Realtime fallback on record-not-found (SQL_NO_DATA)

This patch fixes an issue in the ODBC Realtime engine where Asterisk incorrectly
falls back to the next configured backend when the current one returns
SQL_NO_DATA (i.e., no record found).
This is a logical error and performance risk in multi-backend configurations.

Solution:
Introduced CONFIG_RT_NOT_FOUND ((void *)-1) as a special return marker.
ODBC Realtime backend now return CONFIG_RT_NOT_FOUND when no data is found.
Core engine stops iterating on this marker, avoiding unnecessary fallback.

Notes:
Other Realtime backends (PostgreSQL, LDAP, etc.) can be updated similarly.
This patch only covers ODBC.

Fixes: #1305
This commit is contained in:
Alexei Gradinari
2025-07-15 17:56:39 -04:00
parent 0ba07ac7c3
commit 9e3ea1c8ac
3 changed files with 27 additions and 4 deletions

View File

@@ -126,6 +126,12 @@ typedef int realtime_require(const char *database, const char *table, va_list ap
*/
typedef int realtime_unload(const char *database, const char *table);
/*! Special return value indicating a successful query that returned no data.
* Used by realtime backends to signal "not found" vs an actual backend failure.
* This allows the core engine to differentiate and avoid unnecessary failover.
*/
#define CONFIG_RT_NOT_FOUND (void *)-1
/*! \brief Configuration engine structure, used to define realtime drivers */
struct ast_config_engine {
char *name;