LCOV - code coverage report
Current view: top level - src/ctlib/unittests - blk_in2.c (source / functions) Hit Total Coverage
Test: FreeTDS coverage Lines: 36 43 83.7 %
Date: 2025-02-21 10:02:42 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 <config.h>
       8             : 
       9             : #include <stdio.h>
      10             : #include <assert.h>
      11             : 
      12             : #if HAVE_STDLIB_H
      13             : #include <stdlib.h>
      14             : #endif /* HAVE_STDLIB_H */
      15             : 
      16             : #if HAVE_SYS_STAT_H
      17             : #include <sys/stat.h>
      18             : #endif /* HAVE_SYS_STAT_H */
      19             : 
      20             : #if HAVE_STRING_H
      21             : #include <string.h>
      22             : #endif /* HAVE_STRING_H */
      23             : 
      24             : 
      25             : #include <ctpublic.h>
      26             : #include <bkpublic.h>
      27             : #include "common.h"
      28             : 
      29             : static const char create_table_sql[] = "CREATE TABLE hogexxx (col varchar(100))";
      30             : 
      31             : static CS_RETCODE
      32          80 : hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data)
      33             : {
      34          80 :         CS_DATAFMT meta = { "" };
      35          80 :         CS_INT length = 5;
      36          80 :         CS_INT row = 0;
      37             : 
      38          80 :         if (CS_SUCCEED != ct_cancel(con, NULL, CS_CANCEL_ALL))
      39             :                 return CS_FAIL;
      40          80 :         if (CS_SUCCEED != blk_init(blk, CS_BLK_IN, table, CS_NULLTERM))
      41             : 
      42           0 :         if (CS_SUCCEED != blk_props(blk, CS_SET, BLK_HINTS, "TABLOCK", CS_NULLTERM, NULL))
      43             :                 return CS_FAIL;
      44             : 
      45          80 :         meta.count = 1;
      46          80 :         meta.datatype = CS_CHAR_TYPE;
      47          80 :         meta.format = CS_FMT_PADBLANK;
      48          80 :         meta.maxlength = 5;
      49             : 
      50          80 :         if (CS_SUCCEED != blk_bind(blk, (int) 1, &meta, data, &length, NULL))
      51             :                 return CS_FAIL;
      52          80 :         if (CS_SUCCEED != blk_rowxfer(blk))
      53             :                 return CS_FAIL;
      54          80 :         if (CS_SUCCEED != blk_done(blk, CS_BLK_ALL, &row))
      55             :                 return CS_FAIL;
      56             : 
      57          80 :         return CS_SUCCEED;
      58             : }
      59             : 
      60             : int
      61           8 : main(int argc, char **argv)
      62             : {
      63             :         CS_CONTEXT *ctx;
      64             :         CS_CONNECTION *conn;
      65             :         CS_COMMAND *cmd;
      66             :         CS_BLKDESC *blkdesc;
      67           8 :         int verbose = 0;
      68           8 :         int ret = 0;
      69             :         int i;
      70             :         char command[512];
      71             : 
      72             : 
      73             :         static char table_name[20] = "hogexxx";
      74             : 
      75           8 :         printf("%s: Inserting data using bulk cancelling\n", __FILE__);
      76             :         if (verbose) {
      77             :                 printf("Trying login\n");
      78             :         }
      79           8 :         ret = try_ctlogin(&ctx, &conn, &cmd, verbose);
      80           8 :         if (ret != CS_SUCCEED) {
      81           0 :                 fprintf(stderr, "Login failed\n");
      82           0 :                 return 1;
      83             :         }
      84             : 
      85           8 :         sprintf(command, "if exists (select 1 from sysobjects where type = 'U' and name = '%s') drop table %s",
      86             :                 table_name, table_name);
      87             : 
      88           8 :         ret = run_command(cmd, command);
      89           8 :         if (ret != CS_SUCCEED)
      90             :                 return 1;
      91             : 
      92           8 :         ret = run_command(cmd, create_table_sql);
      93           8 :         if (ret != CS_SUCCEED)
      94             :                 return 1;
      95             : 
      96           8 :         ret = blk_alloc(conn, BLK_VERSION_100, &blkdesc);
      97           8 :         if (ret != CS_SUCCEED) {
      98           0 :                 fprintf(stderr, "blk_alloc() failed\n");
      99           0 :                 return 1;
     100             :         }
     101             : 
     102          80 :         for (i = 0; i < 10; i++) {
     103             :                 /* compute some data */
     104          80 :                 memset(command, ' ', sizeof(command));
     105          80 :                 memset(command, 'a' + i, (i * 37) % 11);
     106             : 
     107          80 :                 ret = hoge_blkin(conn, blkdesc, table_name, command);
     108          80 :                 if (ret != CS_SUCCEED)
     109             :                         return 1;
     110             :         }
     111             : 
     112           8 :         blk_drop(blkdesc);
     113             : 
     114             :         /* TODO test correct insert */
     115             : 
     116           8 :         printf("done\n");
     117             : 
     118           8 :         ret = try_ctlogout(ctx, conn, cmd, verbose);
     119           8 :         if (ret != CS_SUCCEED) {
     120           0 :                 fprintf(stderr, "Logout failed\n");
     121           0 :                 return 1;
     122             :         }
     123             : 
     124             :         return 0;
     125             : }
     126             : 

Generated by: LCOV version 1.13