LCOV - code coverage report
Current view: top level - src/dblib/unittests - t0003.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 50 66 75.8 %
Date: 2025-02-21 09:36:06 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.13