I am trying to write a customized app using C that would fetch voice file from SQL Server 2000 using ODBC and FREETDS. Currently I am only able to fetch first 63 KB chunk from the DB, and not able to fetch the rest of the file, below is the code that i am using to do so, fd = open(fullpath, O_RDWR | O_CREAT | O_TRUNC, 0770); if (fd < 0) { ast_log(LOG_WARNING, "Failed to write '%s': %s\n", fullpath, strerror(errno)); res = -1; goto free_res; } res = SQLGetData(stmt, 1, SQL_BINARY, empty, 0, &colsize); fdlen = colsize; if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "COLSIZE = %d", colsize); //PRINTING COLSIZE ON CLI if (fd > -1) { char tmp[1]=""; lseek(fd, fdlen - 1, SEEK_SET); if (write(fd, tmp, 1) != 1) { close(fd); res = -1; goto free_res; } } if (fd > -1){ //Trying to fetch data in chunks for (offset = 0; offset < colsize; offset += CHUNKSIZE) { if ((fdm = mmap(NULL, CHUNKSIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, offset)) == MAP_FAILED) { ast_log(LOG_WARNING, "Could not mmap the output file: %s (%d)\n", strerror(errno), errno); goto free_res; } else { res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, CHUNKSIZE, NULL); 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(fullpath); goto free_res; } } } } close(fd); SQLFreeHandle(SQL_HANDLE_STMT, stmt); The value of colsize printed on CLI is 64512, Is there some limitation somewhere in FREETDS or ODBC. Can anyone please help me to get this fixed? Regards, Sanjay Rajdev -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.digium.com/pipermail/asterisk-users/attachments/20080517/b1928701/attachment.htm
Tilghman Lesher
2008-May-16 22:27 UTC
[asterisk-users] Fetching Binary data from SQL Server
On Friday 16 May 2008 16:10:22 Sanjay Rajdev wrote:> I am trying to write a customized app using C that would fetch voice file > from SQL Server 2000 using ODBC and FREETDS. > > Currently I am only able to fetch first 63 KB chunk from the DB, and not > able to fetch the rest of the file, below is the code that i am using to do > so, > > //Trying to fetch data in chunks > for (offset = 0; offset < colsize; offset += CHUNKSIZE) {What is your value of CHUNKSIZE? -- Tilghman
Tilghman Lesher
2008-May-16 22:39 UTC
[asterisk-users] Fetching Binary data from SQL Server
On Friday 16 May 2008 16:10:22 Sanjay Rajdev wrote:> I am trying to write a customized app using C that would fetch voice file > from SQL Server 2000 using ODBC and FREETDS. > > Currently I am only able to fetch first 63 KB chunk from the DB, and not > able to fetch the rest of the file, below is the code that i am using to do > so,Actually, if you Google, you'll find that in freetds.conf, the default 'text size' parameter is set to exactly 64512, which is the limit that FreeTDS itself is placing on the data. You might try increasing that (to a maximum of 2GB) and see if that works better for you. -- Tilghman