]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/hstmt.c
1 /** Query statement object management functions
3 Copyright (C) 1995 by Ke Jin <kejin@empress.com>
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.
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.
16 #include <../iodbc/iodbc.h>
18 #include <../iodbc/isql.h>
19 #include <../iodbc/isqlext.h>
21 #include <../iodbc/dlproc.h>
23 #include <../iodbc/herr.h>
24 #include <../iodbc/henv.h>
25 #include <../iodbc/hdbc.h>
26 #include <../iodbc/hstmt.h>
28 #include <../iodbc/itrace.h>
30 RETCODE SQL_API
SQLAllocStmt (
34 DBC_t FAR
* pdbc
= (DBC_t FAR
*)hdbc
;
35 STMT_t FAR
* pstmt
= NULL
;
36 HPROC hproc
= SQL_NULL_HPROC
;
37 RETCODE retcode
= SQL_SUCCESS
;
39 #if (ODBCVER >= 0x0300)
40 if( hdbc
== SQL_NULL_HDBC
41 || pdbc
->type
!= SQL_HANDLE_DBC
)
43 if( hdbc
== SQL_NULL_HDBC
)
46 return SQL_INVALID_HANDLE
;
51 PUSHSQLERR ( pdbc
->herr
, en_S1009
);
59 case en_dbc_connected
:
63 case en_dbc_allocated
:
65 PUSHSQLERR ( pdbc
->herr
, en_08003
);
66 *phstmt
= SQL_NULL_HSTMT
;
70 return SQL_INVALID_HANDLE
;
73 pstmt
= (STMT_t FAR
*)MEM_ALLOC(sizeof(STMT_t
));
77 PUSHSQLERR ( pdbc
->herr
, en_S1001
);
78 *phstmt
= SQL_NULL_HSTMT
;
83 #if (ODBCVER >= 0x0300)
84 pstmt
->type
= SQL_HANDLE_STMT
;
86 /* initiate the object */
87 pstmt
->herr
= SQL_NULL_HERR
;
89 pstmt
->state
= en_stmt_allocated
;
90 pstmt
->cursor_state
= en_stmt_cursor_no
;
91 pstmt
->prep_state
= 0;
92 pstmt
->asyn_on
= en_NullProc
;
93 pstmt
->need_on
= en_NullProc
;
95 /* call driver's function */
96 #if (ODBCVER >= 0x0300)
97 hproc
= _iodbcdm_getproc( hdbc
, en_AllocHandle
);
101 CALL_DRIVER ( pstmt
->hdbc
, hdbc
, retcode
, hproc
,
110 hproc
= _iodbcdm_getproc( hdbc
, en_AllocStmt
);
112 if( hproc
== SQL_NULL_HPROC
)
114 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
115 *phstmt
= SQL_NULL_HSTMT
;
121 CALL_DRIVER ( hdbc
, retcode
, hproc
, en_AllocStmt
, (
122 pdbc
->dhdbc
, &(pstmt
->dhstmt
) ) )
125 if( retcode
!= SQL_SUCCESS
126 && retcode
!= SQL_SUCCESS_WITH_INFO
)
128 *phstmt
= SQL_NULL_HSTMT
;
134 /* insert into list */
135 pstmt
->next
= pdbc
->hstmt
;
138 *phstmt
= (HSTMT
)pstmt
;
140 /* state transition */
141 pdbc
->state
= en_dbc_hstmt
;
146 RETCODE
_iodbcdm_dropstmt( HSTMT hstmt
)
148 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
152 if( hstmt
== SQL_NULL_HSTMT
)
154 return SQL_INVALID_HANDLE
;
157 pdbc
= (DBC_t FAR
*)(pstmt
->hdbc
);
159 for(tpstmt
= (STMT_t FAR
*)pdbc
->hstmt
;
161 tpstmt
= tpstmt
->next
)
165 pdbc
->hstmt
= (HSTMT
)pstmt
->next
;
169 if(tpstmt
->next
== pstmt
)
171 tpstmt
->next
= pstmt
->next
;
178 return SQL_INVALID_HANDLE
;
181 _iodbcdm_freesqlerrlist(pstmt
->herr
);
187 RETCODE SQL_API
SQLFreeStmt (
191 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
192 /* STMT_t FAR* tpstmt; */
195 HPROC hproc
= SQL_NULL_HPROC
;
198 if( hstmt
== SQL_NULL_HSTMT
199 || pstmt
->hdbc
== SQL_NULL_HDBC
)
201 return SQL_INVALID_HANDLE
;
204 pdbc
= (DBC_t FAR
*)(pstmt
->hdbc
);
212 case SQL_RESET_PARAMS
:
216 PUSHSQLERR ( pstmt
->herr
, en_S1092
);
221 if( pstmt
->state
>= en_stmt_needdata
222 || pstmt
->asyn_on
!= en_NullProc
)
224 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
229 hproc
= SQL_NULL_HPROC
;
231 #if (ODBCVER >= 0x0300)
232 if( fOption
== SQL_DROP
)
234 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_FreeHandle
);
238 CALL_DRIVER( pstmt
->hdbc
, retcode
, hproc
, en_FreeHandle
, (
239 SQL_HANDLE_STMT
, pstmt
->dhstmt
)
244 if( hproc
== SQL_NULL_HPROC
)
246 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_FreeStmt
);
248 if( hproc
== SQL_NULL_HPROC
)
250 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
255 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_FreeStmt
, (
256 pstmt
->dhstmt
, fOption
) )
259 if( retcode
!= SQL_SUCCESS
260 && retcode
!= SQL_SUCCESS_WITH_INFO
)
265 /* state transition */
269 /* delet this object (ignore return) */
270 _iodbcdm_dropstmt( hstmt
);
274 pstmt
->cursor_state
= en_stmt_cursor_no
;
275 /* This means cursor name set by
276 * SQLSetCursorName() call will also
280 switch( pstmt
->state
)
282 case en_stmt_allocated
:
283 case en_stmt_prepared
:
286 case en_stmt_executed
:
287 case en_stmt_cursoropen
:
288 case en_stmt_fetched
:
289 case en_stmt_xfetched
:
290 if( pstmt
->prep_state
)
308 case SQL_RESET_PARAMS
:
316 RETCODE SQL_API
SQLSetStmtOption (
321 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
323 int sqlstat
= en_00000
;
326 if( hstmt
== SQL_NULL_HSTMT
327 || pstmt
->hdbc
== SQL_NULL_HDBC
)
329 return SQL_INVALID_HANDLE
;
333 if(/* fOption < SQL_STMT_OPT_MIN || */
334 fOption
> SQL_STMT_OPT_MAX
)
336 PUSHSQLERR ( pstmt
->herr
, en_S1092
);
341 if( fOption
== SQL_CONCURRENCY
342 || fOption
== SQL_CURSOR_TYPE
343 || fOption
== SQL_SIMULATE_CURSOR
344 || fOption
== SQL_USE_BOOKMARKS
)
346 if( pstmt
->asyn_on
!= en_NullProc
)
348 if( pstmt
->prep_state
)
355 switch( pstmt
->state
)
357 case en_stmt_prepared
:
361 case en_stmt_executed
:
362 case en_stmt_cursoropen
:
363 case en_stmt_fetched
:
364 case en_stmt_xfetched
:
368 case en_stmt_needdata
:
369 case en_stmt_mustput
:
371 if( pstmt
->prep_state
)
384 if( pstmt
->asyn_on
!= en_NullProc
)
386 if( ! pstmt
->prep_state
)
393 if( pstmt
->state
>= en_stmt_needdata
)
400 if( sqlstat
!= en_00000
)
402 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
407 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_SetStmtOption
);
409 if( hproc
== SQL_NULL_HPROC
)
411 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
416 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_SetStmtOption
, (
417 pstmt
->dhstmt
, fOption
, vParam
) )
420 retcode
= hproc ( pstmt
->dhstmt
, fOption
, vParam
);
426 RETCODE SQL_API
SQLGetStmtOption (
431 STMT_t FAR
* pstmt
= (STMT_t
*)hstmt
;
433 int sqlstat
= en_00000
;
436 if( hstmt
== SQL_NULL_HSTMT
437 || pstmt
->hdbc
== SQL_NULL_HDBC
)
439 return SQL_INVALID_HANDLE
;
443 if( /* fOption < SQL_STMT_OPT_MIN || */
444 fOption
> SQL_STMT_OPT_MAX
)
446 PUSHSQLERR ( pstmt
->herr
, en_S1092
);
452 if( pstmt
->state
>= en_stmt_needdata
453 || pstmt
->asyn_on
!= en_NullProc
)
459 switch( pstmt
->state
)
461 case en_stmt_allocated
:
462 case en_stmt_prepared
:
463 case en_stmt_executed
:
464 case en_stmt_cursoropen
:
465 if( fOption
== SQL_ROW_NUMBER
466 || fOption
== SQL_GET_BOOKMARK
)
477 if( sqlstat
!= en_00000
)
479 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
484 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_GetStmtOption
);
486 if( hproc
== SQL_NULL_HPROC
)
488 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
492 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_GetStmtOption
, (
493 pstmt
->dhstmt
, fOption
, pvParam
) )
496 retcode
= hproc ( pstmt
->dhstmt
, fOption
, pvParam
);
502 RETCODE SQL_API
SQLCancel ( HSTMT hstmt
)
504 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
508 if( hstmt
== SQL_NULL_HSTMT
509 || pstmt
->hdbc
== SQL_NULL_HDBC
)
511 return SQL_INVALID_HANDLE
;
518 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Cancel
);
520 if( hproc
== SQL_NULL_HPROC
)
522 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
527 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Cancel
, (pstmt
->dhstmt
) )
530 retcode
= hproc ( pstmt
->dhstmt
);
533 /* state transition */
534 if( retcode
!= SQL_SUCCESS
535 && retcode
!= SQL_SUCCESS_WITH_INFO
)
540 switch( pstmt
->state
)
542 case en_stmt_allocated
:
543 case en_stmt_prepared
:
546 case en_stmt_executed
:
547 if( pstmt
->prep_state
)
549 pstmt
->state
= en_stmt_prepared
;
553 pstmt
->state
= en_stmt_allocated
;
557 case en_stmt_cursoropen
:
558 case en_stmt_fetched
:
559 case en_stmt_xfetched
:
560 if( pstmt
->prep_state
)
562 pstmt
->state
= en_stmt_prepared
;
566 pstmt
->state
= en_stmt_allocated
;
570 case en_stmt_needdata
:
571 case en_stmt_mustput
:
573 switch( pstmt
->need_on
)
576 pstmt
->state
= en_stmt_allocated
;
580 pstmt
->state
= en_stmt_prepared
;
584 pstmt
->state
= en_stmt_xfetched
;
590 pstmt
->need_on
= en_NullProc
;