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_CONNECTION *conn;
16 : CS_COMMAND *cmd;
17 : CS_DATAFMT srcfmt;
18 8 : CS_INT src = 32768;
19 : CS_DATAFMT dstfmt;
20 : CS_SMALLINT dst;
21 :
22 8 : printf("%s: Testing context callbacks\n", __FILE__);
23 8 : srcfmt.datatype = CS_INT_TYPE;
24 8 : srcfmt.maxlength = sizeof(CS_INT);
25 8 : srcfmt.locale = NULL;
26 : #if 0
27 : dstfmt.datatype = CS_SMALLINT_TYPE;
28 : #else
29 8 : dstfmt.datatype = CS_DATETIME_TYPE;
30 : #endif
31 8 : dstfmt.maxlength = sizeof(CS_SMALLINT);
32 8 : dstfmt.locale = NULL;
33 :
34 : if (verbose) {
35 8 : printf("Trying clientmsg_cb with context\n");
36 : }
37 8 : check_call(cs_ctx_alloc, (CS_VERSION_100, &ctx));
38 8 : check_call(ct_init, (ctx, CS_VERSION_100));
39 :
40 8 : check_call(ct_callback, (ctx, NULL, CS_SET, CS_CLIENTMSG_CB, (CS_VOID*) clientmsg_cb));
41 8 : clientmsg_cb_invoked = 0;
42 8 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
43 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
44 0 : return 1;
45 : }
46 8 : if (clientmsg_cb_invoked != 0) {
47 0 : fprintf(stderr, "clientmsg_cb was invoked!\n");
48 0 : return 1;
49 : }
50 :
51 : if (verbose) {
52 8 : printf("Trying cslibmsg_cb\n");
53 : }
54 8 : check_call(cs_config, (ctx, CS_SET, CS_MESSAGE_CB, (CS_VOID*) cslibmsg_cb, CS_UNUSED, NULL));
55 8 : cslibmsg_cb_invoked = 0;
56 8 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
57 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
58 0 : return 1;
59 : }
60 8 : if (cslibmsg_cb_invoked == 0) {
61 0 : fprintf(stderr, "cslibmsg_cb was not invoked!\n");
62 0 : return 1;
63 : }
64 :
65 8 : check_call(ct_exit, (ctx, CS_UNUSED));
66 8 : check_call(cs_ctx_drop, (ctx));
67 :
68 : if (verbose) {
69 8 : printf("Trying login\n");
70 : }
71 8 : check_call(try_ctlogin, (&ctx, &conn, &cmd, verbose));
72 :
73 : if (verbose) {
74 8 : printf("Trying clientmsg_cb with connection\n");
75 : }
76 8 : check_call(ct_callback, (NULL, conn, CS_SET, CS_CLIENTMSG_CB, (CS_VOID *) clientmsg_cb));
77 8 : clientmsg_cb_invoked = 0;
78 8 : check_call(run_command, (cmd, "."));
79 8 : if (clientmsg_cb_invoked) {
80 0 : fprintf(stderr, "clientmsg_cb was invoked!\n");
81 0 : return 1;
82 : }
83 :
84 : if (verbose) {
85 8 : printf("Trying servermsg_cb with connection\n");
86 : }
87 8 : check_call(ct_callback, (NULL, conn, CS_SET, CS_SERVERMSG_CB, (CS_VOID *) servermsg_cb));
88 8 : servermsg_cb_invoked = 0;
89 : #if 0
90 : check_call(run_command, (cmd, "raiserror 99999 'This is a test'"));
91 : check_call(run_command, (cmd, "raiserror('This is a test', 17, 1)"));
92 : #else
93 8 : check_call(run_command, (cmd, "print 'This is a test'"));
94 : #endif
95 8 : if (servermsg_cb_invoked == 0) {
96 0 : fprintf(stderr, "servermsg_cb was not invoked!\n");
97 0 : return 1;
98 : }
99 :
100 : if (verbose) {
101 8 : printf("Trying logout\n");
102 : }
103 8 : check_call(try_ctlogout, (ctx, conn, cmd, verbose));
104 :
105 8 : return 0;
106 : }
|