1 : #if HAVE_CONFIG_H
2 : #include <config.h>
3 : #endif /* HAVE_CONFIG_H */
4 :
5 : #include <stdio.h>
6 : #include <cspublic.h>
7 : #include <ctpublic.h>
8 : #include "common.h"
9 :
10 : static char software_version[] = "$Id: t0008.c,v 1.9 2003/01/26 18:42:54 freddy77 Exp $";
11 : static void *no_unused_var_warn[] = { software_version, no_unused_var_warn };
12 :
13 : /*
14 : * ct_send SQL |select name = @@servername|
15 : * ct_bind variable
16 : * ct_fetch and print results
17 : */
18 : int
19 : main(int argc, char **argv)
20 2 : {
21 2 : int verbose = 1;
22 : CS_CONTEXT *ctx;
23 : CS_CONNECTION *conn;
24 : CS_COMMAND *cmd;
25 : CS_RETCODE ret;
26 : CS_DATAFMT srcfmt;
27 2 : CS_INT src = 32768;
28 : CS_DATAFMT dstfmt;
29 : CS_SMALLINT dst;
30 :
31 2 : fprintf(stdout, "%s: Testing context callbacks\n", __FILE__);
32 2 : srcfmt.datatype = CS_INT_TYPE;
33 2 : srcfmt.maxlength = sizeof(CS_INT);
34 2 : srcfmt.locale = NULL;
35 : #if 0
36 : dstfmt.datatype = CS_SMALLINT_TYPE;
37 : #else
38 2 : dstfmt.datatype = CS_DATETIME_TYPE;
39 : #endif
40 2 : dstfmt.maxlength = sizeof(CS_SMALLINT);
41 2 : dstfmt.locale = NULL;
42 :
43 2 : if (verbose) {
44 2 : fprintf(stdout, "Trying clientmsg_cb with context\n");
45 : }
46 2 : if (cs_ctx_alloc(CS_VERSION_100, &ctx) != CS_SUCCEED) {
47 0 : fprintf(stderr, "cs_ctx_alloc() failed\n");
48 : }
49 2 : if (ct_init(ctx, CS_VERSION_100) != CS_SUCCEED) {
50 0 : fprintf(stderr, "ct_init() failed\n");
51 : }
52 :
53 2 : if (ct_callback(ctx, NULL, CS_SET, CS_CLIENTMSG_CB, (CS_VOID*) clientmsg_cb)
54 : != CS_SUCCEED) {
55 0 : fprintf(stderr, "ct_callback() failed\n");
56 0 : return 1;
57 : }
58 2 : clientmsg_cb_invoked = 0;
59 2 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
60 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
61 0 : return 1;
62 : }
63 2 : if (clientmsg_cb_invoked != 0) {
64 0 : fprintf(stderr, "clientmsg_cb was invoked!\n");
65 0 : return 1;
66 : }
67 :
68 2 : if (verbose) {
69 2 : fprintf(stdout, "Trying cslibmsg_cb\n");
70 : }
71 2 : if (cs_config(ctx, CS_SET, CS_MESSAGE_CB, (CS_VOID*) cslibmsg_cb, CS_UNUSED, NULL)
72 : != CS_SUCCEED) {
73 0 : fprintf(stderr, "cs_config() failed\n");
74 0 : return 1;
75 : }
76 2 : cslibmsg_cb_invoked = 0;
77 2 : if (cs_convert(ctx, &srcfmt, &src, &dstfmt, &dst, NULL) == CS_SUCCEED) {
78 0 : fprintf(stderr, "cs_convert() succeeded when failure was expected\n");
79 0 : return 1;
80 : }
81 2 : if (cslibmsg_cb_invoked == 0) {
82 0 : fprintf(stderr, "cslibmsg_cb was not invoked!\n");
83 0 : return 1;
84 : }
85 :
86 2 : if (ct_exit(ctx, CS_UNUSED) != CS_SUCCEED) {
87 0 : fprintf(stderr, "ct_exit() failed\n");
88 : }
89 2 : if (cs_ctx_drop(ctx) != CS_SUCCEED) {
90 0 : fprintf(stderr, "cx_ctx_drop() failed\n");
91 : }
92 :
93 2 : if (verbose) {
94 2 : fprintf(stdout, "Trying login\n");
95 : }
96 2 : ret = try_ctlogin(&ctx, &conn, &cmd, verbose);
97 2 : if (ret != CS_SUCCEED) {
98 0 : fprintf(stderr, "Login failed\n");
99 0 : return 1;
100 : }
101 :
102 2 : if (verbose) {
103 2 : fprintf(stdout, "Trying clientmsg_cb with connection\n");
104 : }
105 2 : ret = ct_callback(NULL, conn, CS_SET, CS_CLIENTMSG_CB, (CS_VOID *) clientmsg_cb);
106 2 : if (ret != CS_SUCCEED) {
107 0 : fprintf(stderr, "ct_callback() failed\n");
108 0 : return 1;
109 : }
110 2 : clientmsg_cb_invoked = 0;
111 2 : ret = run_command(cmd, ".");
112 2 : if (ret != CS_SUCCEED) {
113 0 : fprintf(stderr, "run_command() failed\n");
114 0 : return 1;
115 : }
116 2 : if (clientmsg_cb_invoked) {
117 0 : fprintf(stderr, "clientmsg_cb was invoked!\n");
118 0 : return 1;
119 : }
120 :
121 2 : if (verbose) {
122 2 : fprintf(stdout, "Trying servermsg_cb with connection\n");
123 : }
124 2 : ret = ct_callback(NULL, conn, CS_SET, CS_SERVERMSG_CB, (CS_VOID *) servermsg_cb);
125 2 : if (ret != CS_SUCCEED) {
126 0 : fprintf(stderr, "ct_callback() failed\n");
127 0 : return 1;
128 : }
129 2 : servermsg_cb_invoked = 0;
130 : #if 0
131 : ret = run_command(cmd, "raiserror 99999 'This is a test'");
132 : ret = run_command(cmd, "raiserror('This is a test', 17, 1)");
133 : #else
134 2 : ret = run_command(cmd, "print 'This is a test'");
135 : #endif
136 2 : if (ret != CS_SUCCEED) {
137 0 : fprintf(stderr, "run_command() failed\n");
138 0 : return 1;
139 : }
140 2 : if (servermsg_cb_invoked == 0) {
141 0 : fprintf(stderr, "servermsg_cb was not invoked!\n");
142 0 : return 1;
143 : }
144 :
145 2 : if (verbose) {
146 2 : fprintf(stdout, "Trying logout\n");
147 : }
148 2 : ret = try_ctlogout(ctx, conn, cmd, verbose);
149 2 : if (ret != CS_SUCCEED) {
150 0 : fprintf(stderr, "Logout failed\n");
151 0 : return 1;
152 : }
153 :
154 2 : return 0;
155 : }
|