LCOV - code coverage report
Current view: top level - src/ctlib/unittests - blk_in2.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 30 30 100.0 %
Date: 2025-01-18 11:50:39 Functions: 2 2 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Test from MATSUMOTO, Tadashi
       3             :  * Cfr "blk_init fails by the even number times execution" on ML, 2007-03-09
       4             :  * This mix bulk and cancel
       5             :  */
       6             : 
       7             : #include "common.h"
       8             : 
       9             : #if HAVE_SYS_STAT_H
      10             : #include <sys/stat.h>
      11             : #endif /* HAVE_SYS_STAT_H */
      12             : 
      13             : #include <bkpublic.h>
      14             : 
      15             : static const char create_table_sql[] = "CREATE TABLE hogexxx (col varchar(100))";
      16             : 
      17             : static void
      18          80 : hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data)
      19             : {
      20          80 :         CS_DATAFMT meta = { "" };
      21          80 :         CS_INT length = 5;
      22          80 :         CS_INT row = 0;
      23             : 
      24          80 :         check_call(ct_cancel, (con, NULL, CS_CANCEL_ALL));
      25          80 :         check_call(blk_init, (blk, CS_BLK_IN, table, CS_NULLTERM));
      26             : 
      27          80 :         check_call(blk_props, (blk, CS_SET, BLK_HINTS, "TABLOCK", CS_NULLTERM, NULL));
      28             : 
      29          80 :         meta.count = 1;
      30          80 :         meta.datatype = CS_CHAR_TYPE;
      31          80 :         meta.format = CS_FMT_PADBLANK;
      32          80 :         meta.maxlength = 5;
      33             : 
      34          80 :         check_call(blk_bind, (blk, (int) 1, &meta, data, &length, NULL));
      35          80 :         check_call(blk_rowxfer, (blk));
      36          80 :         check_call(blk_done, (blk, CS_BLK_ALL, &row));
      37          80 : }
      38             : 
      39             : int
      40           8 : main(void)
      41             : {
      42             :         CS_CONTEXT *ctx;
      43             :         CS_CONNECTION *conn;
      44             :         CS_COMMAND *cmd;
      45             :         CS_BLKDESC *blkdesc;
      46           8 :         int verbose = 0;
      47             :         int i;
      48             :         char command[512];
      49             : 
      50             : 
      51             :         static char table_name[20] = "hogexxx";
      52             : 
      53           8 :         printf("%s: Inserting data using bulk cancelling\n", __FILE__);
      54             :         if (verbose) {
      55             :                 printf("Trying login\n");
      56             :         }
      57           8 :         check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
      58             : 
      59           8 :         sprintf(command, "if exists (select 1 from sysobjects where type = 'U' and name = '%s') drop table %s",
      60             :                 table_name, table_name);
      61             : 
      62           8 :         check_call(run_command, (cmd, command));
      63             : 
      64           8 :         check_call(run_command, (cmd, create_table_sql));
      65             : 
      66           8 :         check_call(blk_alloc, (conn, BLK_VERSION_100, &blkdesc));
      67             : 
      68          88 :         for (i = 0; i < 10; i++) {
      69             :                 /* compute some data */
      70          80 :                 memset(command, ' ', sizeof(command));
      71          80 :                 memset(command, 'a' + i, (i * 37) % 11);
      72             : 
      73          80 :                 hoge_blkin(conn, blkdesc, table_name, command);
      74             :         }
      75             : 
      76           8 :         blk_drop(blkdesc);
      77             : 
      78             :         /* TODO test correct insert */
      79             : 
      80           8 :         printf("done\n");
      81             : 
      82           8 :         check_call(try_ctlogout, (ctx, conn, cmd, verbose));
      83             : 
      84             :         return 0;
      85             : }
      86             : 

Generated by: LCOV version 1.13