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

Generated by: LCOV version 1.13