LCOV - code coverage report
Current view: top level - src/odbc/unittests - warning.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 18 18 100.0 %
Date: 2024-04-18 20:40:06 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 char software_version[] = "$Id: warning.c,v 1.11 2011-07-12 10:16:59 freddy77 Exp $";
      18             : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
      19             : 
      20             : static const char one_null_with_warning[] = "select max(a) as foo from (select convert(int, null) as a) as test";
      21             : 
      22             : #ifdef TDS_NO_DM
      23             : static const int tds_no_dm = 1;
      24             : #else
      25             : static const int tds_no_dm = 0;
      26             : #endif
      27             : 
      28             : static void
      29          16 : Test(const char *query)
      30             : {
      31          16 :         CHKPrepare(T(query), SQL_NTS, "S");
      32             : 
      33          16 :         CHKExecute("S");
      34             : 
      35          16 :         CHKFetch("SI");
      36             : 
      37          16 :         CHKFetch("No");
      38             : 
      39             :         /*
      40             :          * Microsoft SQL Server 2000 provides a diagnostic record
      41             :          * associated with the second SQLFetch (which returns
      42             :          * SQL_NO_DATA) saying "Warning: Null value is eliminated by
      43             :          * an aggregate or other SET operation."
      44             :          * We check for "NO DM" cause unixODBC till 2.2.11 do not read
      45             :          * errors on SQL_NO_DATA
      46             :          */
      47          16 :         if (odbc_db_is_microsoft() && tds_no_dm) {
      48             :                 SQLTCHAR output[256];
      49             : 
      50          12 :                 CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, NULL, NULL, output, TDS_VECTOR_SIZE(output), NULL, "SI");
      51          12 :                 printf("Message: %s\n", C(output));
      52             :         }
      53             : 
      54          16 :         odbc_reset_statement();
      55          16 : }
      56             : 
      57             : int
      58           8 : main(void)
      59             : {
      60           8 :         odbc_connect();
      61             : 
      62           8 :         odbc_command("CREATE TABLE #warning(name varchar(20), value int null)");
      63           8 :         odbc_command("INSERT INTO #warning VALUES('a', NULL)");
      64             : 
      65           8 :         Test(one_null_with_warning);
      66           8 :         Test("SELECT SUM(value) FROM #warning");
      67             : 
      68           8 :         odbc_disconnect();
      69             : 
      70           8 :         printf("Done.\n");
      71             :         return 0;
      72             : }
      73             : 

Generated by: LCOV version 1.13