LCOV - code coverage report
Current view: top level - src/odbc/unittests - error.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 29 31 93.5 %
Date: 2025-01-18 12:13:41 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /* some tests on error reporting */
       4             : 
       5             : int
       6           8 : main(int argc, char *argv[])
       7             : {
       8             :         SQLRETURN RetCode;
       9             :         HSTMT stmt;
      10             : 
      11           8 :         odbc_connect();
      12             : 
      13             :         /* create a test table */
      14           8 :         odbc_command("create table #tmp (i int)");
      15           8 :         odbc_command("insert into #tmp values(3)");
      16           8 :         odbc_command("insert into #tmp values(4)");
      17           8 :         odbc_command("insert into #tmp values(5)");
      18           8 :         odbc_command("insert into #tmp values(6)");
      19           8 :         odbc_command("insert into #tmp values(7)");
      20             : 
      21             :         /* issue our command */
      22           8 :         RetCode = odbc_command2("select 100 / (i - 5) from #tmp order by i", "SE");
      23             : 
      24             :         /* special case, early Sybase detect error early */
      25           8 :         if (RetCode != SQL_ERROR) {
      26             : 
      27             :                 /* TODO when multiple row fetch available test for error on some columns */
      28           8 :                 CHKFetch("S");
      29           8 :                 CHKFetch("S");
      30           8 :                 CHKFetch("E");
      31             :         }
      32             : 
      33           8 :         odbc_read_error();
      34           8 :         if (!strstr(odbc_err, "zero")) {
      35           0 :                 fprintf(stderr, "Message invalid\n");
      36           0 :                 return 1;
      37             :         }
      38             : 
      39           8 :         SQLFetch(odbc_stmt);
      40           8 :         SQLFetch(odbc_stmt);
      41           8 :         SQLFetch(odbc_stmt);
      42           8 :         SQLMoreResults(odbc_stmt);
      43             : 
      44           8 :         CHKAllocStmt(&stmt, "S");
      45             : 
      46           8 :         odbc_command("SELECT * FROM sysobjects");
      47             : 
      48           8 :         odbc_stmt = stmt;
      49             : 
      50             :         /* a statement is already active so you get error... */
      51           8 :         if (odbc_command2("SELECT *  FROM sysobjects", "SE") == SQL_SUCCESS) {
      52           1 :                 SQLMoreResults(odbc_stmt);
      53             :                 /* ...or we are using MARS! */
      54           1 :                 odbc_command2("BEGIN TRANSACTION", "E");
      55             :         }
      56             : 
      57           8 :         odbc_read_error();
      58             : 
      59           8 :         odbc_disconnect();
      60             : 
      61           8 :         printf("Done.\n");
      62           8 :         return 0;
      63             : }

Generated by: LCOV version 1.13