LCOV - code coverage report
Current view: top level - src/odbc/unittests - warning.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 19 19 100.0 %
Date: 2025-10-24 03:11:41 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /*
       4             :  * Test originally written by John K. Hohm
       5             :  * (cfr "Warning return as copy of last result row (was: Warning: Null value
       6             :  * is eliminated by an aggregate or other SET operation.)" July 15th 2006)
       7             :  *
       8             :  * Contains also similar test by Jeff Dahl
       9             :  * (cfr "Warning: Null value is eliminated by an aggregate or other SET 
      10             :  * operation." March 24th 2006
      11             :  *
      12             :  * This test wrong SQLFetch results with warning inside select
      13             :  * Is different from raiserror test cause in raiserror error is not
      14             :  * inside recordset
      15             :  * Sybase do not return warning but test works the same
      16             :  */
      17             : static const char one_null_with_warning[] = "select max(a) as foo from (select convert(int, null) as a) as test";
      18             : 
      19             : static void
      20          20 : Test(const char *query)
      21             : {
      22          20 :         CHKPrepare(T(query), SQL_NTS, "S");
      23             : 
      24          20 :         CHKExecute("S");
      25             : 
      26          20 :         CHKFetch("SI");
      27             : 
      28          20 :         CHKFetch("No");
      29             : 
      30             :         /*
      31             :          * Microsoft SQL Server 2000 provides a diagnostic record
      32             :          * associated with the second SQLFetch (which returns
      33             :          * SQL_NO_DATA) saying "Warning: Null value is eliminated by
      34             :          * an aggregate or other SET operation."
      35             :          * We check for "NO DM" cause unixODBC till 2.2.11 do not read
      36             :          * errors on SQL_NO_DATA
      37             :          */
      38          20 :         if (odbc_db_is_microsoft() && tds_no_dm) {
      39             :                 SQLTCHAR output[256];
      40             : 
      41          16 :                 CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, NULL, NULL, output, TDS_VECTOR_SIZE(output), NULL, "SI");
      42          16 :                 printf("Message: %s\n", C(output));
      43             :         }
      44             : 
      45          20 :         odbc_reset_statement();
      46          20 : }
      47             : 
      48          10 : TEST_MAIN()
      49             : {
      50          10 :         odbc_connect();
      51             : 
      52          10 :         odbc_command("CREATE TABLE #warning(name varchar(20), value int null)");
      53          10 :         odbc_command("INSERT INTO #warning VALUES('a', NULL)");
      54             : 
      55          10 :         Test(one_null_with_warning);
      56          10 :         Test("SELECT SUM(value) FROM #warning");
      57             : 
      58          10 :         odbc_disconnect();
      59             : 
      60          10 :         printf("Done.\n");
      61          10 :         return 0;
      62             : }
      63             : 

Generated by: LCOV version 1.13