LCOV - code coverage report
Current view: top level - src/odbc/unittests - error.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 32 34 94.1 %
Date: 2026-07-19 14:02:14 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_use_version3 = false;
      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          10 :         odbc_command("create table #names(vc varchar(100))");
      22          10 :         odbc_command("set nocount on\ndeclare @i int\nselect @i = 1\n"
      23             :                      "while @i <= 1000 begin\n"
      24             :                      "  insert into #names values('this is a different name ' + convert(varchar(10), @i))\n"
      25             :                      "  select @i = @i + 1\nend\nset nocount off\n");
      26             : 
      27             :         /* issue our command */
      28          10 :         RetCode = odbc_command2("select 100 / (i - 5) from #tmp order by i", "SE");
      29             : 
      30             :         /* special case, early Sybase detect error early */
      31          10 :         if (RetCode != SQL_ERROR) {
      32             : 
      33             :                 /* TODO when multiple row fetch available test for error on some columns */
      34          10 :                 CHKFetch("S");
      35          10 :                 CHKFetch("S");
      36          10 :                 CHKFetch("E");
      37             :         }
      38             : 
      39          10 :         odbc_read_error();
      40          10 :         if (!strstr(odbc_err, "zero")) {
      41           0 :                 fprintf(stderr, "Message invalid\n");
      42           0 :                 return 1;
      43             :         }
      44             : 
      45          10 :         SQLFetch(odbc_stmt);
      46          10 :         SQLFetch(odbc_stmt);
      47          10 :         SQLFetch(odbc_stmt);
      48          10 :         SQLMoreResults(odbc_stmt);
      49             : 
      50          10 :         CHKAllocStmt(&stmt, "S");
      51             : 
      52          10 :         odbc_command("SELECT * FROM #names");
      53             : 
      54          10 :         odbc_stmt = stmt;
      55             : 
      56             :         /* a statement is already active so you get error... */
      57          10 :         if (odbc_command2("SELECT * FROM #names", "SE") == SQL_SUCCESS) {
      58           2 :                 SQLMoreResults(odbc_stmt);
      59             :                 /* ...or we are using MARS! */
      60           2 :                 odbc_command2("BEGIN TRANSACTION", "E");
      61             :         }
      62             : 
      63          10 :         odbc_read_error();
      64             : 
      65          10 :         odbc_disconnect();
      66             : 
      67          10 :         printf("Done.\n");
      68          10 :         return 0;
      69             : }

Generated by: LCOV version 1.13