LCOV - code coverage report
Current view: top level - src/dblib/unittests - t0009.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 45 57 78.9 %
Date: 2025-05-09 15:42:11 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          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, "t0009");
      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 :         sql_cmd(dbproc);
      71          10 :         dbsqlexec(dbproc);
      72             : 
      73          10 :         if (dbresults(dbproc) != SUCCEED) {
      74           0 :                 printf("Was expecting a result set.");
      75           0 :                 exit(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          10 :         dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint);
      82          10 :         dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
      83             : 
      84          10 :         if (REG_ROW != dbnextrow(dbproc)) {
      85           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
      86           0 :                 exit(1);
      87             :         }
      88          10 :         if (0 != strcmp("abcdef    ", teststr)) {
      89           0 :                 fprintf(stderr, "Expected |%s|, found |%s|\n", "abcdef", teststr);
      90           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
      91           0 :                 exit(1);
      92             :         }
      93             : 
      94          10 :         if (REG_ROW != dbnextrow(dbproc)) {
      95           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
      96           0 :                 exit(1);
      97             :         }
      98          10 :         if (0 != strcmp("abc       ", teststr)) {
      99           0 :                 fprintf(stderr, "Expected |%s|, found |%s|\n", "abc", teststr);
     100           0 :                 fprintf(stderr, "dblib failed for %s\n", __FILE__);
     101           0 :                 exit(1);
     102             :         }
     103             : 
     104          10 :         dbexit();
     105             : 
     106          10 :         printf("dblib passed for %s\n", __FILE__);
     107          10 :         return 0;
     108             : }

Generated by: LCOV version 1.13