Line data Source code
1 : /*
2 : * Purpose: Test retrieving compute rows
3 : * Functions: dbaltbind dbaltcolid dbaltop dbalttype dbnumalts
4 : */
5 :
6 : #include "common.h"
7 : #include <assert.h>
8 :
9 : static int got_error = 0;
10 : static int compute_supported = 1;
11 :
12 : static int
13 2 : compute_msg_handler(DBPROCESS * dbproc TDS_UNUSED, DBINT msgno TDS_UNUSED, int state TDS_UNUSED, int severity TDS_UNUSED,
14 : char *text TDS_UNUSED, char *server TDS_UNUSED, char *proc TDS_UNUSED, int line TDS_UNUSED)
15 : {
16 2 : if (strstr(text, "compute"))
17 2 : compute_supported = 0;
18 : else
19 0 : got_error = 1;
20 2 : return 0;
21 : }
22 :
23 10 : TEST_MAIN()
24 : {
25 : LOGINREC *login;
26 : DBPROCESS *dbproc;
27 : int i;
28 : DBINT rowint;
29 : DBCHAR rowchar[2];
30 : DBCHAR rowdate[32];
31 :
32 : DBINT rowtype;
33 : DBINT computeint;
34 : DBCHAR computedate[32];
35 :
36 10 : set_malloc_options();
37 10 : read_login_info(argc, argv);
38 :
39 10 : printf("Starting %s\n", argv[0]);
40 :
41 : /* Fortify_EnterScope(); */
42 10 : dbinit();
43 :
44 10 : dberrhandle(syb_err_handler);
45 10 : dbmsghandle(syb_msg_handler);
46 :
47 10 : printf("About to logon\n");
48 :
49 10 : login = dblogin();
50 10 : DBSETLPWD(login, PASSWORD);
51 10 : DBSETLUSER(login, USER);
52 10 : DBSETLAPP(login, "t0023");
53 :
54 10 : printf("About to open\n");
55 :
56 10 : dbproc = dbopen(login, SERVER);
57 10 : if (strlen(DATABASE))
58 10 : dbuse(dbproc, DATABASE);
59 10 : dbloginfree(login);
60 :
61 10 : sql_cmd(dbproc);
62 10 : dbmsghandle(compute_msg_handler);
63 10 : i = dbsqlexec(dbproc);
64 10 : dbmsghandle(syb_msg_handler);
65 10 : if (!compute_supported) {
66 2 : printf("compute clause not supported, skip test!\n");
67 2 : dbexit();
68 2 : return 0;
69 : }
70 8 : if (got_error) {
71 0 : fprintf(stderr, "Unexpected error from query.\n");
72 0 : exit(1);
73 : }
74 16 : while ((i=dbresults(dbproc)) != NO_MORE_RESULTS) {
75 16 : while (dbnextrow(dbproc) != NO_MORE_ROWS)
76 8 : continue;
77 : }
78 :
79 8 : printf("creating table\n");
80 8 : sql_cmd(dbproc);
81 8 : dbsqlexec(dbproc);
82 8 : while (dbresults(dbproc) == SUCCEED) {
83 : /* nop */
84 : }
85 :
86 8 : printf("insert\n");
87 :
88 8 : sql_cmd(dbproc);
89 8 : dbsqlexec(dbproc);
90 8 : while (dbresults(dbproc) == SUCCEED) {
91 : /* nop */
92 : }
93 8 : sql_cmd(dbproc);
94 8 : dbsqlexec(dbproc);
95 8 : while (dbresults(dbproc) == SUCCEED) {
96 : /* nop */
97 : }
98 8 : sql_cmd(dbproc);
99 8 : dbsqlexec(dbproc);
100 8 : while (dbresults(dbproc) == SUCCEED) {
101 : /* nop */
102 : }
103 8 : sql_cmd(dbproc);
104 8 : dbsqlexec(dbproc);
105 8 : while (dbresults(dbproc) == SUCCEED) {
106 : /* nop */
107 : }
108 8 : sql_cmd(dbproc);
109 8 : dbsqlexec(dbproc);
110 8 : while (dbresults(dbproc) == SUCCEED) {
111 : /* nop */
112 : }
113 :
114 8 : printf("select\n");
115 8 : sql_cmd(dbproc);
116 8 : dbsqlexec(dbproc);
117 :
118 8 : if (dbresults(dbproc) != SUCCEED) {
119 0 : fprintf(stderr, "Was expecting a result set.\n");
120 0 : exit(1);
121 : }
122 :
123 24 : for (i = 1; i <= dbnumcols(dbproc); i++)
124 24 : printf("col %d is %s\n", i, dbcolname(dbproc, i));
125 :
126 8 : printf("binding row columns\n");
127 8 : if (SUCCEED != dbbind(dbproc, 1, INTBIND, 0, (BYTE *) & rowint)) {
128 0 : fprintf(stderr, "Had problem with bind col1\n");
129 0 : abort();
130 : }
131 8 : if (SUCCEED != dbbind(dbproc, 2, STRINGBIND, 0, (BYTE *) rowchar)) {
132 0 : fprintf(stderr, "Had problem with bind col2\n");
133 0 : abort();
134 : }
135 8 : if (SUCCEED != dbbind(dbproc, 3, STRINGBIND, 0, (BYTE *) rowdate)) {
136 0 : fprintf(stderr, "Had problem with bind col3\n");
137 0 : abort();
138 : }
139 :
140 8 : printf("testing compute clause 1\n");
141 :
142 8 : if (dbnumalts(dbproc, 1) != 1) {
143 0 : fprintf(stderr, "Had problem with dbnumalts 1\n");
144 0 : abort();
145 : }
146 :
147 8 : if (dbalttype(dbproc, 1, 1) != SYBINT4) {
148 0 : fprintf(stderr, "Had problem with dbalttype 1, 1\n");
149 0 : abort();
150 : }
151 :
152 8 : if (dbaltcolid(dbproc, 1, 1) != 1) {
153 0 : fprintf(stderr, "Had problem with dbaltcolid 1, 1\n");
154 0 : abort();
155 : }
156 :
157 8 : if (dbaltop(dbproc, 1, 1) != SYBAOPSUM) {
158 0 : fprintf(stderr, "Had problem with dbaltop 1, 1\n");
159 0 : abort();
160 : }
161 :
162 8 : if (SUCCEED != dbaltbind(dbproc, 1, 1, INTBIND, 0, (BYTE *) & computeint)) {
163 0 : fprintf(stderr, "Had problem with dbaltbind 1, 1\n");
164 0 : abort();
165 : }
166 :
167 :
168 8 : printf("testing compute clause 2\n");
169 :
170 8 : if (dbnumalts(dbproc, 2) != 1) {
171 0 : fprintf(stderr, "Had problem with dbnumalts 2\n");
172 0 : abort();
173 : }
174 :
175 8 : if (dbalttype(dbproc, 2, 1) != SYBDATETIME) {
176 0 : fprintf(stderr, "Had problem with dbalttype 2, 1\n");
177 0 : abort();
178 : }
179 :
180 8 : if (dbaltcolid(dbproc, 2, 1) != 3) {
181 0 : fprintf(stderr, "Had problem with dbaltcolid 2, 1\n");
182 0 : abort();
183 : }
184 :
185 8 : if (dbaltop(dbproc, 2, 1) != SYBAOPMAX) {
186 0 : fprintf(stderr, "Had problem with dbaltop 2, 1\n");
187 0 : abort();
188 : }
189 :
190 8 : if (SUCCEED != dbaltbind(dbproc, 2, 1, STRINGBIND, -1, (BYTE *) computedate)) {
191 0 : fprintf(stderr, "Had problem with dbaltbind 2, 1\n");
192 0 : abort();
193 : }
194 :
195 72 : while ((rowtype = dbnextrow(dbproc)) != NO_MORE_ROWS) {
196 :
197 64 : if (rowtype == REG_ROW) {
198 40 : printf("gotten a regular row\n");
199 : }
200 :
201 64 : if (rowtype == 1) {
202 16 : printf("gotten a compute row for clause 1\n");
203 16 : printf("value of sum(col1) = %d\n", computeint);
204 : }
205 :
206 64 : if (rowtype == 2) {
207 8 : printf("gotten a compute row for clause 2\n");
208 8 : printf("value of max(col3) = %s\n", computedate);
209 :
210 : }
211 : }
212 :
213 8 : dbexit();
214 :
215 8 : printf("%s %s\n", __FILE__, "OK");
216 8 : return 0;
217 : }
|