?? warning.c
字號:
#include "common.h"/* * Test originally written by John K. Hohm * (cfr "Warning return as copy of last result row (was: Warning: Null value * is eliminated by an aggregate or other SET operation.)" July 15th 2006) * * Contains also similar test by Jeff Dahl * (cfr "Warning: Null value is eliminated by an aggregate or other SET * operation." March 24th 2006 * * This test wrong SQLFetch results with warning inside select * Is different from raiserror test cause in raiserror error is not * inside recordset * Sybase do not return warning but test works the same */static char software_version[] = "$Id: warning.c,v 1.5 2007/05/17 13:11:56 freddy77 Exp $";static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };static const char one_null_with_warning[] = "select max(a) as foo from (select convert(int, null) as a) as test";#ifdef TDS_NO_DMstatic const int tds_no_dm = 1;#elsestatic const int tds_no_dm = 0;#endifstatic voidTest(const char *query){ int res; if (SQLPrepare(Statement, (SQLCHAR *) query, SQL_NTS) != SQL_SUCCESS) { fprintf(stderr, "Unable to prepare statement\n"); exit(1); } if (SQLExecute(Statement) != SQL_SUCCESS) { fprintf(stderr, "Unable to execute statement\n"); exit(1); } res = SQLFetch(Statement); if (res != SQL_SUCCESS && res != SQL_SUCCESS_WITH_INFO) { fprintf(stderr, "Unable to fetch row.\n"); CheckReturn(); exit(1); } if (SQLFetch(Statement) != SQL_NO_DATA) { fprintf(stderr, "Warning was returned as a result row -- bad!\n"); exit(1); } /* * Microsoft SQL Server 2000 provides a diagnostic record * associated with the second SQLFetch (which returns * SQL_NO_DATA) saying "Warning: Null value is eliminated by * an aggregate or other SET operation." * We check for "NO DM" cause unixODBC till 2.2.11 do not read * errors on SQL_NO_DATA */ if (db_is_microsoft() && tds_no_dm) { SQLCHAR output[256]; if (!SQL_SUCCEEDED(SQLGetDiagRec(SQL_HANDLE_STMT, Statement, 1, NULL, NULL, output, sizeof(output), NULL))) { fprintf(stderr, "SQLGetDiagRec should not fail\n"); exit(1); } printf("Message: %s\n", (char *) output); } ResetStatement();}intmain(void){ Connect(); Command(Statement, "CREATE TABLE #warning(name varchar(20), value int null)"); Command(Statement, "INSERT INTO #warning VALUES('a', NULL)"); Test(one_null_with_warning); Test("SELECT SUM(value) FROM #warning"); Disconnect(); printf("Done.\n"); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -