LCOV - code coverage report
Current view: top level - src/dblib/unittests - canquery.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 32 48 66.7 %
Date: 2024-04-18 20:40:06 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Purpose: Check dbcanquery throw away rows and we can continue after the call
       3             :  * Functions: dbcanquery
       4             :  */
       5             : 
       6             : #include "common.h"
       7             : 
       8             : int
       9           8 : main(int argc, char **argv)
      10             : {
      11             :         LOGINREC *login;
      12             :         DBPROCESS *dbproc;
      13             :         DBINT data;
      14             :         RETCODE erc;
      15             : 
      16           8 :         set_malloc_options();
      17             : 
      18           8 :         read_login_info(argc, argv);
      19             : 
      20           8 :         printf("Starting %s\n", argv[0]);
      21             : 
      22           8 :         dbinit();
      23             : 
      24           8 :         dberrhandle(syb_err_handler);
      25           8 :         dbmsghandle(syb_msg_handler);
      26             : 
      27           8 :         printf("About to logon as \"%s\"\n", USER);
      28             : 
      29           8 :         login = dblogin();
      30           8 :         DBSETLPWD(login, PASSWORD);
      31           8 :         DBSETLUSER(login, USER);
      32           8 :         DBSETLAPP(login, "canquery");
      33             : 
      34           8 :         printf("About to open \"%s\"\n", SERVER);
      35             : 
      36           8 :         dbproc = dbopen(login, SERVER);
      37           8 :         if (!dbproc) {
      38           0 :                 fprintf(stderr, "Unable to connect to %s\n", SERVER);
      39           0 :                 return 1;
      40             :         }
      41           8 :         dbloginfree(login);
      42             : 
      43           8 :         printf("Using database \"%s\"\n", DATABASE);
      44           8 :         if (strlen(DATABASE)) {
      45           8 :                 erc = dbuse(dbproc, DATABASE);
      46           8 :                 assert(erc == SUCCEED);
      47             :         }
      48             : 
      49           8 :         sql_cmd(dbproc);
      50           8 :         dbsqlexec(dbproc);
      51             : 
      52           8 :         if (dbresults(dbproc) != SUCCEED) {
      53           0 :                 fprintf(stderr, "error: expected a result set, none returned.\n");
      54           0 :                 return 1;
      55             :         }
      56             : 
      57           8 :         if (dbcanquery(dbproc) != SUCCEED) {
      58           0 :                 fprintf(stderr, "error: unexpected error from dbcanquery.\n");
      59           0 :                 return 1;
      60             :         }
      61             : 
      62           8 :         if (dbresults(dbproc) != SUCCEED) {
      63           0 :                 fprintf(stderr, "error: expected a result set, none returned.\n");
      64           0 :                 return 1;
      65             :         }
      66             : 
      67           8 :         if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & data)) {
      68           0 :                 fprintf(stderr, "Had problem with bind\n");
      69           0 :                 return 1;
      70             :         }
      71             : 
      72           8 :         if (REG_ROW != dbnextrow(dbproc)) {
      73           0 :                 fprintf(stderr, "Failed.  Expected a row\n");
      74           0 :                 return 1;
      75             :         }
      76             : 
      77           8 :         if (data != 2) {
      78           0 :                 fprintf(stderr, "Failed. Expected row data to be 2, was %d\n", data);
      79           0 :                 return 1;
      80             :         }
      81             : 
      82           8 :         if (dbnextrow(dbproc) != NO_MORE_ROWS) {
      83           0 :                 fprintf(stderr, "Was expecting no more rows\n");
      84           0 :                 return 1;
      85             :         }
      86             : 
      87           8 :         dbclose(dbproc);
      88             : 
      89           8 :         dbexit();
      90           8 :         return 0;
      91             : }

Generated by: LCOV version 1.13