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-02-21 09:36:06 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.13