LCOV - code coverage report
Current view: top level - src/dblib/unittests - cancel.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 36 45 80.0 %
Date: 2025-07-02 09:40:27 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          10 : TEST_MAIN()
      18             : {
      19             :         LOGINREC *login;
      20             :         DBPROCESS *dbproc;
      21             :         int i;
      22          10 :         DBINT testint = -1;
      23             : 
      24          10 :         read_login_info(argc, argv);
      25             : 
      26          10 :         printf("Starting %s\n", argv[0]);
      27             : 
      28          10 :         dbinit();
      29             : 
      30          10 :         dberrhandle(syb_err_handler);
      31          10 :         dbmsghandle(syb_msg_handler);
      32             : 
      33          10 :         printf("About to logon\n");
      34             : 
      35          10 :         login = dblogin();
      36          10 :         DBSETLPWD(login, PASSWORD);
      37          10 :         DBSETLUSER(login, USER);
      38          10 :         DBSETLAPP(login, "cancel");
      39             : 
      40          10 :         printf("About to open\n");
      41             : 
      42          10 :         dbproc = dbopen(login, SERVER);
      43          10 :         if (strlen(DATABASE))
      44          10 :                 dbuse(dbproc, DATABASE);
      45          10 :         dbloginfree(login);
      46             : 
      47             :         /* first query, select with error  */
      48          10 :         dbmsghandle(cancel_msg_handler);
      49          10 :         sql_cmd(dbproc);
      50          10 :         dbsqlexec(dbproc);
      51             : 
      52          10 :         dbmsghandle(syb_msg_handler);
      53             : 
      54             :         /* second query, select */
      55          10 :         printf("second select\n");
      56             : 
      57          10 :         if (SUCCEED != sql_cmd(dbproc) || SUCCEED != dbsqlexec(dbproc)) {
      58           0 :                 fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__);
      59           0 :                 exit(1);
      60             :         }
      61             : 
      62          10 :         if (dbresults(dbproc) != SUCCEED) {
      63           0 :                 fprintf(stderr, "Was expecting a result set.");
      64           0 :                 exit(1);
      65             :         }
      66             : 
      67          10 :         for (i = 1; i <= dbnumcols(dbproc); i++)
      68          10 :                 printf("col %d is %s\n", i, dbcolname(dbproc, i));
      69             : 
      70          10 :         dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
      71             : 
      72          10 :         if (REG_ROW != dbnextrow(dbproc)) {
      73           0 :                 fprintf(stderr, "Failed.  Expected a row\n");
      74           0 :                 exit(1);
      75             :         }
      76          10 :         if (testint != 1) {
      77           0 :                 fprintf(stderr, "Failed.  Expected i to be %d, was %d\n", i, (int) testint);
      78           0 :                 exit(1);
      79             :         }
      80          10 :         if (dbnextrow(dbproc) != NO_MORE_ROWS) {
      81           0 :                 fprintf(stderr, "No other rows expected\n");
      82             :         }
      83             : 
      84          10 :         dbexit();
      85             : 
      86          10 :         printf("ok\n");
      87          10 :         return 0;
      88             : }

Generated by: LCOV version 1.13