[Asterisk-cvs] asterisk/apps app_voicemail.c,1.255,1.256

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


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

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


Index: app_voicemail.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_voicemail.c,v
retrieving revision 1.255
retrieving revision 1.256
diff -u -d -r1.255 -r1.256
--- app_voicemail.c	26 Oct 2005 19:48:14 -0000	1.255
+++ app_voicemail.c	31 Oct 2005 21:31:24 -0000	1.256
@@ -752,7 +752,6 @@
 	int fd=-1;
 	size_t fdlen = 0;
 	void *fdm=NULL;
-	SQLLEN rowcount=0;
 	SQLSMALLINT colcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
@@ -807,79 +806,74 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		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);
+		res = SQLFetch(stmt);
+		if (res == SQL_NO_DATA) {
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		if (rowcount) {
-			fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC);
-			if (fd < 0) {
-				ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
-				SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-				goto yuck;
-			}
-			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);
-				SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-				goto yuck;
-			}
-			res = SQLFetch(stmt);
+		else 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);
+			goto yuck;
+		}
+		fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC);
+		if (fd < 0) {
+			ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
+			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+			goto yuck;
+		}
+		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);
+			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+			goto yuck;
+		}
+		if (f) 
+			fprintf(f, "[message]\n");
+		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);
+				ast_log(LOG_WARNING, "SQL Describe Column error!\n[%s]\n\n", sql);
 				SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 				goto yuck;
 			}
-			if (f) 
-				fprintf(f, "[message]\n");
-			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);
-					SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-					goto yuck;
-				}
-				if (!strcmp(coltitle, "recording")) {
-					res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
-					fdlen = colsize;
-					fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770);
-					if (fd > -1) {
-						char tmp[1]="";
-						lseek(fd, fdlen - 1, SEEK_SET);
-						if (write(fd, tmp, 1) != 1) {
-							close(fd);
-							fd = -1;
-						}
-						if (fd > -1)
-							fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
-					}
-					if (fdm) {
-						memset(fdm, 0, fdlen);
-						res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
-						if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
-							ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
-							SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-							goto yuck;
-						}
+			if (!strcasecmp(coltitle, "recording")) {
+				res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
+				fdlen = colsize;
+				fd = open(full_fn, O_RDWR | O_TRUNC | O_CREAT, 0770);
+				if (fd > -1) {
+					char tmp[1]="";
+					lseek(fd, fdlen - 1, SEEK_SET);
+					if (write(fd, tmp, 1) != 1) {
+						close(fd);
+						fd = -1;
 					}
-				} else {
-					res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
+					if (fd > -1)
+						fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+				}
+				if (fdm) {
+					memset(fdm, 0, fdlen);
+					res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
 					if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 						ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
 						SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 						goto yuck;
 					}
-					if (strcmp(coltitle, "msgnum") && strcmp(coltitle, "dir") && f)
-						fprintf(f, "%s=%s\n", coltitle, rowdata);
 				}
+			} else {
+				res = SQLGetData(stmt, x + 1, SQL_CHAR, rowdata, sizeof(rowdata), NULL);
+				if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
+					ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
+					SQLFreeHandle (SQL_HANDLE_STMT, stmt);
+					goto yuck;
+				}
+				if (strcasecmp(coltitle, "msgnum") && strcasecmp(coltitle, "dir") && f)
+					fprintf(f, "%s=%s\n", coltitle, rowdata);
 			}
-		} else if (msgnum > -1) /* msgnum will be -1 if the message hasn't yet been saved */
-			ast_log(LOG_WARNING, "Failed to retrieve rows for msgnum=%s and dir=%s\n", msgnums, dir);
+		}
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 	} else
 		ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -914,7 +908,6 @@
 {
 	int x = 0;
 	int res;
-	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
 	char rowdata[20];
@@ -941,12 +934,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		res = SQLRowCount(stmt, &rowcount);
-		if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-			ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			goto yuck;
-		}
 		res = SQLFetch(stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 			ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -972,7 +959,6 @@
 {
 	int x = 0;
 	int res;
-	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
 	char rowdata[20];
@@ -1002,12 +988,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		res = SQLRowCount(stmt, &rowcount);
-		if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-			ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			goto yuck;
-		}
 		res = SQLFetch(stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 			ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -1037,7 +1017,6 @@
 static void delete_file(char *sdir, int smsg)
 {
 	int res;
-	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
 	char msgnums[20];
@@ -1066,12 +1045,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		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);
-			goto yuck;
-		}
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 	} else
 		ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1082,7 +1055,6 @@
 static void copy_file(char *sdir, int smsg, char *ddir, int dmsg, char *dmailboxuser, char *dmailboxcontext)
 {
 	int res;
-	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
 	char msgnums[20];
@@ -1127,12 +1099,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		res = SQLRowCount(stmt, &rowcount);
-		if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-			ast_log(LOG_WARNING, "SQL Row Count error!\n[%s] (You probably don't have MySQL 4.1 or later installed)\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			goto yuck;
-		}
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 	} else
 		ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1147,7 +1113,6 @@
 	int fd = -1;
 	void *fdm=NULL;
 	size_t fdlen = -1;
-	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	SQLINTEGER len;
 	char sql[256];
@@ -1252,12 +1217,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		res = SQLRowCount(stmt, &rowcount);
-		if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-			ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			goto yuck;
-		}
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 	} else
 		ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1274,7 +1233,6 @@
 static void rename_file(char *sdir, int smsg, char *mailboxuser, char *mailboxcontext, char *ddir, int dmsg)
 {
 	int res;
-	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
 	char msgnums[20];
@@ -1319,12 +1277,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		res = SQLRowCount(stmt, &rowcount);
-		if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-			ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			goto yuck;
-		}
 		SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 	} else
 		ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
@@ -1974,7 +1926,6 @@
 {
 	int x = 0;
 	int res;
-	SQLLEN rowcount=0;
 	SQLHSTMT stmt;
 	char sql[256];
 	char rowdata[20];
@@ -2019,12 +1970,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		res = SQLRowCount(stmt, &rowcount);
-		if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-			ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			goto yuck;
-		}
 		res = SQLFetch(stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 			ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -2058,12 +2003,6 @@
 			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
 			goto yuck;
 		}
-		res = SQLRowCount(stmt, &rowcount);
-		if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-			ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-			SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-			goto yuck;
-		}
 		res = SQLFetch(stmt);
 		if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 			ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
@@ -2090,7 +2029,6 @@
 {
 	int nummsgs = 0;
         int res;
-        SQLLEN rowcount=0;
         SQLHSTMT stmt;
         char sql[256];
         char rowdata[20];
@@ -2132,12 +2070,6 @@
                         SQLFreeHandle (SQL_HANDLE_STMT, stmt);
                         goto yuck;
                 }
-                res = SQLRowCount(stmt, &rowcount);
-                if (((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) || (rowcount < 1)) {
-                        ast_log(LOG_WARNING, "SQL Row Count error!\n[%s]\n\n", sql);
-                        SQLFreeHandle (SQL_HANDLE_STMT, stmt);
-                        goto yuck;
-                }
                 res = SQLFetch(stmt);
                 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
                         ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);




More information about the svn-commits mailing list