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

          Line data    Source code
       1             : /*
       2             :  * Purpose: Retrieve the connection SPID.
       3             :  * Functions: dbspid
       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 expected_spid, actual_spid;
      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, "spid");
      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             : #ifdef DBQUOTEDIDENT
      50           8 :         printf("QUOTED_IDENTIFIER is %s\n", (dbisopt(dbproc, DBQUOTEDIDENT, NULL))? "ON":"OFF");
      51             : #endif
      52           8 :         sql_cmd(dbproc);
      53           8 :         dbsqlexec(dbproc);
      54             : 
      55           8 :         if (dbresults(dbproc) != SUCCEED) {
      56           0 :                 fprintf(stderr, "error: expected a result set, none returned.\n");
      57           0 :                 return 1;
      58             :         }
      59             : 
      60           8 :         if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & expected_spid)) {
      61           0 :                 fprintf(stderr, "Had problem with bind\n");
      62           0 :                 return 1;
      63             :         }
      64           8 :         if (REG_ROW != dbnextrow(dbproc)) {
      65           0 :                 fprintf(stderr, "Failed.  Expected a row\n");
      66           0 :                 return 1;
      67             :         }
      68           8 :         assert(expected_spid > 0);
      69             : 
      70           8 :         actual_spid = dbspid(dbproc);
      71           8 :         if (expected_spid != actual_spid) {
      72           0 :                 fprintf(stderr, "Failed.  Expected spid to be %d, was %d\n", expected_spid, actual_spid);
      73           0 :                 return 1;
      74             :         }
      75             : 
      76           8 :         if (dbnextrow(dbproc) != NO_MORE_ROWS) {
      77           0 :                 fprintf(stderr, "Was expecting no more rows\n");
      78           0 :                 return 1;
      79             :         }
      80             : 
      81           8 :         dbclose(dbproc);
      82             : 
      83           8 :         dbexit();
      84           8 :         return 0;
      85             : }

Generated by: LCOV version 1.13