LCOV - code coverage report
Current view: top level - src/odbc/unittests - error.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 31 33 93.9 %
Date: 2026-05-04 13:14:38 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.13