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