35 printf(
"Trying logout\n");
43 fprintf(stderr,
"Logout failed\n");
57 vfprintf(stderr, fmt, ap);
65 main(
int argc,
char *argv[])
87 if (argc > 1 && (0 ==
strcmp(argv[1],
"-v")))
90 printf(
"%s: use ct_dynamic to prepare and execute a statement\n", __FILE__);
92 printf(
"Trying login\n");
96 fprintf(stderr,
"Login failed\n");
108 ret =
run_command(
cmd,
"IF OBJECT_ID('tempdb..#ct_dynamic') IS NOT NULL DROP table #ct_dynamic");
110 strcpy(cmdbuf,
"create table #ct_dynamic (id numeric identity not null, \
111 name varchar(30), age int, cost money, bdate datetime, fval float) ");
116 strcpy(cmdbuf,
"insert into #ct_dynamic ( name , age , cost , bdate , fval ) ");
117 strcat(cmdbuf,
"values ('Bill', 44, 2000.00, 'May 21 1960', 60.97 ) ");
122 strcpy(cmdbuf,
"insert into #ct_dynamic ( name , age , cost , bdate , fval ) ");
123 strcat(cmdbuf,
"values ('Freddy', 32, 1000.00, 'Jan 21 1972', 70.97 ) ");
128 strcpy(cmdbuf,
"insert into #ct_dynamic ( name , age , cost , bdate , fval ) ");
129 strcat(cmdbuf,
"values ('James', 42, 5000.00, 'May 21 1962', 80.97 ) ");
134 strcpy(cmdbuf,
"select name from #ct_dynamic where age = ?");
142 switch ((
int) res_type) {
163 switch ((
int) res_type) {
169 for (
i = 1;
i <= num_cols;
i++) {
172 fprintf(stderr,
"CS_DESCRIBE_INPUT parameter %d :\n",
i);
174 fprintf(stderr,
"\t\tNo name...\n");
176 fprintf(stderr,
"\t\tName = %*.*s\n", descfmt.
namelen, descfmt.
namelen, descfmt.
name);
177 fprintf(stderr,
"\t\tType = %d\n", descfmt.
datatype);
178 fprintf(stderr,
"\t\tLength = %d\n", descfmt.
maxlength);
200 switch ((
int) res_type) {
205 chk(num_cols == 1,
"CS_DESCRIBE_OUTPUT showed %d columns , expected 1\n", num_cols);
207 for (
i = 1;
i <= num_cols;
i++) {
212 fprintf(stderr,
"\t\tNo name...\n");
214 fprintf(stderr,
"\t\tName = %*.*s\n", descfmt.
namelen, descfmt.
namelen, descfmt.
name);
215 fprintf(stderr,
"\t\tType = %d\n", descfmt.
datatype);
216 fprintf(stderr,
"\t\tLength = %d\n", descfmt.
maxlength);
251 chk(res_type !=
CS_CMD_FAIL,
"1: ct_results() result_type CS_CMD_FAIL.\n");
254 switch ((
int) res_type) {
265 ret =
ct_bind(
cmd2, 1, &datafmt, name, &datalength, &ind);
271 chk(ret !=
CS_ROW_FAIL,
"ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
273 chk(!
strcmp(name,
"Bill"),
"fetched value '%s' expected 'Bill'\n", name);
278 chk(ret ==
CS_END_DATA,
"ct_fetch() unexpected return %d.\n", (
int) ret);
281 fprintf(stderr,
"ct_results() unexpected result_type.\n");
285 chk(results_ret ==
CS_END_RESULTS,
"ct_results() unexpected return.\n", (
int) results_ret);
292 chk(res_type !=
CS_CMD_FAIL,
"2: ct_results() result_type CS_CMD_FAIL.\n");
295 switch ((
int) res_type) {
306 ret =
ct_bind(
cmd2, 1, &datafmt, name, &datalength, &ind);
312 chk(ret !=
CS_ROW_FAIL,
"ct_fetch() CS_ROW_FAIL on row %d.\n", row_count);
315 chk(!
strcmp(name,
"Freddy"),
"fetched value '%s' expected 'Freddy'\n", name);
320 chk(ret ==
CS_END_DATA,
"ct_fetch() unexpected return %d.\n", (
int) ret);
323 fprintf(stderr,
"ct_results() unexpected result_type.\n");
327 chk(results_ret ==
CS_END_RESULTS,
"ct_results() unexpected return.\n", (
int) results_ret);
335 switch ((
int) res_type) {
353 strcpy(cmdbuf,
"select name from #ct_dynamic where age = ?");
360 switch ((
int) res_type) {
408 printf(
"\nOpen Client Message:\n");
411 printf(
"Message String: %s\n", errmsg->
msgstring);
413 printf(
"Operating System Error: %s\n", errmsg->
osstring);
423 printf(
"\nServer message:\n");
424 printf(
"Message number: %d, Severity %d, ", srvmsg->
msgnumber, srvmsg->
severity);
425 printf(
"State %d, Line %d\n", srvmsg->
state, srvmsg->
line);
428 printf(
"Server '%s'\n", srvmsg->
svrname);
432 printf(
" Procedure '%s'\n", srvmsg->
proc);
435 printf(
"Message String: %s\n", srvmsg->
text);
#define CS_DESCRIBE_OUTPUT
#define CS_DESCRIBE_RESULT
#define CS_COMPUTE_RESULT
#define CS_DESCRIBE_INPUT
CS_RETCODE try_ctlogin(CS_CONTEXT **ctx, CS_CONNECTION **conn, CS_COMMAND **cmd, int verbose)
CS_RETCODE run_command(CS_COMMAND *cmd, const char *sql)
CS_RETCODE try_ctlogout(CS_CONTEXT *ctx, CS_CONNECTION *conn, CS_COMMAND *cmd, int verbose)
static CS_RETCODE ex_clientmsg_cb(CS_CONTEXT *context, CS_CONNECTION *connection, CS_CLIENTMSG *errmsg)
int main(int argc, char *argv[])
static CS_RETCODE ex_servermsg_cb(CS_CONTEXT *context, CS_CONNECTION *connection, CS_SERVERMSG *errmsg)
static void cleanup(void)
static void chk(int check, const char *fmt,...)
static CS_CONNECTION * conn
CS_RETCODE ct_dynamic(CS_COMMAND *cmd, CS_INT type, CS_CHAR *id, CS_INT idlen, CS_CHAR *buffer, CS_INT buflen)
CS_RETCODE ct_results(CS_COMMAND *cmd, CS_INT *result_type)
CS_RETCODE ct_res_info(CS_COMMAND *cmd, CS_INT type, CS_VOID *buffer, CS_INT buflen, CS_INT *out_len)
CS_RETCODE ct_callback(CS_CONTEXT *ctx, CS_CONNECTION *con, CS_INT action, CS_INT type, CS_VOID *func)
CS_RETCODE ct_fetch(CS_COMMAND *cmd, CS_INT type, CS_INT offset, CS_INT option, CS_INT *rows_read)
CS_RETCODE ct_cmd_drop(CS_COMMAND *cmd)
CS_RETCODE ct_cmd_alloc(CS_CONNECTION *con, CS_COMMAND **cmd)
CS_RETCODE ct_send(CS_COMMAND *cmd)
CS_RETCODE ct_bind(CS_COMMAND *cmd, CS_INT item, CS_DATAFMT *datafmt, CS_VOID *buffer, CS_INT *copied, CS_SMALLINT *indicator)
CS_RETCODE ct_describe(CS_COMMAND *cmd, CS_INT item, CS_DATAFMT *datafmt)
CS_RETCODE ct_setparam(CS_COMMAND *cmd, CS_DATAFMT *datafmt, CS_VOID *data, CS_INT *datalen, CS_SMALLINT *indicator)
int strcmp(const char *str1, const char *str2)
static CS_CONTEXT * context