LCOV - code coverage report
Current view: top level - src/dblib/unittests - t0008.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 53 67 79.1 %
Date: 2025-01-18 11:50:39 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* 
       2             :  * Purpose: Test buffering.  As of April 2005, jkl believes this test is broken. 
       3             :  * Functions: dbclrbuf dbsetopt 
       4             :  */
       5             : 
       6             : #include "common.h"
       7             : 
       8             : int
       9           8 : main(int argc, char **argv)
      10             : {
      11           8 :         const int rows_to_add = 48;
      12             :         LOGINREC *login;
      13             :         DBPROCESS *dbproc;
      14             :         int i;
      15             :         char teststr[1024];
      16             :         DBINT testint;
      17           8 :         DBINT last_read = -1;
      18             : 
      19           8 :         set_malloc_options();
      20             : 
      21           8 :         read_login_info(argc, argv);
      22             : 
      23           8 :         printf("Starting %s\n", argv[0]);
      24             : 
      25             :         /* Fortify_EnterScope(); */
      26           8 :         dbinit();
      27             : 
      28           8 :         dberrhandle(syb_err_handler);
      29           8 :         dbmsghandle(syb_msg_handler);
      30             : 
      31           8 :         printf("About to logon\n");
      32             : 
      33           8 :         login = dblogin();
      34           8 :         DBSETLPWD(login, PASSWORD);
      35           8 :         DBSETLUSER(login, USER);
      36           8 :         DBSETLAPP(login, "t0008");
      37           8 :         DBSETLHOST(login, "ntbox.dntis.ro");
      38             : 
      39           8 :         printf("About to open\n");
      40             : 
      41           8 :         dbproc = dbopen(login, SERVER);
      42           8 :         if (strlen(DATABASE))
      43           8 :                 dbuse(dbproc, DATABASE);
      44           8 :         dbloginfree(login);
      45             : 
      46             : #ifdef MICROSOFT_DBLIB
      47             :         dbsetopt(dbproc, DBBUFFER, "25");
      48             : #else
      49           8 :         dbsetopt(dbproc, DBBUFFER, "25", 0);
      50             : #endif
      51             : 
      52           8 :         printf("creating table\n");
      53           8 :         dbcmd(dbproc, "create table #dblib0008 (i int not null, s char(10) not null)");
      54           8 :         dbsqlexec(dbproc);
      55           8 :         while (dbresults(dbproc) != NO_MORE_RESULTS) {
      56             :                 /* nop */
      57             :         }
      58             : 
      59           8 :         printf("insert\n");
      60         392 :         for (i = 1; i <= rows_to_add; i++) {
      61             :         char cmd[1024];
      62             : 
      63         384 :                 sprintf(cmd, "insert into #dblib0008 values (%d, 'row %03d')", i, i);
      64         384 :                 dbcmd(dbproc, cmd);
      65         384 :                 dbsqlexec(dbproc);
      66         384 :                 while (dbresults(dbproc) != NO_MORE_RESULTS) {
      67             :                         /* nop */
      68             :                 }
      69             :         }
      70             : 
      71           8 :         printf("select\n");
      72           8 :         dbcmd(dbproc, "select * from #dblib0008 order by i");
      73           8 :         dbsqlexec(dbproc);
      74             : 
      75           8 :         if (dbresults(dbproc) != SUCCEED) {
      76           0 :                 printf("Was expecting a result set.");
      77           0 :                 exit(1);
      78             :         }
      79             : 
      80          16 :         for (i = 1; i <= dbnumcols(dbproc); i++)
      81          16 :                 printf("col %d is %s\n", i, dbcolname(dbproc, i));
      82             : 
      83           8 :         dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
      84           8 :         dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
      85             : 
      86         392 :         for (i = 1; i <= rows_to_add; i++) {
      87             :         char expected[1024];
      88             : 
      89         384 :                 sprintf(expected, "row %03d", i);
      90             : 
      91         384 :                 if (i % 25 == 0) {
      92           8 :                         dbclrbuf(dbproc, 25);
      93             :                 }
      94             : 
      95         384 :                 if (REG_ROW != dbnextrow(dbproc)) {
      96           0 :                         fprintf(stderr, "dblib failed for %s, dbnextrow1\n", __FILE__);
      97           0 :                         dbexit();
      98           0 :                         return 1;
      99             :                 }
     100         384 :                 last_read = testint;
     101         384 :                 if (testint < 1 || testint > rows_to_add) {
     102           0 :                         fprintf(stderr, "dblib failed for %s testint = %d\n", __FILE__, (int) testint);
     103           0 :                         exit(1);
     104             :                 }
     105         384 :                 if (testint != i) {
     106           0 :                         fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
     107           0 :                         abort();
     108             :                 }
     109         384 :                 if (0 != strncmp(teststr, expected, strlen(expected))) {
     110           0 :                         printf("Failed.  Expected s to be |%s|, was |%s|\n", expected, teststr);
     111           0 :                         abort();
     112             :                 }
     113         384 :                 printf("Read a row of data -> %d %s\n", (int) testint, teststr);
     114             :         }
     115             : 
     116           8 :         if (REG_ROW == dbnextrow(dbproc)) {
     117           0 :                 fprintf(stderr, "dblib failed for %s, dbnextrow2\n", __FILE__);
     118           0 :                 dbexit();
     119           0 :                 return 1;
     120             :         }
     121             : 
     122           8 :         dbexit();
     123             : 
     124           8 :         printf("%s %s (last_read: %d)\n", __FILE__, ((last_read != rows_to_add)? "failed!" : "OK"), (int) last_read);
     125           8 :         return (last_read == rows_to_add) ? 0 : 1;
     126             : }

Generated by: LCOV version 1.13