[svn-commits] tilghman: trunk r107722 - /trunk/cdr/cdr_odbc.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Mar 11 16:10:45 CDT 2008


Author: tilghman
Date: Tue Mar 11 16:10:45 2008
New Revision: 107722

URL: http://svn.digium.com/view/asterisk?view=rev&rev=107722
Log:
Convert prepare_and_execute to direct_execute for speed
(closes issue #11935)
 Reported by: falves11
 Patches: 
       20080208__bug11935.diff.txt uploaded by Corydon76 (license 14)
 Tested by: falves11, Corydon76

Modified:
    trunk/cdr/cdr_odbc.c

Modified: trunk/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/trunk/cdr/cdr_odbc.c?view=diff&rev=107722&r1=107721&r2=107722
==============================================================================
--- trunk/cdr/cdr_odbc.c (original)
+++ trunk/cdr/cdr_odbc.c Tue Mar 11 16:10:45 2008
@@ -59,7 +59,7 @@
 
 static struct ast_flags config = { 0 };
 
-static SQLHSTMT prepare_cb(struct odbc_obj *obj, void *data)
+static SQLHSTMT execute_cb(struct odbc_obj *obj, void *data)
 {
 	struct ast_cdr *cdr = data;
 	SQLRETURN ODBC_res;
@@ -86,14 +86,6 @@
 
 	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
 		ast_verb(11, "cdr_odbc: Failure in AllocStatement %d\n", ODBC_res);
-		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
-		return NULL;
-	}
-
-	ODBC_res = SQLPrepare(stmt, (unsigned char *)sqlcmd, SQL_NTS);
-	
-	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
-		ast_verb(11, "cdr_odbc: Error in PREPARE %d\n", ODBC_res);
 		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 		return NULL;
 	}
@@ -120,6 +112,14 @@
 		SQLBindParameter(stmt, 15, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, sizeof(cdr->userfield), 0, cdr->userfield, 0, NULL);
 	}
 
+	ODBC_res = SQLExecDirect(stmt, (unsigned char *)sqlcmd, SQL_NTS);
+	
+	if ((ODBC_res != SQL_SUCCESS) && (ODBC_res != SQL_SUCCESS_WITH_INFO)) {
+		ast_verb(11, "cdr_odbc: Error in ExecDirect: %d\n", ODBC_res);
+		SQLFreeHandle(SQL_HANDLE_STMT, stmt);
+		return NULL;
+	}
+
 	return stmt;
 }
 
@@ -134,7 +134,7 @@
 		return -1;
 	}
 
-	stmt = ast_odbc_prepare_and_execute(obj, prepare_cb, cdr);
+	stmt = ast_odbc_direct_execute(obj, execute_cb, cdr);
 	if (stmt) {
 		SQLLEN rows = 0;
 
@@ -144,7 +144,7 @@
 		if (rows == 0)
 			ast_log(LOG_WARNING, "CDR successfully ran, but inserted 0 rows?\n");
 	} else
-		ast_log(LOG_ERROR, "CDR prepare or execute failed\n");
+		ast_log(LOG_ERROR, "CDR direct execute failed\n");
 	ast_odbc_release_obj(obj);
 	return 0;
 }




More information about the svn-commits mailing list