LCOV - code coverage report
Current view: top level - src/dblib/unittests - text_buffer.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 49 67 73.1 %
Date: 2025-01-18 12:13:41 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.13