Line data Source code
1 : #include "common.h"
2 :
3 : #include <cspublic.h>
4 :
5 : /*
6 : * ct_send SQL |select name = @@servername|
7 : * ct_bind variable
8 : * ct_fetch and print results
9 : */
10 : int
11 8 : main(void)
12 : {
13 8 : int verbose = 1;
14 : CS_CONTEXT *ctx;
15 : CS_RETCODE ret;
16 : CS_DATAFMT srcfmt;
17 8 : CS_INT src = 32768;
18 : CS_DATAFMT dstfmt;
19 : CS_SMALLINT dst;
20 : CS_DATETIME dst_date;
21 :
22 : int i;
23 :
24 : CS_INT num_msgs;
25 : CS_CLIENTMSG client_message;
26 :
27 8 : printf("%s: Testing context callbacks\n", __FILE__);
28 :
29 8 : srcfmt.datatype = CS_INT_TYPE;
30 8 : srcfmt.maxlength = sizeof(CS_INT);
31 8 : srcfmt.locale = NULL;
32 :
33 8 : dstfmt.datatype = CS_SMALLINT_TYPE;
34 8 : dstfmt.maxlength = sizeof(CS_SMALLINT);
35 8 : dstfmt.locale = NULL;
36 :
37 : if (verbose) {
38 8 : printf("Trying clientmsg_cb with context\n");
39 : }
40 8 : check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
41 8 : check_call(ct_init, (ctx, CS_VERSION_100));
42 :
43 8 : check_call(cs_diag, (ctx, CS_INIT, CS_UNUSED, CS_UNUSED, NULL));
44 :
45 8 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
46 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
47 0 : return 1;
48 : }
49 :
50 8 : dstfmt.datatype = CS_DATETIME_TYPE;
51 8 : dstfmt.maxlength = sizeof(CS_DATETIME);
52 8 : dstfmt.locale = NULL;
53 :
54 8 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst_date, NULL) == CS_SUCCEED) {
55 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
56 0 : return 1;
57 : }
58 :
59 8 : check_call(cs_diag, (ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs));
60 :
61 24 : for (i = 0; i < num_msgs; i++ ) {
62 16 : check_call(cs_diag, (ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message));
63 :
64 16 : cslibmsg_cb(NULL, &client_message);
65 : }
66 :
67 8 : if ((ret = cs_diag(ctx, CS_GET, CS_CLIENTMSG_TYPE, i + 1, &client_message)) != CS_NOMSG) {
68 0 : fprintf(stderr, "cs_diag(CS_GET) did not fail with CS_NOMSG\n");
69 0 : return 1;
70 : }
71 :
72 8 : check_call(cs_diag, (ctx, CS_CLEAR, CS_CLIENTMSG_TYPE, CS_UNUSED, NULL));
73 :
74 8 : check_call(cs_diag, (ctx, CS_STATUS, CS_CLIENTMSG_TYPE, CS_UNUSED, &num_msgs));
75 8 : if (num_msgs != 0) {
76 0 : fprintf(stderr, "cs_diag(CS_CLEAR) failed there are still %d messages on queue\n", num_msgs);
77 0 : return 1;
78 : }
79 :
80 8 : check_call(ct_exit, (ctx, CS_UNUSED));
81 8 : check_call(cs_ctx_drop, (ctx));
82 :
83 8 : return 0;
84 : }
|