LCOV - code coverage report
Current view: top level - src/ctlib/unittests - blk_out.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 45 49 91.8 %
Date: 2025-07-26 13:53:51 Functions: 1 1 100.0 %

          Line data    Source code
       1             : #include "common.h"
       2             : 
       3             : #include <bkpublic.h>
       4             : 
       5             : /* Testing: array binding of result set */
       6          10 : TEST_MAIN()
       7             : {
       8             :         CS_CONTEXT *ctx;
       9             :         CS_CONNECTION *conn;
      10             :         CS_COMMAND *cmd;
      11             :         CS_BLKDESC *blkdesc;
      12          10 :         int verbose = 0;
      13             : 
      14             :         CS_RETCODE ret;
      15             : 
      16             :         CS_DATAFMT datafmt;
      17          10 :         CS_INT count = 0;
      18             : 
      19             :         CS_INT  col1[2];
      20             :         CS_CHAR col2[2][5];
      21             :         CS_CHAR col3[2][32];
      22             :         CS_INT      lencol1[2];
      23             :         CS_SMALLINT indcol1[2];
      24             :         CS_INT      lencol2[2];
      25             :         CS_SMALLINT indcol2[2];
      26             :         CS_INT      lencol3[2];
      27             :         CS_SMALLINT indcol3[2];
      28             : 
      29             :         int i;
      30             : 
      31             : 
      32          10 :         printf("%s: Retrieve data using array binding \n", __FILE__);
      33             :         if (verbose) {
      34             :                 printf("Trying login\n");
      35             :         }
      36          10 :         check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
      37             : 
      38             :         /* do not test error */
      39          10 :         run_command(cmd, "IF OBJECT_ID('tempdb..#ctlibarray') IS NOT NULL DROP TABLE #ctlibarray");
      40             : 
      41          10 :         check_call(run_command, (cmd, "CREATE TABLE #ctlibarray (col1 int null,  col2 char(4) not null, col3 datetime not null)"));
      42          10 :         check_call(run_command, (cmd, "insert into #ctlibarray values (1, 'AAAA', 'Jan  1 2002 10:00:00AM')"));
      43          10 :         check_call(run_command, (cmd, "insert into #ctlibarray values (2, 'BBBB', 'Jan  2 2002 10:00:00AM')"));
      44          10 :         check_call(run_command, (cmd, "insert into #ctlibarray values (3, 'CCCC', 'Jan  3 2002 10:00:00AM')"));
      45          10 :         check_call(run_command, (cmd, "insert into #ctlibarray values (8, 'DDDD', 'Jan  4 2002 10:00:00AM')"));
      46          10 :         check_call(run_command, (cmd, "insert into #ctlibarray values (NULL, 'EEEE', 'Jan  5 2002 10:00:00AM')"));
      47             : 
      48          10 :         check_call(blk_alloc, (conn, BLK_VERSION_100, &blkdesc));
      49             : 
      50          10 :         check_call(blk_init, (blkdesc, CS_BLK_OUT, "#ctlibarray", CS_NULLTERM));
      51             : 
      52          10 :         check_call(blk_describe, (blkdesc, 1, &datafmt));
      53             : 
      54          10 :         datafmt.format = CS_FMT_UNUSED;
      55          10 :         if (datafmt.maxlength > 1024) {
      56           0 :                 datafmt.maxlength = 1024;
      57             :         }
      58             : 
      59          10 :         datafmt.count = 2;
      60             : 
      61          10 :         check_call(blk_bind, (blkdesc, 1, &datafmt, &col1[0], &lencol1[0], &indcol1[0]));
      62             : 
      63          10 :         check_call(blk_describe, (blkdesc, 2, &datafmt));
      64             : 
      65          10 :         datafmt.format = CS_FMT_NULLTERM;
      66          10 :         datafmt.maxlength = 5;
      67          10 :         datafmt.count = 2;
      68             : 
      69          10 :         check_call(blk_bind, (blkdesc, 2, &datafmt, col2[0], &lencol2[0], &indcol2[0]));
      70             : 
      71          10 :         check_call(blk_describe, (blkdesc, 3, &datafmt));
      72             : 
      73          10 :         datafmt.datatype = CS_CHAR_TYPE;
      74          10 :         datafmt.format = CS_FMT_NULLTERM;
      75          10 :         datafmt.maxlength = 32;
      76          10 :         datafmt.count = 2;
      77             : 
      78          10 :         check_call(blk_bind, (blkdesc, 3, &datafmt, col3[0], &lencol3[0], &indcol3[0]));
      79             : 
      80          40 :         while((ret = blk_rowxfer_mult(blkdesc, &count)) == CS_SUCCEED) {
      81          40 :                 for(i = 0; i < count; i++) {
      82         120 :                         printf("retrieved %d (%d,%d) %s (%d,%d) %s (%d,%d)\n", 
      83          40 :                                 col1[i], lencol1[i], indcol1[i],
      84          80 :                                 col2[i], lencol2[i], indcol2[i],
      85          80 :                                 col3[i], lencol3[i], indcol3[i] );
      86             :                 }
      87             :         }
      88          10 :         switch (ret) {
      89             :         case CS_END_DATA:
      90          10 :                 for(i = 0; i < count; i++) {
      91          30 :                         printf("retrieved %d (%d,%d) %s (%d,%d) %s (%d,%d)\n", 
      92          10 :                                 col1[i], lencol1[i], indcol1[i],
      93          20 :                                 col2[i], lencol2[i], indcol2[i],
      94          20 :                                 col3[i], lencol3[i], indcol3[i] );
      95             :                 }
      96             :                 break;
      97           0 :         case CS_FAIL:
      98             :         case CS_ROW_FAIL:
      99           0 :                 fprintf(stderr, "blk_rowxfer_mult() failed\n");
     100           0 :                 return 1;
     101             :         }
     102             : 
     103          10 :         blk_drop(blkdesc);
     104             : 
     105          10 :         check_call(try_ctlogout, (ctx, conn, cmd, verbose));
     106             : 
     107          10 :         return 0;
     108             : }

Generated by: LCOV version 1.13