LCOV - code coverage report
Current view: top level - src/dblib/unittests - cancel.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 35 44 79.5 %
Date: 2025-02-21 09:36:06 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Purpose: Test we can cancel a query inside message handler
       3             :  * Some server some additional tokens which can prevent second query to work
       4             :  * correctly.
       5             :  */
       6             : 
       7             : #include "common.h"
       8             : 
       9             : static int
      10          10 : cancel_msg_handler(DBPROCESS * dbproc, DBINT msgno TDS_UNUSED, int msgstate TDS_UNUSED, int severity TDS_UNUSED,
      11             :                    char *msgtext TDS_UNUSED, char *srvname TDS_UNUSED, char *procname TDS_UNUSED, int line TDS_UNUSED)
      12             : {
      13          10 :         dbcancel(dbproc);
      14          10 :         return 0;
      15             : }
      16             : 
      17             : int
      18          10 : main(int argc, char **argv)
      19             : {
      20             :         LOGINREC *login;
      21             :         DBPROCESS *dbproc;
      22             :         int i;
      23          10 :         DBINT testint = -1;
      24             : 
      25          10 :         read_login_info(argc, argv);
      26             : 
      27          10 :         printf("Starting %s\n", argv[0]);
      28             : 
      29          10 :         dbinit();
      30             : 
      31          10 :         dberrhandle(syb_err_handler);
      32          10 :         dbmsghandle(syb_msg_handler);
      33             : 
      34          10 :         printf("About to logon\n");
      35             : 
      36          10 :         login = dblogin();
      37          10 :         DBSETLPWD(login, PASSWORD);
      38          10 :         DBSETLUSER(login, USER);
      39          10 :         DBSETLAPP(login, "cancel");
      40             : 
      41          10 :         printf("About to open\n");
      42             : 
      43          10 :         dbproc = dbopen(login, SERVER);
      44          10 :         if (strlen(DATABASE))
      45          10 :                 dbuse(dbproc, DATABASE);
      46          10 :         dbloginfree(login);
      47             : 
      48             :         /* first query, select with error  */
      49          10 :         dbmsghandle(cancel_msg_handler);
      50          10 :         sql_cmd(dbproc);
      51          10 :         dbsqlexec(dbproc);
      52             : 
      53          10 :         dbmsghandle(syb_msg_handler);
      54             : 
      55             :         /* second query, select */
      56          10 :         printf("second select\n");
      57             : 
      58          10 :         if (SUCCEED != sql_cmd(dbproc) || SUCCEED != dbsqlexec(dbproc)) {
      59           0 :                 fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__);
      60           0 :                 exit(1);
      61             :         }
      62             : 
      63          10 :         if (dbresults(dbproc) != SUCCEED) {
      64           0 :                 fprintf(stderr, "Was expecting a result set.");
      65           0 :                 exit(1);
      66             :         }
      67             : 
      68          10 :         for (i = 1; i <= dbnumcols(dbproc); i++)
      69          10 :                 printf("col %d is %s\n", i, dbcolname(dbproc, i));
      70             : 
      71          10 :         dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
      72             : 
      73          10 :         if (REG_ROW != dbnextrow(dbproc)) {
      74           0 :                 fprintf(stderr, "Failed.  Expected a row\n");
      75           0 :                 exit(1);
      76             :         }
      77          10 :         if (testint != 1) {
      78           0 :                 fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
      79           0 :                 exit(1);
      80             :         }
      81          10 :         if (dbnextrow(dbproc) != NO_MORE_ROWS) {
      82           0 :                 fprintf(stderr, "No other rows expected\n");
      83             :         }
      84             : 
      85          10 :         dbexit();
      86             : 
      87          10 :         printf("ok\n");
      88             :         return 0;
      89             : }

Generated by: LCOV version 1.13