]> git.saurik.com Git - wxWidgets.git/blob - src/iodbc/prepare.c
added slash to path
[wxWidgets.git] / src / iodbc / prepare.c
1 /** Prepare a query
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 SQLPrepare (
31 HSTMT hstmt,
32 UCHAR FAR* szSqlStr,
33 SDWORD cbSqlStr )
34 {
35 STMT_t FAR* pstmt = (STMT_t*)hstmt;
36
37 HPROC hproc = SQL_NULL_HPROC;
38 RETCODE retcode = SQL_SUCCESS;
39 int sqlstat = en_00000;
40
41 if( hstmt == SQL_NULL_HSTMT
42 || pstmt->hdbc == SQL_NULL_HDBC )
43 {
44 return SQL_INVALID_HANDLE;
45 }
46
47 /* check state */
48 if( pstmt->asyn_on == en_NullProc )
49 {
50 /* not on asyn state */
51 switch( pstmt->state )
52 {
53 case en_stmt_fetched:
54 case en_stmt_xfetched:
55 sqlstat = en_24000;
56 break;
57
58 case en_stmt_needdata:
59 case en_stmt_mustput:
60 case en_stmt_canput:
61 sqlstat = en_S1010;
62 break;
63
64 default:
65 break;
66 }
67 }
68 else if( pstmt->asyn_on != en_Prepare )
69 {
70 /* asyn on other */
71 sqlstat = en_S1010;
72 }
73
74 if( sqlstat != en_00000 )
75 {
76 PUSHSQLERR ( pstmt->herr, sqlstat );
77
78 return SQL_ERROR;
79 }
80
81 if( szSqlStr == NULL )
82 {
83 PUSHSQLERR ( pstmt->herr, en_S1009 );
84
85 return SQL_ERROR;
86 }
87
88 if( cbSqlStr < 0 && cbSqlStr != SQL_NTS )
89 {
90 PUSHSQLERR ( pstmt->herr, en_S1090 );
91
92 return SQL_ERROR;
93 }
94
95 hproc = _iodbcdm_getproc( pstmt->hdbc, en_Prepare );
96
97 if( hproc == SQL_NULL_HPROC )
98 {
99 PUSHSQLERR ( pstmt->herr, en_IM001 );
100 return SQL_ERROR;
101 }
102
103 CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_Prepare, (
104 pstmt->dhstmt, szSqlStr, cbSqlStr) )
105
106 #if 0
107 retcode = hproc ( pstmt->dhstmt, szSqlStr, cbSqlStr );
108 #endif
109
110 /* stmt state transition */
111 if( pstmt->asyn_on == en_Prepare )
112 {
113 switch( retcode )
114 {
115 case SQL_SUCCESS:
116 case SQL_SUCCESS_WITH_INFO:
117 case SQL_ERROR:
118 pstmt->asyn_on = en_NullProc;
119 return retcode;
120
121 case SQL_STILL_EXECUTING:
122 default:
123 return retcode;
124 }
125 }
126
127 switch( retcode )
128 {
129 case SQL_STILL_EXECUTING:
130 pstmt->asyn_on = en_Prepare;
131 break;
132
133 case SQL_SUCCESS:
134 case SQL_SUCCESS_WITH_INFO:
135 pstmt->state = en_stmt_prepared;
136 pstmt->prep_state = 1;
137 break;
138
139 case SQL_ERROR:
140 switch( pstmt->state )
141 {
142 case en_stmt_prepared:
143 case en_stmt_executed:
144 pstmt->state = en_stmt_allocated;
145 pstmt->prep_state = 0;
146 break;
147
148 default:
149 break;
150 }
151
152 default:
153 break;
154 }
155
156 return retcode;
157 }
158
159 RETCODE SQL_API SQLSetCursorName (
160 HSTMT hstmt,
161 UCHAR FAR* szCursor,
162 SWORD cbCursor )
163 {
164 STMT_t FAR* pstmt = (STMT_t*)hstmt;
165 HPROC hproc = SQL_NULL_HPROC;
166
167 RETCODE retcode = SQL_SUCCESS;
168 int sqlstat = en_00000;
169
170 if( hstmt == SQL_NULL_HSTMT
171 || pstmt->hdbc == SQL_NULL_HDBC )
172 {
173 return SQL_INVALID_HANDLE;
174 }
175
176 if( szCursor == NULL )
177 {
178 PUSHSQLERR ( pstmt->herr, en_S1009 );
179
180 return SQL_ERROR;
181 }
182
183 if( cbCursor < 0 && cbCursor != SQL_NTS )
184 {
185 PUSHSQLERR ( pstmt->herr, en_S1090 );
186
187 return SQL_ERROR;
188 }
189
190 /* check state */
191 if( pstmt->asyn_on != en_NullProc )
192 {
193 sqlstat = en_S1010;
194 }
195 else
196 {
197 switch( pstmt->state )
198 {
199 case en_stmt_executed:
200 case en_stmt_cursoropen:
201 case en_stmt_fetched:
202 case en_stmt_xfetched:
203 sqlstat = en_24000;
204 break;
205
206 case en_stmt_needdata:
207 case en_stmt_mustput:
208 case en_stmt_canput:
209 sqlstat = en_S1010;
210 break;
211
212 default:
213 break;
214 }
215 }
216
217 if( sqlstat != en_00000 )
218 {
219 PUSHSQLERR ( pstmt->herr, sqlstat );
220
221 return SQL_ERROR;
222 }
223
224 hproc = _iodbcdm_getproc( pstmt->hdbc, en_SetCursorName);
225
226 if( hproc == SQL_NULL_HPROC )
227 {
228 PUSHSQLERR ( pstmt->herr, en_IM001 );
229
230 return SQL_ERROR;
231 }
232
233 CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_SetCursorName, (
234 pstmt->dhstmt, szCursor, cbCursor ) )
235
236 #if 0
237 retcode = hproc ( pstmt->dhstmt, szCursor, cbCursor );
238 #endif
239
240 if( retcode == SQL_SUCCESS
241 || retcode == SQL_SUCCESS_WITH_INFO )
242 {
243 pstmt->cursor_state = en_stmt_cursor_named;
244 }
245
246 return retcode;
247 }
248
249 RETCODE SQL_API SQLBindParameter (
250 HSTMT hstmt,
251 UWORD ipar,
252 SWORD fParamType,
253 SWORD fCType,
254 SWORD fSqlType,
255 UDWORD cbColDef,
256 SWORD ibScale,
257 PTR rgbValue,
258 SDWORD cbValueMax,
259 SDWORD FAR* pcbValue )
260 {
261 STMT_t FAR* pstmt = (STMT_t FAR*)hstmt;
262 HPROC hproc = SQL_NULL_HPROC;
263
264 int sqlstat = en_00000;
265 RETCODE retcode = SQL_SUCCESS;
266
267 if( hstmt == SQL_NULL_HSTMT
268 || pstmt->hdbc == SQL_NULL_HDBC )
269 {
270 return SQL_INVALID_HANDLE;
271 }
272
273 /* check param */
274 if( fSqlType > SQL_TYPE_MAX
275 || ( fSqlType < SQL_TYPE_MIN
276 && fSqlType > SQL_TYPE_DRIVER_START ) )
277 /* Note: SQL_TYPE_DRIVER_START is a nagtive number
278 * So, we use ">" */
279 {
280 sqlstat = en_S1004;
281 }
282 else if ( ipar < 1 )
283 {
284 sqlstat = en_S1093;
285 }
286 else if( (rgbValue == NULL && pcbValue == NULL)
287 && fParamType != SQL_PARAM_OUTPUT )
288 {
289 sqlstat = en_S1009;
290 /* This means, I allow output to nowhere
291 * (i.e. * junk output result). But I can't
292 * allow input from nowhere.
293 */
294 }
295 /**********
296 else if( cbValueMax < 0L && cbValueMax != SQL_SETPARAM_VALUE_MAX )
297 {
298 sqlstat = en_S1090;
299 }
300 **********/
301 else if( fParamType != SQL_PARAM_INPUT
302 && fParamType != SQL_PARAM_OUTPUT
303 && fParamType != SQL_PARAM_INPUT_OUTPUT )
304 {
305 sqlstat = en_S1105;
306 }
307 else
308 {
309 switch( fCType )
310 {
311 case SQL_C_DEFAULT:
312 case SQL_C_CHAR:
313 case SQL_C_BINARY:
314 case SQL_C_BIT:
315 case SQL_C_TINYINT:
316 case SQL_C_STINYINT:
317 case SQL_C_UTINYINT:
318 case SQL_C_SHORT:
319 case SQL_C_SSHORT:
320 case SQL_C_USHORT:
321 case SQL_C_LONG:
322 case SQL_C_SLONG:
323 case SQL_C_ULONG:
324 case SQL_C_FLOAT:
325 case SQL_C_DOUBLE:
326 case SQL_C_DATE:
327 case SQL_C_TIME:
328 case SQL_C_TIMESTAMP:
329 break;
330
331 default:
332 sqlstat = en_S1003;
333 break;
334 }
335 }
336
337 if(sqlstat != en_00000 )
338 {
339 PUSHSQLERR ( pstmt->herr, sqlstat );
340
341 return SQL_ERROR;
342 }
343
344 /* check state */
345 if( pstmt->state >= en_stmt_needdata
346 || pstmt->asyn_on != en_NullProc )
347 {
348 PUSHSQLERR ( pstmt->herr, en_S1010 );
349
350 retcode = SQL_ERROR;
351 }
352
353 hproc = _iodbcdm_getproc( pstmt->hdbc, en_BindParameter );
354
355 if( hproc == SQL_NULL_HPROC )
356 {
357 PUSHSQLERR ( pstmt->herr, en_IM001 );
358
359 return SQL_ERROR;
360 }
361
362 CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_BindParameter, (
363 pstmt->dhstmt, ipar, fParamType, fCType, fSqlType,
364 cbColDef, ibScale, rgbValue, cbValueMax, pcbValue ) )
365
366 #if 0
367 retcode = hproc(pstmt->dhstmt, ipar, fParamType, fCType, fSqlType,
368 cbColDef, ibScale, rgbValue, cbValueMax, pcbValue );
369 #endif
370
371 return retcode;
372 }
373
374 RETCODE SQL_API SQLParamOptions(
375 HSTMT hstmt,
376 UDWORD crow,
377 UDWORD FAR* pirow )
378 {
379 STMT_t FAR* pstmt = (STMT_t FAR*)hstmt;
380 HPROC hproc;
381 RETCODE retcode;
382
383 if( hstmt == SQL_NULL_HSTMT
384 || pstmt->hdbc == SQL_NULL_HDBC )
385 {
386 return SQL_INVALID_HANDLE;
387 }
388
389 if( crow == (UDWORD)0UL )
390 {
391 PUSHSQLERR ( pstmt->herr, en_S1107 );
392
393 return SQL_ERROR;
394 }
395
396 if( pstmt->state >= en_stmt_needdata
397 || pstmt->asyn_on != en_NullProc )
398 {
399 PUSHSQLERR ( pstmt->herr, en_S1010 );
400
401 return SQL_ERROR;
402 }
403
404 hproc = _iodbcdm_getproc ( pstmt->hdbc, en_ParamOptions );
405
406 if( hproc == SQL_NULL_HPROC )
407 {
408 PUSHSQLERR ( pstmt->herr, en_IM001 );
409
410 return SQL_ERROR;
411 }
412
413 CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_ParamOptions, (
414 pstmt->dhstmt, crow, pirow) )
415
416 #if 0
417 retcode = hproc ( pstmt->dhstmt, crow, pirow );
418 #endif
419
420 return retcode;
421 }
422
423 RETCODE SQL_API SQLSetScrollOptions(
424 HSTMT hstmt,
425 UWORD fConcurrency,
426 SDWORD crowKeyset,
427 UWORD crowRowset )
428 {
429 STMT_t FAR* pstmt = (STMT_t FAR*)hstmt;
430 HPROC hproc;
431 int sqlstat = en_00000;
432 RETCODE retcode;
433
434 if( hstmt == SQL_NULL_HSTMT
435 || pstmt->hdbc == SQL_NULL_HDBC )
436 {
437 return SQL_INVALID_HANDLE;
438 }
439
440 for(;;)
441 {
442 if( crowRowset == (UWORD)0 )
443 {
444 sqlstat = en_S1107;
445 break;
446 }
447
448 if( crowKeyset > (SDWORD)0L && crowKeyset < (SDWORD)crowRowset )
449 {
450 sqlstat = en_S1107;
451 break;
452 }
453
454 if( crowKeyset < 1 )
455 {
456 if( crowKeyset != SQL_SCROLL_FORWARD_ONLY
457 && crowKeyset != SQL_SCROLL_STATIC
458 && crowKeyset != SQL_SCROLL_KEYSET_DRIVEN
459 && crowKeyset != SQL_SCROLL_DYNAMIC )
460 {
461 sqlstat = en_S1107;
462 break;
463 }
464 }
465
466 if( fConcurrency != SQL_CONCUR_READ_ONLY
467 && fConcurrency != SQL_CONCUR_LOCK
468 && fConcurrency != SQL_CONCUR_ROWVER
469 && fConcurrency != SQL_CONCUR_VALUES )
470 {
471 sqlstat = en_S1108;
472 break;
473 }
474
475 if( pstmt->state != en_stmt_allocated )
476 {
477 sqlstat = en_S1010;
478 break;
479 }
480
481 hproc = _iodbcdm_getproc( pstmt->hdbc, en_SetScrollOptions );
482
483 if( hproc == SQL_NULL_HPROC )
484 {
485 sqlstat = en_IM001;
486 break;
487 }
488
489 sqlstat = en_00000;
490 if( 1 ) /* turn off solaris warning message */
491 break;
492 }
493
494 if( sqlstat != en_00000 )
495 {
496 PUSHSQLERR ( pstmt->herr, sqlstat );
497
498 return SQL_ERROR;
499 }
500
501 CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_SetScrollOptions, (
502 pstmt->dhstmt,
503 fConcurrency,
504 crowKeyset,
505 crowRowset ) )
506
507 #if 0
508 retcode = hproc(pstmt->dhstmt,
509 fConcurrency,
510 crowKeyset,
511 crowRowset );
512 #endif
513
514 return retcode;
515 }
516
517 RETCODE SQL_API SQLSetParam (
518 HSTMT hstmt,
519 UWORD ipar,
520 SWORD fCType,
521 SWORD fSqlType,
522 UDWORD cbColDef,
523 SWORD ibScale,
524 PTR rgbValue,
525 SDWORD FAR *pcbValue)
526 {
527 return SQLBindParameter(hstmt,
528 ipar,
529 (SWORD)SQL_PARAM_INPUT_OUTPUT,
530 fCType,
531 fSqlType,
532 cbColDef,
533 ibScale,
534 rgbValue,
535 SQL_SETPARAM_VALUE_MAX,
536 pcbValue );
537 }