[Asterisk-cvs] asterisk/res res_config_odbc.c, 1.30, 1.31 res_odbc.c, 1.22, 1.23

kpfleming kpfleming
Mon Oct 31 16:39:20 CST 2005


Update of /usr/cvsroot/asterisk/res
In directory mongoose.digium.com:/tmp/cvs-serv5398/res

Modified Files:
	res_config_odbc.c res_odbc.c 
Log Message:
don't use 'rowcount' after SELECT statements, since the ODBC API does not say it is allowed (issue #5083)


Index: res_config_odbc.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_config_odbc.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- res_config_odbc.c	24 Oct 2005 20:12:06 -0000	1.30
+++ res_config_odbc.c	31 Oct 2005 21:31:25 -0000	1.31
@@ -64,7 +64,6 @@
 	int res;
 	int x;
 	struct ast_variable *var=NULL, *prev=NULL;
-	SQLLEN rowcount=0;
 	SQLULEN colsize;
 	SQLSMALLINT colcount=0;
 	SQLSMALLINT datatype;
@@ -126,62 +125,57 @@
 		return NULL;
 	}
 
-	res = SQLRowCount(stmt, &rowcount);
+	res = SQLNumResultCols(stmt, &colcount);
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-		ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
+		ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 		return NULL;
 	}
 
-	res = SQLNumResultCols(stmt, &colcount);
+	res = SQLFetch(stmt);
+	if (res == SQL_NO_DATA) {
+		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+                return NULL;
+	}
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-		ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
+		ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 		return NULL;
 	}
-
-	if (rowcount) {
-		res = SQLFetch(stmt);
+	for (x=0;x<colcount;x++) {
+		rowdata[0] = '\0';
+		collen = sizeof(coltitle);
+		res = SQLDescribeCol(stmt, x + 1, coltitle, sizeof(coltitle), &collen, 
+					&datatype, &colsize, &decimaldigits, &nullable);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-			ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+			ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
+			if (var)
+				ast_variables_destroy(var);
 			return NULL;
 		}
-		for (x=0;x<colcount;x++) {
-			rowdata[0] = '\0';
-			collen = sizeof(coltitle);
-			res = SQLDescribeCol(stmt, x + 1, coltitle, sizeof(coltitle), &collen, 
-						&datatype, &colsize, &decimaldigits, &nullable);
-			if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-				ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
-				if (var)
-					ast_variables_destroy(var);
-				return NULL;
-			}
 
-			indicator = 0;
-			res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), &indicator);
-			if (indicator == SQL_NULL_DATA)
-				continue;
+		indicator = 0;
+		res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), &indicator);
+		if (indicator == SQL_NULL_DATA)
+			continue;
 
-			if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-				ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
-				if (var)
-					ast_variables_destroy(var);
-				return NULL;
-			}
-			stringp = rowdata;
-			while(stringp) {
-				chunk = strsep(&stringp, ";");
-				if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
-					if (prev) {
-						prev->next = ast_variable_new(coltitle, chunk);
-						if (prev->next)
-							prev = prev->next;
+		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+			ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
+			if (var)
+				ast_variables_destroy(var);
+			return NULL;
+		}
+		stringp = rowdata;
+		while(stringp) {
+			chunk = strsep(&stringp, ";");
+			if (chunk && !ast_strlen_zero(ast_strip(chunk))) {
+				if (prev) {
+					prev->next = ast_variable_new(coltitle, chunk);
+					if (prev->next)
+						prev = prev->next;
 					} else 
 						prev = var = ast_variable_new(coltitle, chunk);
 					
-				}
 			}
 		}
 	}
@@ -210,7 +204,6 @@
 	struct ast_config *cfg=NULL;
 	struct ast_category *cat=NULL;
 	struct ast_realloca ra;
-	SQLLEN rowcount=0;
 	SQLULEN colsize;
 	SQLSMALLINT colcount=0;
 	SQLSMALLINT datatype;
@@ -278,13 +271,6 @@
 		return NULL;
 	}
 
-	res = SQLRowCount(stmt, &rowcount);
-	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-		ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-		return NULL;
-	}
-
 	res = SQLNumResultCols(stmt, &colcount);
 	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 		ast_log(LOG_WARNING, "SQL Column Count error!\n[%s]\n\n", sql);
@@ -299,9 +285,8 @@
 		return NULL;
 	}
 
-	while (rowcount--) {
+	while ((res=SQLFetch(stmt)) != SQL_NO_DATA) {
 		var = NULL;
-		res = SQLFetch(stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 			ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
 			continue;

Index: res_odbc.c
===================================================================
RCS file: /usr/cvsroot/asterisk/res/res_odbc.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -d -r1.22 -r1.23
--- res_odbc.c	26 Oct 2005 23:11:36 -0000	1.22
+++ res_odbc.c	31 Oct 2005 21:31:25 -0000	1.23
@@ -110,7 +110,7 @@
 {
 	int res = 0;
 	res = SQLExecute(stmt);
-	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+	if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO) && (res != SQL_NO_DATA)) {
 		ast_log(LOG_WARNING, "SQL Execute error! Attempting a reconnect...\n");
 		ast_mutex_lock(&obj->lock);
 		obj->up = 0;
@@ -147,7 +147,6 @@
 	char *test_sql = "select 1";
 	SQLHSTMT stmt;
 	int res = 0;
-	SQLLEN rowcount = 0;
 
 	ast_mutex_lock(&obj->lock);
 	if(obj->up) { /* so you say... let's make sure */
@@ -162,11 +161,6 @@
 				res = SQLExecute(stmt);
 				if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 					obj->up = 0; /* Liar!*/
-				} else {
-					res = SQLRowCount(stmt, &rowcount);
-					if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-						obj->up = 0; /* Liar!*/
-					}
 				}
 			}
 		}




More information about the svn-commits mailing list