LCOV - code coverage report
Current view: top level - src/odbc/unittests - descrec.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 32 34 94.1 %
Date: 2026-05-04 13:14:38 Functions: 4 4 100.0 %

          Line data    Source code
       1             : /* test SQLGetDescRec */
       2             : #include "common.h"
       3             : 
       4             : static void
       5          30 : check_int(bool cond, long int value, const char *msg, int line)
       6             : {
       7          30 :         if (cond)
       8          30 :                 return;
       9           0 :         fprintf(stderr, "Invalid value %ld at line %d, check: %s\n", value, line, msg);
      10           0 :         exit(1);
      11             : }
      12             : 
      13             : #define check_int(value, cond, expected) \
      14             :         check_int(value cond expected, value, #value " " #cond " " #expected, __LINE__)
      15             : 
      16             : static void
      17          10 : test_column_number(void)
      18             : {
      19             :         SQLHDESC Descriptor;
      20             :         SQLINTEGER ind;
      21             :         SQLTCHAR name[128];
      22             :         SQLSMALLINT si;
      23             : 
      24             :         /* get IRD */
      25          10 :         CHKGetStmtAttr(SQL_ATTR_IMP_ROW_DESC, &Descriptor, sizeof(Descriptor), &ind, "S");
      26             : 
      27             :         /* Wrong column number */
      28          10 :         CHKGetDescRec(-1, name, TDS_VECTOR_SIZE(name), &si, NULL, NULL, NULL, NULL, NULL, NULL, "E");
      29             : 
      30             :         /* TODO here should be NO_DATA cause we are requesting bookmark */
      31             :         /* CHKGetDescRec(0, name, sizeof(name), &si, NULL, NULL, NULL, NULL, NULL, NULL, "No"); */
      32             : 
      33             :         /* No column present */
      34          10 :         CHKGetDescRec(1, name, TDS_VECTOR_SIZE(name), &si, NULL /*Type */ , NULL /*SubType */ , NULL /*Length */ ,
      35             :                       NULL /*Precision */ , NULL /*Scale */ , NULL /*Nullable */ , "No");
      36             : 
      37          10 :         odbc_command("SELECT name FROM #tmp1");
      38             : 
      39             :         /* Column present */
      40          10 :         CHKGetDescRec(1, name, TDS_VECTOR_SIZE(name), &si, NULL /*Type */ , NULL /*SubType */ , NULL /*Length */ ,
      41             :                       NULL /*Precision */ , NULL /*Scale */ , NULL /*Nullable */ , "S");
      42          10 : }
      43             : 
      44             : static void
      45          10 : test_ard_allocation(void)
      46             : {
      47             :         SQLHDESC ard;
      48             :         SQLINTEGER ind;
      49             :         SQLSMALLINT count;
      50             : 
      51          10 :         odbc_reset_statement();
      52             : 
      53          10 :         CHKGetStmtAttr(SQL_ATTR_APP_ROW_DESC, &ard, sizeof(ard), &ind, "S");
      54             : 
      55             :         /* A query should not extent ARD */
      56          10 :         odbc_command("SELECT name FROM #tmp1");
      57          10 :         CHKGetDescField(ard, 0, SQL_DESC_COUNT, &count, sizeof(count), &ind, "S");
      58          10 :         check_int(count, ==, 0);
      59             : 
      60             :         /* This should not extent ARD */
      61          10 :         CHKSetDescField(ard, 2, SQL_DESC_AUTO_UNIQUE_VALUE, TDS_INT2PTR(10), 0, "E");
      62          10 :         CHKGetDescField(ard, 0, SQL_DESC_COUNT, &count, sizeof(count), &ind, "S");
      63          10 :         check_int(count, ==, 0);
      64             : 
      65             :         /* This should extent ARD */
      66          10 :         CHKSetDescField(ard, 2, SQL_DESC_SCALE, TDS_INT2PTR(10), 0, "S");
      67          10 :         CHKGetDescField(ard, 0, SQL_DESC_COUNT, &count, sizeof(count), &ind, "S");
      68          10 :         check_int(count, ==, 2);
      69          10 : }
      70             : 
      71          10 : TEST_MAIN()
      72             : {
      73          10 :         odbc_use_version3 = true;
      74          10 :         odbc_connect();
      75             : 
      76          10 :         odbc_command("create table #tmp1 (name varchar(100))");
      77             : 
      78          10 :         test_column_number();
      79          10 :         test_ard_allocation();
      80             : 
      81          10 :         odbc_disconnect();
      82          10 :         ODBC_FREE();
      83          10 :         return 0;
      84             : }

Generated by: LCOV version 1.13