]>
Commit | Line | Data |
---|---|---|
1a6944fd RR |
1 | /** Prepare for getting query result |
2 | ||
3 | Copyright (C) 1995 by Ke Jin <kejin@empress.com> | |
4 | ||
5 | This program is free software; you can redistribute it and/or modify | |
6 | it under the terms of the GNU General Public License as published by | |
7 | the Free Software Foundation; either version 2 of the License, or | |
8 | (at your option) any later version. | |
9 | ||
10 | This program is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | GNU General Public License for more details. | |
14 | **/ | |
15 | ||
16 | #include <../iodbc/iodbc.h> | |
17 | ||
18 | #include <../iodbc/isql.h> | |
19 | #include <../iodbc/isqlext.h> | |
20 | ||
21 | #include <../iodbc/dlproc.h> | |
22 | ||
23 | #include <../iodbc/herr.h> | |
24 | #include <../iodbc/henv.h> | |
25 | #include <../iodbc/hdbc.h> | |
26 | #include <../iodbc/hstmt.h> | |
27 | ||
28 | #include <../iodbc/itrace.h> | |
29 | ||
30 | RETCODE SQL_API SQLBindCol ( | |
31 | HSTMT hstmt, | |
32 | UWORD icol, | |
33 | SWORD fCType, | |
34 | PTR rgbValue, | |
35 | SDWORD cbValueMax, | |
36 | SDWORD FAR* pcbValue ) | |
37 | { | |
38 | STMT_t FAR* pstmt = (STMT_t FAR*)hstmt; | |
39 | HPROC hproc = SQL_NULL_HPROC; | |
40 | RETCODE retcode; | |
41 | ||
42 | if( hstmt == SQL_NULL_HSTMT | |
43 | || pstmt->hdbc == SQL_NULL_HDBC ) | |
44 | { | |
45 | return SQL_INVALID_HANDLE; | |
46 | } | |
47 | ||
48 | /* check argument */ | |
49 | switch(fCType) | |
50 | { | |
51 | case SQL_C_DEFAULT: | |
52 | case SQL_C_CHAR: | |
53 | case SQL_C_BINARY: | |
54 | case SQL_C_BIT: | |
55 | case SQL_C_TINYINT: | |
56 | case SQL_C_STINYINT: | |
57 | case SQL_C_UTINYINT: | |
58 | case SQL_C_SHORT: | |
59 | case SQL_C_SSHORT: | |
60 | case SQL_C_USHORT: | |
61 | case SQL_C_LONG: | |
62 | case SQL_C_SLONG: | |
63 | case SQL_C_ULONG: | |
64 | case SQL_C_FLOAT: | |
65 | case SQL_C_DOUBLE: | |
66 | case SQL_C_DATE: | |
67 | case SQL_C_TIME: | |
68 | case SQL_C_TIMESTAMP: | |
69 | break; | |
70 | ||
71 | default: | |
72 | PUSHSQLERR ( pstmt->herr, en_S1003); | |
73 | return SQL_ERROR; | |
74 | } | |
75 | ||
76 | if( cbValueMax < 0 ) | |
77 | { | |
78 | PUSHSQLERR ( pstmt->herr, en_S1090 ); | |
79 | ||
80 | return SQL_ERROR; | |
81 | } | |
82 | ||
83 | /* check state */ | |
84 | if( pstmt->state > en_stmt_needdata | |
85 | || pstmt->asyn_on != en_NullProc ) | |
86 | { | |
87 | PUSHSQLERR ( pstmt->herr, en_S1010 ); | |
88 | return SQL_ERROR; | |
89 | } | |
90 | ||
91 | /* call driver's function */ | |
92 | hproc = _iodbcdm_getproc( pstmt->hdbc, en_BindCol ); | |
93 | ||
94 | if( hproc == SQL_NULL_HPROC ) | |
95 | { | |
96 | PUSHSQLERR ( pstmt->herr, en_IM001 ); | |
97 | ||
98 | return SQL_ERROR; | |
99 | } | |
100 | ||
101 | CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_BindCol, ( | |
102 | pstmt->dhstmt, | |
103 | icol, | |
104 | fCType, | |
105 | rgbValue, | |
106 | cbValueMax, | |
107 | pcbValue ) ) | |
108 | ||
109 | #if 0 | |
110 | retcode = hproc(pstmt->dhstmt, | |
111 | icol, | |
112 | fCType, | |
113 | rgbValue, | |
114 | cbValueMax, | |
115 | pcbValue ); | |
116 | #endif | |
117 | ||
118 | return retcode; | |
119 | } | |
120 | ||
121 | RETCODE SQL_API SQLGetCursorName( | |
122 | HSTMT hstmt, | |
123 | UCHAR FAR* szCursor, | |
124 | SWORD cbCursorMax, | |
125 | SWORD FAR* pcbCursor ) | |
126 | { | |
127 | STMT_t FAR* pstmt = (STMT_t FAR*)hstmt; | |
128 | HPROC hproc; | |
129 | RETCODE retcode; | |
130 | ||
131 | if( hstmt == SQL_NULL_HSTMT | |
132 | || pstmt->hdbc == SQL_NULL_HDBC ) | |
133 | { | |
134 | return SQL_INVALID_HANDLE; | |
135 | } | |
136 | ||
137 | /* check argument */ | |
138 | if( cbCursorMax < (SWORD)0 ) | |
139 | { | |
140 | PUSHSQLERR ( pstmt->herr, en_S1090 ); | |
141 | ||
142 | return SQL_ERROR; | |
143 | } | |
144 | ||
145 | /* check state */ | |
146 | if( pstmt->state >= en_stmt_needdata | |
147 | || pstmt->asyn_on != en_NullProc ) | |
148 | { | |
149 | PUSHSQLERR ( pstmt->herr, en_S1010 ); | |
150 | ||
151 | return SQL_ERROR; | |
152 | } | |
153 | ||
154 | if( pstmt->state < en_stmt_cursoropen | |
155 | && pstmt->cursor_state == en_stmt_cursor_no ) | |
156 | { | |
157 | PUSHSQLERR ( pstmt->herr, en_S1015 ); | |
158 | ||
159 | return SQL_ERROR; | |
160 | } | |
161 | ||
162 | /* call driver's function */ | |
163 | hproc = _iodbcdm_getproc ( pstmt->hdbc, en_GetCursorName ); | |
164 | ||
165 | if( hproc == SQL_NULL_HPROC ) | |
166 | { | |
167 | PUSHSQLERR ( pstmt->herr, en_IM001 ); | |
168 | ||
169 | return SQL_ERROR; | |
170 | } | |
171 | ||
172 | CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_GetCursorName, ( | |
173 | pstmt->dhstmt, | |
174 | szCursor, | |
175 | cbCursorMax, | |
176 | pcbCursor ) ) | |
177 | ||
178 | #if 0 | |
179 | retcode = hproc(pstmt->dhstmt, | |
180 | szCursor, | |
181 | cbCursorMax, | |
182 | pcbCursor ); | |
183 | #endif | |
184 | ||
185 | return retcode; | |
186 | } | |
187 | ||
188 | RETCODE SQL_API SQLRowCount( | |
189 | HSTMT hstmt, | |
190 | SDWORD FAR* pcrow ) | |
191 | { | |
192 | STMT_t FAR* pstmt = (STMT_t FAR*)hstmt; | |
193 | HPROC hproc; | |
194 | RETCODE retcode; | |
195 | ||
196 | if( hstmt == SQL_NULL_HSTMT | |
197 | || pstmt->hdbc == SQL_NULL_HDBC ) | |
198 | { | |
199 | return SQL_INVALID_HANDLE; | |
200 | } | |
201 | ||
202 | /* check state */ | |
203 | if( pstmt->state >= en_stmt_needdata | |
204 | || pstmt->state <= en_stmt_prepared | |
205 | || pstmt->asyn_on != en_NullProc ) | |
206 | { | |
207 | PUSHSQLERR ( pstmt->herr, en_S1010 ); | |
208 | ||
209 | return SQL_ERROR; | |
210 | } | |
211 | ||
212 | /* call driver */ | |
213 | hproc = _iodbcdm_getproc( pstmt->hdbc, en_RowCount ); | |
214 | ||
215 | if( hproc == SQL_NULL_HPROC ) | |
216 | { | |
217 | PUSHSQLERR ( pstmt->herr, en_IM001 ); | |
218 | ||
219 | return SQL_ERROR; | |
220 | } | |
221 | ||
222 | CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_RowCount, ( | |
223 | pstmt->dhstmt, pcrow) ) | |
224 | ||
225 | #if 0 | |
226 | retcode = hproc ( pstmt->dhstmt, pcrow ); | |
227 | #endif | |
228 | ||
229 | return retcode; | |
230 | } | |
231 | ||
232 | RETCODE SQL_API SQLNumResultCols( | |
233 | HSTMT hstmt, | |
234 | SWORD FAR* pccol ) | |
235 | { | |
236 | STMT_t FAR* pstmt = (STMT_t FAR*)hstmt; | |
237 | HPROC hproc; | |
238 | RETCODE retcode; | |
239 | SWORD ccol; | |
240 | ||
241 | if( hstmt == SQL_NULL_HSTMT | |
242 | || pstmt->hdbc == SQL_NULL_HDBC ) | |
243 | { | |
244 | return SQL_INVALID_HANDLE; | |
245 | } | |
246 | ||
247 | /* check state */ | |
248 | if( pstmt->asyn_on == en_NullProc ) | |
249 | { | |
250 | if( pstmt->state == en_stmt_allocated | |
251 | || pstmt->state >= en_stmt_needdata ) | |
252 | { | |
253 | PUSHSQLERR ( pstmt->herr, en_S1010 ); | |
254 | return SQL_ERROR; | |
255 | } | |
256 | } | |
257 | else if( pstmt->asyn_on != en_NumResultCols ) | |
258 | { | |
259 | PUSHSQLERR ( pstmt->herr, en_S1010 ); | |
260 | ||
261 | return SQL_ERROR; | |
262 | } | |
263 | ||
264 | /* call driver */ | |
265 | hproc = _iodbcdm_getproc( pstmt->hdbc, en_NumResultCols ); | |
266 | ||
267 | if( hproc == SQL_NULL_HPROC ) | |
268 | { | |
269 | PUSHSQLERR ( pstmt->herr, en_IM001 ); | |
270 | ||
271 | return SQL_ERROR; | |
272 | } | |
273 | ||
274 | CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_NumResultCols, ( | |
275 | pstmt->dhstmt, &ccol) ) | |
276 | ||
277 | #if 0 | |
278 | retcode = hproc( pstmt->dhstmt, &ccol ); | |
279 | #endif | |
280 | ||
281 | /* state transition */ | |
282 | if( pstmt->asyn_on == en_NumResultCols ) | |
283 | { | |
284 | switch( retcode ) | |
285 | { | |
286 | case SQL_SUCCESS: | |
287 | case SQL_SUCCESS_WITH_INFO: | |
288 | case SQL_ERROR: | |
289 | pstmt->asyn_on = en_NullProc; | |
290 | ||
291 | case SQL_STILL_EXECUTING: | |
292 | default: | |
293 | break; | |
294 | } | |
295 | } | |
296 | ||
297 | switch( retcode ) | |
298 | { | |
299 | case SQL_SUCCESS: | |
300 | case SQL_SUCCESS_WITH_INFO: | |
301 | break; | |
302 | ||
303 | case SQL_STILL_EXECUTING: | |
304 | ccol = 0; | |
305 | pstmt->asyn_on = en_NumResultCols; | |
306 | break; | |
307 | ||
308 | default: | |
309 | ccol = 0; | |
310 | break; | |
311 | } | |
312 | ||
313 | if( pccol ) | |
314 | { | |
315 | *pccol = ccol; | |
316 | } | |
317 | ||
318 | return retcode; | |
319 | } | |
320 | ||
321 | RETCODE SQL_API SQLDescribeCol( | |
322 | HSTMT hstmt, | |
323 | UWORD icol, | |
324 | UCHAR FAR* szColName, | |
325 | SWORD cbColNameMax, | |
326 | SWORD FAR* pcbColName, | |
327 | SWORD FAR* pfSqlType, | |
328 | UDWORD FAR* pcbColDef, | |
329 | SWORD FAR* pibScale, | |
330 | SWORD FAR* pfNullable ) | |
331 | { | |
332 | STMT_t FAR* pstmt = (STMT_t FAR*)hstmt; | |
333 | HPROC hproc; | |
334 | RETCODE retcode; | |
335 | int sqlstat = en_00000; | |
336 | ||
337 | if( hstmt == SQL_NULL_HSTMT | |
338 | || pstmt->hdbc == SQL_NULL_HDBC ) | |
339 | { | |
340 | return SQL_INVALID_HANDLE; | |
341 | } | |
342 | ||
343 | /* check arguments */ | |
344 | if( icol == 0 ) | |
345 | { | |
346 | sqlstat = en_S1002; | |
347 | } | |
348 | else if( cbColNameMax < 0 ) | |
349 | { | |
350 | sqlstat = en_S1090; | |
351 | } | |
352 | ||
353 | if( sqlstat != en_00000 ) | |
354 | { | |
355 | PUSHSQLERR ( pstmt->herr, sqlstat ); | |
356 | ||
357 | return SQL_ERROR; | |
358 | } | |
359 | ||
360 | /* check state */ | |
361 | if( pstmt->asyn_on == en_NullProc ) | |
362 | { | |
363 | if( pstmt->asyn_on == en_stmt_allocated | |
364 | || pstmt->asyn_on >= en_stmt_needdata ) | |
365 | { | |
366 | sqlstat = en_S1010; | |
367 | } | |
368 | } | |
369 | else if( pstmt->asyn_on != en_DescribeCol ) | |
370 | { | |
371 | sqlstat = en_S1010; | |
372 | } | |
373 | ||
374 | if( sqlstat != en_00000 ) | |
375 | { | |
376 | PUSHSQLERR ( pstmt->herr, sqlstat ); | |
377 | ||
378 | return SQL_ERROR; | |
379 | } | |
380 | ||
381 | /* call driver */ | |
382 | hproc = _iodbcdm_getproc( pstmt->hdbc, en_DescribeCol ); | |
383 | ||
384 | if( hproc == SQL_NULL_HPROC ) | |
385 | { | |
386 | PUSHSQLERR ( pstmt->herr, en_IM001 ); | |
387 | ||
388 | return SQL_ERROR; | |
389 | } | |
390 | ||
391 | CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_DescribeCol, ( | |
392 | pstmt->dhstmt, | |
393 | icol, | |
394 | szColName, | |
395 | cbColNameMax, | |
396 | pcbColName, | |
397 | pfSqlType, | |
398 | pcbColDef, | |
399 | pibScale, | |
400 | pfNullable) ) | |
401 | ||
402 | #if 0 | |
403 | retcode = hproc(pstmt->dhstmt, | |
404 | icol, | |
405 | szColName, | |
406 | cbColNameMax, | |
407 | pcbColName, | |
408 | pfSqlType, | |
409 | pcbColDef, | |
410 | pibScale, | |
411 | pfNullable ); | |
412 | #endif | |
413 | ||
414 | /* state transition */ | |
415 | if( pstmt->asyn_on == en_DescribeCol ) | |
416 | { | |
417 | switch( retcode ) | |
418 | { | |
419 | case SQL_SUCCESS: | |
420 | case SQL_SUCCESS_WITH_INFO: | |
421 | case SQL_ERROR: | |
422 | pstmt->asyn_on = en_NullProc; | |
423 | break; | |
424 | ||
425 | default: | |
426 | return retcode; | |
427 | } | |
428 | } | |
429 | ||
430 | switch( pstmt->state ) | |
431 | { | |
432 | case en_stmt_prepared: | |
433 | case en_stmt_cursoropen: | |
434 | case en_stmt_fetched: | |
435 | case en_stmt_xfetched: | |
436 | if( retcode == SQL_STILL_EXECUTING ) | |
437 | { | |
438 | pstmt->asyn_on = en_DescribeCol; | |
439 | } | |
440 | break; | |
441 | ||
442 | default: | |
443 | break; | |
444 | } | |
445 | ||
446 | return retcode; | |
447 | } | |
448 | ||
449 | RETCODE SQL_API SQLColAttributes( | |
450 | HSTMT hstmt, | |
451 | UWORD icol, | |
452 | UWORD fDescType, | |
453 | PTR rgbDesc, | |
454 | SWORD cbDescMax, | |
455 | SWORD FAR* pcbDesc, | |
456 | SDWORD FAR* pfDesc ) | |
457 | { | |
458 | STMT_t FAR* pstmt = (STMT_t FAR*)hstmt; | |
459 | HPROC hproc; | |
460 | RETCODE retcode; | |
461 | int sqlstat = en_00000; | |
462 | ||
463 | if( hstmt == SQL_NULL_HSTMT | |
464 | || pstmt->hdbc == SQL_NULL_HDBC ) | |
465 | { | |
466 | return SQL_INVALID_HANDLE; | |
467 | } | |
468 | ||
469 | /* check arguments */ | |
470 | if( icol == 0 && fDescType != SQL_COLUMN_COUNT ) | |
471 | { | |
472 | sqlstat = en_S1002; | |
473 | } | |
474 | else if( cbDescMax < 0 ) | |
475 | { | |
476 | sqlstat = en_S1090; | |
477 | } | |
478 | else if(/* fDescType < SQL_COLATT_OPT_MIN || */ /* turnoff warning */ | |
479 | ( fDescType > SQL_COLATT_OPT_MAX | |
480 | && fDescType < SQL_COLUMN_DRIVER_START ) ) | |
481 | { | |
482 | sqlstat = en_S1091; | |
483 | } | |
484 | ||
485 | if( sqlstat != en_00000 ) | |
486 | { | |
487 | PUSHSQLERR ( pstmt->herr, sqlstat ); | |
488 | ||
489 | return SQL_ERROR; | |
490 | } | |
491 | ||
492 | /* check state */ | |
493 | if( pstmt->asyn_on == en_NullProc ) | |
494 | { | |
495 | if( pstmt->asyn_on == en_stmt_allocated | |
496 | || pstmt->asyn_on >= en_stmt_needdata ) | |
497 | { | |
498 | sqlstat = en_S1010; | |
499 | } | |
500 | } | |
501 | else if( pstmt->asyn_on != en_ColAttributes ) | |
502 | { | |
503 | sqlstat = en_S1010; | |
504 | } | |
505 | ||
506 | if( sqlstat != en_00000 ) | |
507 | { | |
508 | PUSHSQLERR ( pstmt->herr, sqlstat ); | |
509 | ||
510 | return SQL_ERROR; | |
511 | } | |
512 | ||
513 | /* call driver */ | |
514 | hproc = _iodbcdm_getproc( pstmt->hdbc, en_ColAttributes ); | |
515 | ||
516 | if( hproc == SQL_NULL_HPROC ) | |
517 | { | |
518 | PUSHSQLERR ( pstmt->herr, en_IM001 ); | |
519 | ||
520 | return SQL_ERROR; | |
521 | } | |
522 | ||
523 | CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_ColAttributes, ( | |
524 | pstmt->dhstmt, | |
525 | icol, | |
526 | fDescType, | |
527 | rgbDesc, | |
528 | cbDescMax, | |
529 | pcbDesc, | |
530 | pfDesc) ) | |
531 | ||
532 | #if 0 | |
533 | retcode = hproc(pstmt->dhstmt, | |
534 | icol, | |
535 | fDescType, | |
536 | rgbDesc, | |
537 | cbDescMax, | |
538 | pcbDesc, | |
539 | pfDesc ); | |
540 | #endif | |
541 | ||
542 | /* state transition */ | |
543 | if( pstmt->asyn_on == en_ColAttributes ) | |
544 | { | |
545 | switch( retcode ) | |
546 | { | |
547 | case SQL_SUCCESS: | |
548 | case SQL_SUCCESS_WITH_INFO: | |
549 | case SQL_ERROR: | |
550 | pstmt->asyn_on = en_NullProc; | |
551 | break; | |
552 | ||
553 | default: | |
554 | return retcode; | |
555 | } | |
556 | } | |
557 | ||
558 | switch( pstmt->state ) | |
559 | { | |
560 | case en_stmt_prepared: | |
561 | case en_stmt_cursoropen: | |
562 | case en_stmt_fetched: | |
563 | case en_stmt_xfetched: | |
564 | if( retcode == SQL_STILL_EXECUTING ) | |
565 | { | |
566 | pstmt->asyn_on = en_ColAttributes; | |
567 | } | |
568 | break; | |
569 | ||
570 | default: | |
571 | break; | |
572 | } | |
573 | ||
574 | return retcode; | |
575 | } |