Line data Source code
1 : /*
2 : * Purpose: Test retrieving data and attempting to initiate a new query with results pending
3 : * Functions: dbnextrow dbresults dbsqlexec dbgetchar
4 : */
5 :
6 : #include "common.h"
7 : #include <ctype.h>
8 :
9 : int
10 10 : main(int argc, char **argv)
11 : {
12 10 : const int rows_to_add = 50;
13 : LOGINREC *login;
14 : DBPROCESS *dbproc;
15 : int i, expected_error;
16 : char *s, teststr[1024];
17 : DBINT testint;
18 10 : int failed = 0;
19 :
20 10 : set_malloc_options();
21 :
22 10 : read_login_info(argc, argv);
23 :
24 10 : printf("Starting %s\n", argv[0]);
25 :
26 10 : dbinit();
27 :
28 10 : dberrhandle(syb_err_handler);
29 10 : dbmsghandle(syb_msg_handler);
30 :
31 10 : printf("About to logon\n");
32 :
33 10 : login = dblogin();
34 10 : DBSETLPWD(login, PASSWORD);
35 10 : DBSETLUSER(login, USER);
36 10 : DBSETLAPP(login, "t0004");
37 :
38 10 : printf("About to open\n");
39 :
40 10 : dbproc = dbopen(login, SERVER);
41 10 : if (strlen(DATABASE))
42 10 : dbuse(dbproc, DATABASE);
43 10 : dbloginfree(login);
44 :
45 10 : printf("creating table\n");
46 10 : sql_cmd(dbproc);
47 10 : dbsqlexec(dbproc);
48 10 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
49 : /* nop */
50 : }
51 :
52 10 : printf("insert\n");
53 500 : for (i = 1; i < rows_to_add; i++) {
54 490 : sql_cmd(dbproc);
55 490 : dbsqlexec(dbproc);
56 490 : while (dbresults(dbproc) != NO_MORE_RESULTS) {
57 : /* nop */
58 : }
59 : }
60 :
61 10 : sql_cmd(dbproc); /* select */
62 10 : dbsqlexec(dbproc);
63 :
64 10 : if (dbresults(dbproc) != SUCCEED) {
65 0 : printf("Was expecting a result set.");
66 0 : exit(1);
67 : }
68 :
69 20 : for (i = 1; i <= dbnumcols(dbproc); i++)
70 20 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
71 :
72 10 : dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & testint);
73 10 : dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) teststr);
74 :
75 250 : for (i = 1; i <= 24; i++) {
76 : char expected[1024];
77 :
78 240 : sprintf(expected, "row %04d", i);
79 :
80 240 : if (i % 5 == 0) {
81 40 : dbclrbuf(dbproc, 5);
82 : }
83 :
84 :
85 240 : testint = -1;
86 240 : strcpy(teststr, "bogus");
87 :
88 240 : if (REG_ROW != dbnextrow(dbproc)) {
89 0 : fprintf(stderr, "Failed. Expected a row\n");
90 0 : exit(1);
91 : }
92 240 : if (testint != i) {
93 0 : fprintf(stderr, "Failed. Expected i to be %d, was %d\n", i, (int) testint);
94 0 : abort();
95 : }
96 240 : if (0 != strncmp(teststr, expected, strlen(expected))) {
97 0 : printf("Failed. Expected s to be |%s|, was |%s|\n", expected, teststr);
98 0 : abort();
99 : }
100 240 : printf("Read a row of data -> %d %s\n", (int) testint, teststr);
101 : }
102 :
103 :
104 :
105 10 : printf("second select\n");
106 10 : printf("testing dbgetchar...\n");
107 490 : for (i=0; (s = dbgetchar(dbproc, i)) != NULL; i++) {
108 960 : putchar(*s);
109 480 : if (!(isprint((unsigned char)*s) || iscntrl((unsigned char)*s))) {
110 0 : fprintf(stderr, "%s:%d: dbgetchar failed with %x at position %d\n", __FILE__, __LINE__, *s, i);
111 0 : failed = 1;
112 0 : break;
113 : }
114 : }
115 10 : printf("<== end of command buffer\n");
116 :
117 10 : if (SUCCEED != sql_cmd(dbproc)) {
118 0 : fprintf(stderr, "%s:%d: dbcmd failed\n", __FILE__, __LINE__);
119 0 : failed = 1;
120 : }
121 10 : printf("About to exec for the second time. Should fail\n");
122 10 : expected_error = 20019;
123 10 : dbsetuserdata(dbproc, (BYTE*) &expected_error);
124 10 : if (FAIL != dbsqlexec(dbproc)) {
125 0 : fprintf(stderr, "%s:%d: dbsqlexec should have failed but didn't\n", __FILE__, __LINE__);
126 0 : failed = 1;
127 : }
128 0 : dbexit();
129 :
130 10 : printf("%s %s\n", __FILE__, (failed ? "failed!" : "OK"));
131 10 : return failed ? 1 : 0;
132 : }
|