NCBI C++ ToolKit
blk_in2.c
Go to the documentation of this file.

Go to the SVN repository for this file.

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  * $Id: blk_in2.c 80645 2017-12-28 17:20:38Z ucko $
6  */
7 
8 #include <config.h>
9 
10 #include <stdio.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 #include <common/test_assert.h>
30 
31 static const char create_table_sql[] = "CREATE TABLE hogexxx (col varchar(100))";
32 
33 static CS_RETCODE
34 hoge_blkin(CS_CONNECTION * con, CS_BLKDESC * blk, char *table, char *data)
35 {
36  CS_DATAFMT meta = { "" };
37  CS_INT length = 5;
38  CS_INT row = 0;
39 
40  if (CS_SUCCEED != ct_cancel(con, NULL, CS_CANCEL_ALL))
41  return CS_FAIL;
43  return CS_FAIL;
44 
45  meta.count = 1;
46  meta.datatype = CS_CHAR_TYPE;
47  meta.format = CS_FMT_PADBLANK;
48  meta.maxlength = 5;
49 
50  if (CS_SUCCEED != blk_bind(blk, (int) 1, &meta, data, &length, NULL))
51  return CS_FAIL;
52  if (CS_SUCCEED != blk_rowxfer(blk))
53  return CS_FAIL;
54  if (CS_SUCCEED != blk_done(blk, CS_BLK_ALL, &row))
55  return CS_FAIL;
56 
57  return CS_SUCCEED;
58 }
59 
60 int
61 main(int argc, char **argv)
62 {
63  CS_CONTEXT *ctx;
65  CS_COMMAND *cmd;
66  CS_BLKDESC *blkdesc;
67  int verbose = 0;
68  int ret = 0;
69  int i;
70  char command[512];
71 
72 
73  static char table_name[20] = "hogexxx";
74 
75  fprintf(stdout, "%s: Inserting data using bulk cancelling\n", __FILE__);
76  if (verbose) {
77  fprintf(stdout, "Trying login\n");
78  }
79  ret = try_ctlogin(&ctx, &conn, &cmd, verbose);
80  if (ret != CS_SUCCEED) {
81  fprintf(stderr, "Login failed\n");
82  return 1;
83  }
84 
85  sprintf(command, "if exists (select 1 from sysobjects where type = 'U' and name = '%s') drop table %s",
87 
88  ret = run_command(cmd, command);
89  if (ret != CS_SUCCEED)
90  return 1;
91 
93  if (ret != CS_SUCCEED)
94  return 1;
95 
96  ret = blk_alloc(conn, BLK_VERSION_100, &blkdesc);
97  if (ret != CS_SUCCEED) {
98  fprintf(stderr, "blk_alloc() failed\n");
99  return 1;
100  }
101 
102  for (i = 0; i < 10; i++) {
103  /* compute some data */
104  memset(command, ' ', sizeof(command));
105  memset(command, 'a' + i, (i * 37) % 11);
106 
107  ret = hoge_blkin(conn, blkdesc, table_name, command);
108  if (ret != CS_SUCCEED)
109  return 1;
110  }
111 
112  blk_drop(blkdesc);
113 
114  /* TODO test correct insert */
115 
116  printf("done\n");
117 
118  ret = try_ctlogout(ctx, conn, cmd, verbose);
119  if (ret != CS_SUCCEED) {
120  fprintf(stderr, "Logout failed\n");
121  return 1;
122  }
123 
124  return 0;
125 }
126 
CS_RETCODE blk_init(CS_BLKDESC *blkdesc, CS_INT direction, CS_CHAR *tablename, CS_INT tnamelen)
Definition: blk.c:340
CS_RETCODE blk_drop(CS_BLKDESC *blkdesc)
Definition: blk.c:310
CS_RETCODE blk_rowxfer(CS_BLKDESC *blkdesc)
Definition: blk.c:442
CS_RETCODE blk_bind(CS_BLKDESC *blkdesc, CS_INT colnum, CS_DATAFMT *datafmt, CS_VOID *buffer, CS_INT *datalen, CS_SMALLINT *indicator)
Definition: blk.c:70
CS_RETCODE blk_done(CS_BLKDESC *blkdesc, CS_INT type, CS_INT *outrow)
Definition: blk.c:228
CS_RETCODE blk_alloc(CS_CONNECTION *connection, CS_INT version, CS_BLKDESC **blk_pointer)
Definition: blk.c:51
int main(int argc, char **argv)
Definition: blk_in2.c:61
static CS_RETCODE hoge_blkin(CS_CONNECTION *con, CS_BLKDESC *blk, char *table, char *data)
Definition: blk_in2.c:34
static const char create_table_sql[]
Definition: blk_in2.c:31
#define CS_FAIL
Definition: cspublic.h:41
#define BLK_VERSION_100
Definition: cspublic.h:452
@ CS_FMT_PADBLANK
Definition: cspublic.h:403
#define CS_CANCEL_ALL
Definition: cspublic.h:466
#define CS_BLK_ALL
Definition: cspublic.h:519
#define CS_BLK_IN
Definition: cspublic.h:515
#define CS_CHAR_TYPE
Definition: cspublic.h:550
#define CS_SUCCEED
Definition: cspublic.h:40
#define CS_NULLTERM
Definition: cspublic.h:422
Int4 CS_INT
Definition: cstypes.h:41
CS_INT CS_RETCODE
Definition: cstypes.h:63
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static CS_CONNECTION * conn
Definition: ct_dynamic.c:25
CS_RETCODE try_ctlogin(CS_CONTEXT **ctx, CS_CONNECTION **conn, CS_COMMAND **cmd, int verbose)
Definition: common.c:194
CS_RETCODE run_command(CS_COMMAND *cmd, const char *sql)
Definition: common.c:330
CS_RETCODE try_ctlogout(CS_CONTEXT *ctx, CS_CONNECTION *conn, CS_COMMAND *cmd, int verbose)
Definition: common.c:308
CS_CONTEXT * ctx
Definition: t0006.c:12
CS_RETCODE ct_cancel(CS_CONNECTION *conn, CS_COMMAND *cmd, CS_INT type)
Definition: ct.c:2201
#define NULL
Definition: ncbistd.hpp:225
<!DOCTYPE HTML >< html > n< header > n< title > PubSeq Gateway Help Page</title > n< style > n table
int i
const char * command
static const char table_name[]
Definition: bcp.c:249
true_type verbose
Definition: processing.cpp:889
CS_INT format
Definition: cstypes.h:126
CS_INT maxlength
Definition: cstypes.h:127
CS_INT count
Definition: cstypes.h:131
CS_INT datatype
Definition: cstypes.h:125
Modified on Fri Dec 08 08:23:33 2023 by modify_doxy.py rev. 669887