LCOV - code coverage report
Current view: top level - src/dblib/unittests - t0009.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 44 56 78.6 %
Date: 2024-03-23 09:12:27 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /* 
       2             :  * Purpose: Test if dbbind can handle a varlen of 0 with a column bound as STRINGBIND and a database column of CHAR.
       3             :  * Functions: dbbind dbcmd dbnextrow dbnumcols dbopen dbresults dbsqlexec 
       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, "t0009");
      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 :         sql_cmd(dbproc);
      72           8 :         dbsqlexec(dbproc);
      73             : 
      74           8 :         if (dbresults(dbproc) != SUCCEED) {
      75           0 :                 printf("Was expecting a result set.");
      76           0 :                 exit(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           8 :         dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint);
      83           8 :         dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
      84             : 
      85           8 :         if (REG_ROW != dbnextrow(dbproc)) {
      86           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
      87           0 :                 exit(1);
      88             :         }
      89           8 :         if (0 != strcmp("abcdef    ", teststr)) {
      90           0 :                 fprintf(stderr, "Expected |%s|, found |%s|\n", "abcdef", teststr);
      91           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
      92           0 :                 exit(1);
      93             :         }
      94             : 
      95           8 :         if (REG_ROW != dbnextrow(dbproc)) {
      96           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
      97           0 :                 exit(1);
      98             :         }
      99           8 :         if (0 != strcmp("abc       ", teststr)) {
     100           0 :                 fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr);
     101           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
     102           0 :                 exit(1);
     103             :         }
     104             : 
     105           8 :         dbexit();
     106             : 
     107           8 :         printf("dblib passed for %s\n", __FILE__);
     108             :         return 0;
     109             : }

Generated by: LCOV version 1.13