LCOV - code coverage report
Current view: top level - src/ctlib/unittests - blk_in2.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 31 31 100.0 %
Date: 2025-04-21 03:58:01 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         100 : hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data)
      19             : {
      20         100 :         CS_DATAFMT meta = { "" };
      21         100 :         CS_INT length = 5;
      22         100 :         CS_INT row = 0;
      23             : 
      24         100 :         check_call(ct_cancel, (con, NULL, CS_CANCEL_ALL));
      25         100 :         check_call(blk_init, (blk, CS_BLK_IN, table, CS_NULLTERM));
      26             : 
      27         100 :         check_call(blk_props, (blk, CS_SET, BLK_HINTS, "TABLOCK", CS_NULLTERM, NULL));
      28             : 
      29         100 :         meta.count = 1;
      30         100 :         meta.datatype = CS_CHAR_TYPE;
      31         100 :         meta.format = CS_FMT_PADBLANK;
      32         100 :         meta.maxlength = 5;
      33             : 
      34         100 :         check_call(blk_bind, (blk, (int) 1, &meta, data, &length, NULL));
      35         100 :         check_call(blk_rowxfer, (blk));
      36         100 :         check_call(blk_done, (blk, CS_BLK_ALL, &row));
      37         100 : }
      38             : 
      39          10 : TEST_MAIN()
      40             : {
      41             :         CS_CONTEXT *ctx;
      42             :         CS_CONNECTION *conn;
      43             :         CS_COMMAND *cmd;
      44             :         CS_BLKDESC *blkdesc;
      45          10 :         int verbose = 0;
      46             :         int i;
      47             :         char command[512];
      48             : 
      49             : 
      50             :         static char table_name[20] = "hogexxx";
      51             : 
      52          10 :         printf("%s: Inserting data using bulk cancelling\n", __FILE__);
      53             :         if (verbose) {
      54             :                 printf("Trying login\n");
      55             :         }
      56          10 :         check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
      57             : 
      58          10 :         sprintf(command, "if exists (select 1 from sysobjects where type = 'U' and name = '%s') drop table %s",
      59             :                 table_name, table_name);
      60             : 
      61          10 :         check_call(run_command, (cmd, command));
      62             : 
      63          10 :         check_call(run_command, (cmd, create_table_sql));
      64             : 
      65          10 :         check_call(blk_alloc, (conn, BLK_VERSION_100, &blkdesc));
      66             : 
      67         110 :         for (i = 0; i < 10; i++) {
      68             :                 /* compute some data */
      69         100 :                 memset(command, ' ', sizeof(command));
      70         100 :                 memset(command, 'a' + i, (i * 37) % 11);
      71             : 
      72         100 :                 hoge_blkin(conn, blkdesc, table_name, command);
      73             :         }
      74             : 
      75          10 :         blk_drop(blkdesc);
      76             : 
      77             :         /* TODO test correct insert */
      78             : 
      79          10 :         printf("done\n");
      80             : 
      81          10 :         check_call(try_ctlogout, (ctx, conn, cmd, verbose));
      82             : 
      83          10 :         return 0;
      84             : }
      85             : 

Generated by: LCOV version 1.13