Skip to Content.
Sympa Menu

freetds - Re: TDS 7.0 and queries over 512 bytes

freetds AT lists.ibiblio.org

Subject: FreeTDS Development Group

List archive

Chronological Thread  
  • From: "Brandon M. Reynolds" <bmr AT comtime.com>
  • To: TDS Development Group <freetds AT franklin.oit.unc.edu>
  • Subject: Re: TDS 7.0 and queries over 512 bytes
  • Date: Thu, 12 Oct 2000 17:22:05 -0400


Brian Bruns wrote:
>
> Actually, BUFSIZ is used only once in the code which is to do a malloc.
> That needs to be cleaned up but it's not causing any problems.

Well, a little more than once, tds/login.c is probably OK, not sure
about
tds/read.c. What's that stuff under the server directory get used for
anyway?

[w3]freetds> grep -r BUFSIZ *
samples/debug.c:unsigned char buf[BUFSIZ];
samples/debug.c: while ((len = read(fd, buf, BUFSIZ)) > 0) {
src/server/login.c:unsigned char buf[BUFSIZ];
src/server/login.c: tds = tds_alloc_socket(BUFSIZ);
src/server/query.c:static unsigned char query[BUFSIZ];
src/tds/login.c: tds = tds_alloc_socket(BUFSIZ);
src/tds/read.c:unsigned char buf[BUFSIZ];

> I think you've hit on the real problem here:
>
> > + if (tds->out_pos>=8192) {
>
> It appears that TDS 7.0 does not allow multiple query packets!?
>
> I'm guessing if you made the query larger than 8192 bytes this would again
> fail. I'll try to throw a permanent patch together (this one will break
> TDS 4.2 and 5.0) if somebody is willing to test it.

Here's what I changed it to:
- if (tds->out_pos>=512) {
+ if (!IS_TDS70(tds) && tds->out_pos>=512) {

I think SQL Server 7 can't handle queries longer than 8k, but I'm not
sure.

While we're at it there's a couple of other things I'd like added...
1. I changed the dbbuf to be dynamic.

2. In dbbind(), I changed one line to prevent dereferencing a NULL
pointer.

3. I Changed dbsqlexec so that you don't have to do a fetch and make it
fail in
order to not have your program crash!

I have tested these changes for some time and they work for me. I have
programs written in C and PHP.

Notice: these are not acurate diff's because I can't keep up with the
CVS!

--- freetds/include/sybdb.h Sat Oct 7 15:32:32 2000
+++ freetds.good/include/sybdb.h Fri Oct 6 11:28:21 2000
int noautofree;
int more_results; /* boolean. Are we expecting results?
*/
BYTE *user_data; /* see dbsetuserdata() and
dbgetuserdata() */
- unsigned char dbbuf[8192]; /* XXX should be
dynamic */
+ unsigned char *dbbuf; /* is dynamic! */
+ int dbbufsz;
int empty_res_hack;
TDS_INT text_size;
TDS_INT text_sent;
@@ -293,6 +296,7 @@
extern RETCODE dbinit();
extern LOGINREC *dblogin();
extern RETCODE DBSETLPACKET(LOGINREC *login, short packet_size);
+extern RETCODE DBSETLCHARSET(LOGINREC *login, char *charset);
extern RETCODE DBSETLPWD(LOGINREC *login, char *password);
extern RETCODE DBSETLUSER(LOGINREC *login, char *username);
extern RETCODE DBSETLHOST(LOGINREC *login, char *hostname);

--- freetds/src/dblib/dblib.c Sun Oct 8 22:19:09 2000
+++ freetds.good/src/dblib/dblib.c Fri Oct 6 11:30:22 2000
@@ -449,11 +448,13 @@
}

dbproc->tds_socket = (void *) tds_connect(login->tds_login);
- dbproc->dbbuf[0]='\0'; /* initialize query buffer */
+ dbproc->dbbuf = NULL;
+ dbproc->dbbufsz = 0;

RETCODE dbcmd(DBPROCESS *dbproc, char *cmdstring)
{
- /* here is one of those large static buffers that should be
malloced
- ** but in the interest of time i kludged :) */
- strcat(dbproc->dbbuf,cmdstring);
- return SUCCEED;
+ if(dbproc->dbbufsz == 0) {
+ if((dbproc->dbbuf =
+ (unsigned char *)malloc(strlen(cmdstring)+1)) == NULL) {
+ return FAIL;
+ }
+ strcpy(dbproc->dbbuf,cmdstring);
+ dbproc->dbbufsz = strlen(cmdstring) + 1;
+ } else {
+ int newsz;
+ void *p;
+
+ newsz = strlen(cmdstring) + dbproc->dbbufsz;
+ if((p=realloc(dbproc->dbbuf,newsz)) == NULL) {
+ return FAIL;
+ }
+ dbproc->dbbuf = (unsigned char *)p;
+ strcat(dbproc->dbbuf,cmdstring);
+ dbproc->dbbufsz = newsz;
+ }
+
+ return SUCCEED;
}
RETCODE dbsqlexec(DBPROCESS *dbproc)
{
@@ -478,7 +507,9 @@
tds = (TDSSOCKET *) dbproc->tds_socket;
if (!tds || !tds->s) return FAIL;

- if (tds->res_info && tds->res_info->more_results)
+ if (tds->res_info && tds->res_info->more_results || tds->state ==
TDS_PENDING)
/* if (dbproc->more_results &&
tds_is_end_of_results(dbproc->tds_socket)) */
{
dbresults(dbproc);

@@ -833,8 +851,9 @@
tds = (TDSSOCKET *) dbproc->tds_socket;
resinfo = tds->res_info;
}

- okay = okay && ((column >= 1) && (column <= resinfo->num_cols));
+ okay = okay && ((column >= 1) && (column <=
(resinfo?resinfo->num_cols:0)));

if (okay)
{
@@ -1618,7 +1637,13 @@

void dbfreebuf(DBPROCESS *dbproc)
{
- dbproc->dbbuf[0] = '\0';
+ // bmr: 10-06-2000
+ // dbproc->dbbuf[0] = '\0';
+ if(dbproc->dbbuf) {
+ free(dbproc->dbbuf);
+ dbproc->dbbuf = NULL;
+ }
+ dbproc->dbbufsz = 0;
} /* dbfreebuf() */

RETCODE dbclropt(DBPROCESS *dbproc,int option, char *param)
@@ -1895,7 +1920,9 @@
}
if (! dbproc->noautofree)
{
- dbproc->dbbuf[0]='\0';
+ dbfreebuf(dbproc);
}
result = SUCCEED;
}

--
Brandon Reynolds Phone: (330) 644-3059
Systems Engineer Fax: (330) 644-8110
Commercial Timesharing Inc. E-mail: bmr AT comtime.com




Archive powered by MHonArc 2.6.24.

Top of Page