[freetds] request to implement dbmorecmds for dblib

Bill Stewart bstewart at verio.net
Wed Apr 30 15:50:32 EDT 2003


James,

Here is the test script for dbmorecmds. I set it up so it was the next 
in sequence in dblib/unittests t0024, hope that's ok. I pasted the 
entire program because I wasn't sure about attachments, plus its small.

I was not able to run it on my system because the underlying command seg 
faults, but the behavior of dbmorecmds should be correct for the given 
queries.

output showing seg fault:
------------------------------------------------------------------------------
(gdb) r
Starting program
/usr/shared/bstewart/freetds-0.62.dev.20030405/src/dblib/unittests/.libs/t0024 

found NTTBOCA.tempdb for nttboca in "../../../PWD"
Start
About to logon
after bread crumb
after dblogin
About to open [Liberty][nttboca]
After second bread crumb

Program received signal SIGSEGV, Segmentation fault.
tds_dstr_copy (s=0x6374652f, src=0x28091f90 "SYBASE") at tdsstring.c:118
118             if (*s != tds_str_empty)
-----------------------------------------------------------------------------
You had given me this version to work with that included the new 
dbmorecmds function:
freetds-0.62.dev.20030405

Let me know what else I might do to get dbmorecmds moving forward.

Thanks again for all your support.

Bill Stewart
NTT/Verio

=========================<start program text>======================
/*
** t0024.c: Test behaviour of dbmorecmds()
**
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */

#include <stdio.h>

#if HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */

#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */

#include <sqlfront.h>
#include <sqldb.h>

/*
** t0024.c: Test behaviour of dbmorecmds()
**
*/
#if HAVE_CONFIG_H
#include <config.h>
#endif /* HAVE_CONFIG_H */

#include <stdio.h>

#if HAVE_STDLIB_H
#include <stdlib.h>
#endif /* HAVE_STDLIB_H */

#if HAVE_STRING_H
#include <string.h>
#endif /* HAVE_STRING_H */

#include <sqlfront.h>
#include <sqldb.h>

#include "common.h"

static char software_version[] = "$Id: t0024.c,v 1.11 2002/11/20 
13:47:06 freddy
77 Exp $";
static void *no_unused_var_warn[] = { software_version, 
no_unused_var_warn };



int failed = 0;


int
main(int argc, char **argv)
{
         const int rows_to_add = 10;
         LOGINREC *login;
         DBPROCESS *dbproc;
         int i, more_count;
         char teststr[1024];
         DBINT testint;

         set_malloc_options();

         read_login_info();
         fprintf(stdout, "Start\n");
         add_bread_crumb();

         /* Fortify_EnterScope(); */
         dbinit();

         add_bread_crumb();
         dberrhandle(syb_err_handler);
         dbmsghandle(syb_msg_handler);

         fprintf(stdout, "About to logon\n");

         add_bread_crumb();

         fprintf(stdout, "after bread crumb\n");

         login = dblogin();
         fprintf(stdout, "after dblogin\n");
         DBSETLPWD(login, PASSWORD);
         DBSETLUSER(login, USER);
         DBSETLAPP(login, "t0024");

         fprintf(stdout, "About to open [%s][%s]\n", PASSWORD, USER);

         add_bread_crumb();

         fprintf(stdout, "After second bread crumb\n");

         dbproc = dbopen(login, SERVER);
         fprintf(stdout, "After dbopen [%s]\n", SERVER);

         if (strlen(DATABASE))
         {
                 fprintf(stdout, "About to dbuse [%s]\n", DATABASE);
                 dbuse(dbproc, DATABASE);
         }

         fprintf(stdout, "After dbuse [%s]\n", DATABASE);
         add_bread_crumb();

         fprintf(stdout, "Dropping table\n");
         add_bread_crumb();
         dbcmd(dbproc, "drop table #dblib0024");
         add_bread_crumb();
         dbsqlexec(dbproc);
         add_bread_crumb();
         while (dbresults(dbproc) != NO_MORE_RESULTS) {
                 /* nop */
         }
         add_bread_crumb();

         fprintf(stdout, "creating table\n");
	dbcmd(dbproc, "create table #dblib0024 (i int not null, s char(10) not 
null)");
         dbsqlexec(dbproc);
         while (dbresults(dbproc) != NO_MORE_RESULTS) {
                 /* nop */
         }

         fprintf(stdout, "insert\n");
         for (i = 0; i < rows_to_add; i++) {
         char cmd[1024];

                 sprintf(cmd, "insert into #dblib0024 values (%d, 'row 
%03d')", i, i);
                 fprintf(stdout, "%s\n", cmd);
                 dbcmd(dbproc, cmd);
                 dbsqlexec(dbproc);
                 while (dbresults(dbproc) != NO_MORE_RESULTS) {
                         /* nop */
                 }
         }

         fprintf(stdout, "select 1\n");
         dbcmd(dbproc, "select count(*) from #dblib0024 order by i");
         dbsqlexec(dbproc);
         add_bread_crumb();

         more_count = 0;

         while(dbmorecmds(dbproc)) {
                 more_count++;
                 dbresults(dbproc);
         }

         /* dbmorecmds should return success 0 times for select 1 */
         if (more_count != 0) {
                 add_bread_crumb();
                 failed = 1;
                 fprintf(stdout, "Was expecting more_count = 0.");
                 exit(1);
         }

         dbcancel(dbproc);

         fprintf(stdout, "select 2\n");
         dbcmd(dbproc, "if exists (select i from #dblib0024 where i=1) 
begin select count(*) from #dblib0024 end\n");
         dbsqlexec(dbproc);

         more_count = 0;

         while(dbmorecmds(dbproc)) {
                 more_count++;
                 dbresults(dbproc);
     }

         /* dbmorecmds should return success 2 times for select 2 */
         if (more_count != 2) {
                 add_bread_crumb();
                 failed = 1;
                 fprintf(stdout, "Was expecting more_count = 2.");
                 exit(1);
         }

         /* end of test processing */

         add_bread_crumb();
         dbexit();
         add_bread_crumb();

         fprintf(stdout, "dblib %s on %s\n", (failed ? "failed!" : 
"okay"), __FILE__);
         return failed ? 1 : 0;
}
=========================<end program text>======================

Bill Stewart wrote:
> James,
> 
> <snip>
> 
>>>> The most helpful thing you could do would be to write a 
>>>
>>> simple dbmorecmds.c
>>>
>>>> for the dblib/unittest directory.  
>>>
> 
> I'm working on the test case for dbmorecmds now, in my spare time. :)
> I will hopefully get it to you fairly soon so we can move forward on 
> debugging this.
> 
> <snip>
> 
> Thanks,
> Bill
> 
> _______________________________________________
> FreeTDS mailing list
> FreeTDS at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/freetds
> 
> 




More information about the FreeTDS mailing list