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