All pastes #289344 Raw Edit

jsmith

public text v1 · immutable
#289344 ·published 2006-12-23 02:12 UTC
rendered paste body
Index: Makefile
===================================================================
--- Makefile	(revision 48923)
+++ Makefile	(working copy)
@@ -78,9 +78,9 @@
 # storage
 #
 # Uncomment to use ODBC storage
-#CFLAGS+=-DUSE_ODBC_STORAGE
+CFLAGS+=-DUSE_ODBC_STORAGE
 # Uncomment for extended ODBC voicemail storage
-#CFLAGS+=-DEXTENDED_ODBC_STORAGE
+CFLAGS+=-DEXTENDED_ODBC_STORAGE
 # See doc/README.odbcstorage for more information
 
 all: $(APPS)
Index: app_voicemail.c
===================================================================
--- app_voicemail.c	(revision 48923)
+++ app_voicemail.c	(working copy)
@@ -848,6 +848,7 @@
 	SQLSMALLINT decimaldigits;
 	SQLSMALLINT nullable;
 	SQLULEN colsize;
+	SQLULEN colsize2;
 	FILE *f=NULL;
 	char rowdata[80];
 	char fn[256];
@@ -927,7 +928,8 @@
 			}
 			if (!strcasecmp(coltitle, "recording")) {
 				off_t offset;
-				res = SQLGetData(stmt, x + 1, SQL_BINARY, NULL, 0, &colsize);
+				res = SQLGetData(stmt, x + 1, SQL_C_BINARY, rowdata, 0, &colsize);
+				ast_log(LOG_NOTICE, "res = %d; colsize = %d\n",res,colsize);
 				fdlen = colsize;
 				if (fd > -1) {
 					char tmp[1]="";
@@ -938,15 +940,19 @@
 						continue;
 					}
 					/* Read out in small chunks */
+					ast_log(LOG_NOTICE, "Proceeding with reading out the data in small chunks\n");
 					for (offset = 0; offset < colsize; offset += CHUNKSIZE) {
-						/* +1 because SQLGetData likes null-terminating binary data */
-						if ((fdm = mmap(NULL, CHUNKSIZE + 1, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == -1) {
+						ast_log(LOG_NOTICE, "Offset = %d\n",offset);
+						if ((fdm = mmap(NULL, CHUNKSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == (void *)-1) {
 							ast_log(LOG_WARNING, "Could not mmap the output file: %s (%d)\n", strerror(errno), errno);
+							/* Do we need this unlink here? I added it because I think we do */
+							unlink(full_fn);
 							SQLFreeHandle(SQL_HANDLE_STMT, stmt);
 							goto yuck;
 						} else {
-							res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, CHUNKSIZE + 1, NULL);
-							munmap(fdm, 0);
+							res = SQLGetData(stmt, x + 1, SQL_C_BINARY, fdm, CHUNKSIZE, &colsize2);
+							ast_log(LOG_NOTICE, "res = %d, colsize2 = \n",res,colsize2);
+							munmap(fdm, CHUNKSIZE);
 							if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
 								ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
 								unlink(full_fn);