LCOV - code coverage report
Current view: top level - src/dblib/unittests - t0011.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 52 65 80.0 %
Date: 2025-04-25 08:22:23 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* 
       2             :  * Purpose: Test binding of string types
       3             :  * Functions: dbbind dbcmd dbcolname dbnextrow dbnumcols dbopen dbresults dbsqlexec 
       4             : 
       5             :  */
       6             : 
       7             : #include "common.h"
       8             : 
       9             : static int failed = 0;
      10             : 
      11             : static void insert_row(DBPROCESS * dbproc);
      12             : static int select_rows(DBPROCESS * dbproc, int bind_type);
      13             : 
      14          10 : TEST_MAIN()
      15             : {
      16             :         LOGINREC *login;
      17             :         DBPROCESS *dbproc;
      18             : 
      19          10 :         read_login_info(argc, argv);
      20          10 :         printf("Starting %s\n", argv[0]);
      21             : 
      22          10 :         dbinit();
      23             : 
      24          10 :         printf("About to logon\n");
      25             : 
      26          10 :         login = dblogin();
      27          10 :         DBSETLPWD(login, PASSWORD);
      28          10 :         DBSETLUSER(login, USER);
      29          10 :         DBSETLAPP(login, "t0011");
      30             : 
      31          10 :         printf("About to open\n");
      32             : 
      33          10 :         dbproc = dbopen(login, SERVER);
      34          10 :         if (strlen(DATABASE))
      35          10 :                 dbuse(dbproc, DATABASE);
      36          10 :         dbloginfree(login);
      37             : 
      38          10 :         printf("Dropping table\n");
      39          10 :         sql_cmd(dbproc);
      40          10 :         dbsqlexec(dbproc);
      41          10 :         while (dbresults(dbproc) != NO_MORE_RESULTS) {
      42             :                 /* nop */
      43             :         }
      44             : 
      45          10 :         printf("creating table\n");
      46          10 :         sql_cmd(dbproc);
      47          10 :         dbsqlexec(dbproc);
      48          10 :         while (dbresults(dbproc) != NO_MORE_RESULTS) {
      49             :                 /* nop */
      50             :         }
      51             : 
      52          10 :         printf("insert\n");
      53             : 
      54          10 :         insert_row(dbproc);
      55          10 :         insert_row(dbproc);
      56          10 :         insert_row(dbproc);
      57             : 
      58          10 :         failed = select_rows(dbproc, STRINGBIND);
      59             : 
      60          10 :         dbexit();
      61             : 
      62          10 :         printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
      63          10 :         return failed ? 1 : 0;
      64             : }
      65             : 
      66             : static int
      67          10 : select_rows(DBPROCESS * dbproc, int bind_type)
      68             : {
      69             :         char teststr[1024];
      70             :         char teststr2[1024];
      71             :         char testvstr[1024];
      72             :         DBINT testint;
      73             :         DBINT i;
      74             : 
      75             : 
      76          10 :         printf("select\n");
      77          10 :         sql_cmd(dbproc);
      78          10 :         dbsqlexec(dbproc);
      79             : 
      80             : 
      81          10 :         if (dbresults(dbproc) != SUCCEED) {
      82           0 :                 failed = 1;
      83           0 :                 printf("Was expecting a result set.");
      84           0 :                 exit(1);
      85             :         }
      86             : 
      87          40 :         for (i = 1; i <= dbnumcols(dbproc); i++) {
      88          40 :                 printf("col %d is %s\n", i, dbcolname(dbproc, i));
      89             :         }
      90             : 
      91          10 :         if (SUCCEED != dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint)) {
      92           0 :                 fprintf(stderr, "Had problem with bind\n");
      93           0 :                 return 1;
      94             :         }
      95          10 :         if (SUCCEED != dbbind(dbproc, 2, bind_type, 0, (BYTE *) teststr)) {
      96           0 :                 fprintf(stderr, "Had problem with bind\n");
      97           0 :                 return 1;
      98             :         }
      99          10 :         if (SUCCEED != dbbind(dbproc, 3, bind_type, 0, (BYTE *) teststr2)) {
     100           0 :                 fprintf(stderr, "Had problem with bind\n");
     101           0 :                 return 1;
     102             :         }
     103          10 :         if (SUCCEED != dbbind(dbproc, 4, bind_type, 0, (BYTE *) testvstr)) {
     104           0 :                 fprintf(stderr, "Had problem with bind\n");
     105           0 :                 return 1;
     106             :         }
     107             : 
     108             :         i = 0;
     109          40 :         while (dbnextrow(dbproc) == REG_ROW) {
     110          30 :                 i++;
     111          30 :                 if (testint != i) {
     112           0 :                         printf("Failed.  Expected i to be |%d|, was |%d|\n", testint, i);
     113           0 :                         return 1;
     114             :                 }
     115          30 :                 printf("c:  %s$\n", teststr);
     116          30 :                 printf("c2: %s$\n", teststr2);
     117          30 :                 printf("vc: %s$\n", testvstr);
     118             :                 if (bind_type == STRINGBIND) {
     119             :                 } else {
     120             :                 }
     121             :         }
     122             :         return 0;
     123             : }
     124             : 
     125             : static void
     126          30 : insert_row(DBPROCESS * dbproc)
     127             : {
     128          30 :         sql_cmd(dbproc);
     129          30 :         dbsqlexec(dbproc);
     130          30 :         while (dbresults(dbproc) != NO_MORE_RESULTS) {
     131             :                 /* nop */
     132             :         }
     133          30 : }

Generated by: LCOV version 1.13