LCOV - code coverage report
Current view: top level - src/odbc/unittests - preperror.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 20 20 100.0 %
Date: 2025-04-15 09:57:00 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : /* test error on prepared statement, from Nathaniel Talbott test */
       4             : 
       5          10 : TEST_MAIN()
       6             : {
       7          10 :         SQLLEN cbInString = SQL_NTS;
       8             :         char buf[256];
       9             :         SQLTCHAR msg[256];
      10             :         SQLTCHAR sqlstate[6];
      11             : 
      12          10 :         odbc_connect();
      13             : 
      14          10 :         odbc_command("CREATE TABLE #urls ( recdate DATETIME ) ");
      15             : 
      16             :         /* test implicit conversion error */
      17          10 :         CHKExecDirect(T("INSERT INTO #urls ( recdate ) VALUES ( '2003-10-1 10:11:1 0' )"), SQL_NTS, "E");
      18             : 
      19             :         /* test prepared implicit conversion error */
      20          10 :         CHKPrepare(T("INSERT INTO #urls ( recdate ) VALUES ( ? )"), SQL_NTS, "SI");
      21             : 
      22          10 :         strcpy(buf, "2003-10-1 10:11:1 0");
      23          10 :         CHKBindParameter(1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 128, 0, buf, sizeof(buf), &cbInString, "SI");
      24             : 
      25          10 :         CHKExecute("E");
      26             : 
      27          10 :         CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, msg, TDS_VECTOR_SIZE(buf), NULL, "SI");
      28          10 :         printf("err=%s\n", C(msg));
      29             : 
      30             :         /* assure initial state */
      31          10 :         odbc_reset_statement();
      32             : 
      33             :         /* try to prepare and execute a statement with error (from DBD::ODBC test) */
      34          10 :         if (CHKPrepare(T("SELECT XXNOTCOLUMN FROM sysobjects"), SQL_NTS, "SE") == SQL_SUCCESS)
      35           8 :                 CHKExecute("E");
      36             : 
      37          10 :         CHKGetDiagRec(SQL_HANDLE_STMT, odbc_stmt, 1, sqlstate, NULL, msg, TDS_VECTOR_SIZE(buf), NULL, "SI");
      38          10 :         printf("err=%s\n", C(msg));
      39             : 
      40             : 
      41          10 :         odbc_disconnect();
      42             : 
      43          10 :         printf("Done.\n");
      44          10 :         ODBC_FREE();
      45          10 :         return 0;
      46             : }

Generated by: LCOV version 1.13