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