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: 2024-04-18 20:40:06 Functions: 1 1 100.0 %

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

Generated by: LCOV version 1.13