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

Generated by: LCOV version 1.13