From bc494164c8896a13b3ac49e87757e51fd02cb23c Mon Sep 17 00:00:00 2001 From: Tilghman Lesher <tilghman@meg.abyt.es> Date: Fri, 14 Sep 2007 17:29:23 +0000 Subject: [PATCH] Add a direct execute method to res_odbc (closes issue #10722) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@82393 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/res_odbc.h | 10 ++++++++++ res/res_odbc.c | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/asterisk/res_odbc.h b/include/asterisk/res_odbc.h index 1018eef2d0..821b64f283 100644 --- a/include/asterisk/res_odbc.h +++ b/include/asterisk/res_odbc.h @@ -93,6 +93,16 @@ void ast_odbc_release_obj(struct odbc_obj *obj); */ int ast_odbc_sanity_check(struct odbc_obj *obj); +/*! \brief Executes an non prepared statement and returns the resulting + * statement handle. + * \param obj The ODBC object + * \param exec_cb A function callback, which, when called, should return a statement handle with result columns bound. + * \param data A parameter to be passed to the exec_cb parameter function, indicating which statement handle is to be prepared. + * \retval a statement handle + * \retval NULL on error + */ +SQLHSTMT ast_odbc_direct_execute(struct odbc_obj *obj, SQLHSTMT (*exec_cb)(struct odbc_obj *obj, void *data), void *data); + /*! * \brief Prepares, executes, and returns the resulting statement handle. * \param obj The ODBC object diff --git a/res/res_odbc.c b/res/res_odbc.c index c9d3ee700c..2fd4c02cf3 100644 --- a/res/res_odbc.c +++ b/res/res_odbc.c @@ -77,6 +77,28 @@ static odbc_status odbc_obj_disconnect(struct odbc_obj *obj); static int odbc_register_class(struct odbc_class *class, int connect); +SQLHSTMT ast_odbc_direct_execute(struct odbc_obj *obj, SQLHSTMT (*exec_cb)(struct odbc_obj *obj, void *data), void *data) +{ + int attempt; + SQLHSTMT stmt; + + for (attempt = 0; attempt < 2; attempt++) { + stmt = exec_cb(obj, data); + + if (stmt) { + break; + } else { + obj->up = 0; + ast_log(LOG_WARNING, "SQL Exec Direct failed. Attempting a reconnect...\n"); + + odbc_obj_disconnect(obj); + odbc_obj_connect(obj); + } + } + + return stmt; +} + SQLHSTMT ast_odbc_prepare_and_execute(struct odbc_obj *obj, SQLHSTMT (*prepare_cb)(struct odbc_obj *obj, void *data), void *data) { int res = 0, i, attempt; -- GitLab