[asterisk-commits] tilghman: trunk r82393 - in /trunk: include/asterisk/res_odbc.h res/res_odbc.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 14 12:29:24 CDT 2007


Author: tilghman
Date: Fri Sep 14 12:29:23 2007
New Revision: 82393

URL: http://svn.digium.com/view/asterisk?view=rev&rev=82393
Log:
Add a direct execute method to res_odbc (closes issue #10722)

Modified:
    trunk/include/asterisk/res_odbc.h
    trunk/res/res_odbc.c

Modified: trunk/include/asterisk/res_odbc.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/res_odbc.h?view=diff&rev=82393&r1=82392&r2=82393
==============================================================================
--- trunk/include/asterisk/res_odbc.h (original)
+++ trunk/include/asterisk/res_odbc.h Fri Sep 14 12:29:23 2007
@@ -93,6 +93,16 @@
  */
 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

Modified: trunk/res/res_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/res/res_odbc.c?view=diff&rev=82393&r1=82392&r2=82393
==============================================================================
--- trunk/res/res_odbc.c (original)
+++ trunk/res/res_odbc.c Fri Sep 14 12:29:23 2007
@@ -76,6 +76,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)
 {




More information about the asterisk-commits mailing list