Line data Source code
1 : /*
2 : * Purpose: Test we can cancel a query inside message handler
3 : * Some server some additional tokens which can prevent second query to work
4 : * correctly.
5 : */
6 :
7 : #include "common.h"
8 :
9 : static int
10 8 : cancel_msg_handler(DBPROCESS * dbproc, DBINT msgno TDS_UNUSED, int msgstate TDS_UNUSED, int severity TDS_UNUSED,
11 : char *msgtext TDS_UNUSED, char *srvname TDS_UNUSED, char *procname TDS_UNUSED, int line TDS_UNUSED)
12 : {
13 8 : dbcancel(dbproc);
14 8 : return 0;
15 : }
16 :
17 : int
18 8 : main(int argc, char **argv)
19 : {
20 : LOGINREC *login;
21 : DBPROCESS *dbproc;
22 : int i;
23 8 : DBINT testint = -1;
24 :
25 8 : read_login_info(argc, argv);
26 :
27 8 : printf("Starting %s\n", argv[0]);
28 :
29 8 : dbinit();
30 :
31 8 : dberrhandle(syb_err_handler);
32 8 : dbmsghandle(syb_msg_handler);
33 :
34 8 : printf("About to logon\n");
35 :
36 8 : login = dblogin();
37 8 : DBSETLPWD(login, PASSWORD);
38 8 : DBSETLUSER(login, USER);
39 8 : DBSETLAPP(login, "cancel");
40 :
41 8 : printf("About to open\n");
42 :
43 8 : dbproc = dbopen(login, SERVER);
44 8 : if (strlen(DATABASE))
45 8 : dbuse(dbproc, DATABASE);
46 8 : dbloginfree(login);
47 :
48 : /* first query, select with error */
49 8 : dbmsghandle(cancel_msg_handler);
50 8 : sql_cmd(dbproc);
51 8 : dbsqlexec(dbproc);
52 :
53 8 : dbmsghandle(syb_msg_handler);
54 :
55 : /* second query, select */
56 8 : printf("second select\n");
57 :
58 8 : if (SUCCEED != sql_cmd(dbproc) || SUCCEED != dbsqlexec(dbproc)) {
59 0 : fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__);
60 0 : exit(1);
61 : }
62 :
63 8 : if (dbresults(dbproc) != SUCCEED) {
64 0 : fprintf(stderr, "Was expecting a result set.");
65 0 : exit(1);
66 : }
67 :
68 8 : for (i = 1; i <= dbnumcols(dbproc); i++)
69 8 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
70 :
71 8 : dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
72 :
73 8 : if (REG_ROW != dbnextrow(dbproc)) {
74 0 : fprintf(stderr, "Failed. Expected a row\n");
75 0 : exit(1);
76 : }
77 8 : if (testint != 1) {
78 0 : fprintf(stderr, "Failed. Expected i to be %d, was %d\n", i, (int) testint);
79 0 : exit(1);
80 : }
81 8 : if (dbnextrow(dbproc) != NO_MORE_ROWS) {
82 0 : fprintf(stderr, "No other rows expected\n");
83 : }
84 :
85 8 : dbexit();
86 :
87 8 : printf("ok\n");
88 : return 0;
89 : }
|