LCOV - code coverage report
Current view: top level - src/odbc/unittests - long_error.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 24 24 100.0 %
Date: 2026-07-19 14:02:14 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : 
       4             : /*
       5             : Demonstration of triggered assert when invoking this stored procedure
       6             : using FreeTDS odbc driver:
       7             : 
       8             : create procedure proc_longerror as
       9             : begin
      10             :     raiserror('reallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylongreallylong error', 16, 1)
      11             : end
      12             : 
      13             : */
      14             : 
      15             : static void extract_error(SQLHANDLE handle, SQLSMALLINT type);
      16             : 
      17          10 : TEST_MAIN()
      18             : {
      19             :         int i;
      20             :         char cmd[128 + 110*10];
      21             : 
      22          10 :         printf("SQLWCHAR size is: %d\n", (int) sizeof(SQLWCHAR));
      23             : 
      24          10 :         odbc_connect();
      25             : 
      26             :         /* this test do not work with Sybase */
      27          10 :         if (!odbc_db_is_microsoft()) {
      28           2 :                 odbc_disconnect();
      29           2 :                 return 0;
      30             :         }
      31             : 
      32           8 :         strcpy(cmd, "create procedure #proc_longerror as\nbegin\nraiserror('");
      33         888 :         for (i = 0; i < 110; ++i)
      34         880 :                 strcat(cmd, "reallylong");
      35           8 :         strcat(cmd, " error', 16, 1)\nend\n");
      36           8 :         odbc_command(cmd);
      37             : 
      38           8 :         CHKExecDirect(T("{CALL #proc_longerror}"), SQL_NTS, "E");
      39             : 
      40           8 :         extract_error(odbc_stmt, SQL_HANDLE_STMT);
      41             : 
      42           8 :         odbc_disconnect();
      43           8 :         return 0;
      44             : }
      45             : 
      46             : static void
      47           8 : extract_error(SQLHANDLE handle, SQLSMALLINT type)
      48             : {
      49           8 :         SQLSMALLINT i = 0;
      50             :         SQLINTEGER native;
      51             :         SQLTCHAR state[7];
      52             :         SQLTCHAR text[256];
      53             :         SQLSMALLINT len;
      54             :         SQLRETURN ret;
      55             : 
      56           8 :         fprintf(stderr, "\n" "The driver reported the following diagnostics\n");
      57             : 
      58             :         do {
      59          10 :                 ret = CHKGetDiagRec(type, handle, ++i, state, &native, text, 256, &len, "SINo");
      60          10 :                 state[5] = 0;
      61          10 :                 if (SQL_SUCCEEDED(ret))
      62           8 :                         printf("%s:%ld:%ld:%s\n", C(state), (long) i,
      63             :                                (long) native, C(text));
      64             :         }
      65          10 :         while (ret == SQL_SUCCESS);
      66           8 : }
      67             : 

Generated by: LCOV version 1.13