]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/hstmt.c
6 * Query statement object management functions
8 * The iODBC driver manager.
10 * Copyright (C) 1995 by Ke Jin <kejin@empress.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the Free
24 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
46 DBC_t FAR
*pdbc
= (DBC_t FAR
*) hdbc
;
47 STMT_t FAR
*pstmt
= NULL
;
48 HPROC hproc
= SQL_NULL_HPROC
;
49 RETCODE retcode
= SQL_SUCCESS
;
51 #if (ODBCVER >= 0x0300)
52 if (hdbc
== SQL_NULL_HDBC
|| pdbc
->type
!= SQL_HANDLE_DBC
)
54 if (hdbc
== SQL_NULL_HDBC
)
57 return SQL_INVALID_HANDLE
;
62 PUSHSQLERR (pdbc
->herr
, en_S1009
);
70 case en_dbc_connected
:
74 case en_dbc_allocated
:
76 PUSHSQLERR (pdbc
->herr
, en_08003
);
77 *phstmt
= SQL_NULL_HSTMT
;
81 return SQL_INVALID_HANDLE
;
84 pstmt
= (STMT_t FAR
*) MEM_ALLOC (sizeof (STMT_t
));
88 PUSHSQLERR (pdbc
->herr
, en_S1001
);
89 *phstmt
= SQL_NULL_HSTMT
;
94 #if (ODBCVER >= 0x0300)
95 pstmt
->type
= SQL_HANDLE_STMT
;
98 /* initiate the object */
99 pstmt
->herr
= SQL_NULL_HERR
;
101 pstmt
->state
= en_stmt_allocated
;
102 pstmt
->cursor_state
= en_stmt_cursor_no
;
103 pstmt
->prep_state
= 0;
104 pstmt
->asyn_on
= en_NullProc
;
105 pstmt
->need_on
= en_NullProc
;
107 /* call driver's function */
109 #if (ODBCVER >= 0x0300)
110 hproc
= _iodbcdm_getproc (hdbc
, en_AllocHandle
);
114 CALL_DRIVER (pstmt
->hdbc
, hdbc
, retcode
, hproc
, en_AllocHandle
,
115 (SQL_HANDLE_STMT
, pdbc
->dhdbc
, &(pstmt
->dhstmt
)))
121 hproc
= _iodbcdm_getproc (hdbc
, en_AllocStmt
);
123 if (hproc
== SQL_NULL_HPROC
)
125 PUSHSQLERR (pstmt
->herr
, en_IM001
);
126 *phstmt
= SQL_NULL_HSTMT
;
132 CALL_DRIVER (hdbc
, retcode
, hproc
, en_AllocStmt
,
133 (pdbc
->dhdbc
, &(pstmt
->dhstmt
)))
136 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
138 *phstmt
= SQL_NULL_HSTMT
;
144 /* insert into list */
145 pstmt
->next
= pdbc
->hstmt
;
148 *phstmt
= (HSTMT
) pstmt
;
150 /* state transition */
151 pdbc
->state
= en_dbc_hstmt
;
158 _iodbcdm_dropstmt (HSTMT hstmt
)
160 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
164 if (hstmt
== SQL_NULL_HSTMT
)
166 return SQL_INVALID_HANDLE
;
169 pdbc
= (DBC_t FAR
*) (pstmt
->hdbc
);
171 for (tpstmt
= (STMT_t FAR
*) pdbc
->hstmt
;
173 tpstmt
= tpstmt
->next
)
177 pdbc
->hstmt
= (HSTMT
) pstmt
->next
;
181 if (tpstmt
->next
== pstmt
)
183 tpstmt
->next
= pstmt
->next
;
190 return SQL_INVALID_HANDLE
;
193 _iodbcdm_freesqlerrlist (pstmt
->herr
);
205 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
209 HPROC hproc
= SQL_NULL_HPROC
;
212 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
214 return SQL_INVALID_HANDLE
;
217 pdbc
= (DBC_t FAR
*) (pstmt
->hdbc
);
225 case SQL_RESET_PARAMS
:
229 PUSHSQLERR (pstmt
->herr
, en_S1092
);
234 if (pstmt
->state
>= en_stmt_needdata
|| pstmt
->asyn_on
!= en_NullProc
)
236 PUSHSQLERR (pstmt
->herr
, en_S1010
);
241 hproc
= SQL_NULL_HPROC
;
243 #if (ODBCVER >= 0x0300)
244 if (fOption
== SQL_DROP
)
246 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_FreeHandle
);
250 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_FreeHandle
,
251 (SQL_HANDLE_STMT
, pstmt
->dhstmt
))
256 if (hproc
== SQL_NULL_HPROC
)
258 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_FreeStmt
);
260 if (hproc
== SQL_NULL_HPROC
)
262 PUSHSQLERR (pstmt
->herr
, en_IM001
);
267 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_FreeStmt
,
268 (pstmt
->dhstmt
, fOption
))
271 if (retcode
!= SQL_SUCCESS
272 && retcode
!= SQL_SUCCESS_WITH_INFO
)
277 /* state transition */
281 /* delet this object (ignore return) */
282 _iodbcdm_dropstmt (hstmt
);
286 pstmt
->cursor_state
= en_stmt_cursor_no
;
287 /* This means cursor name set by
288 * SQLSetCursorName() call will also
292 switch (pstmt
->state
)
294 case en_stmt_allocated
:
295 case en_stmt_prepared
:
298 case en_stmt_executed
:
299 case en_stmt_cursoropen
:
300 case en_stmt_fetched
:
301 case en_stmt_xfetched
:
302 if (pstmt
->prep_state
)
320 case SQL_RESET_PARAMS
:
335 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
337 int sqlstat
= en_00000
;
340 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
342 return SQL_INVALID_HANDLE
;
346 if ( /* fOption < SQL_STMT_OPT_MIN || */
347 fOption
> SQL_STMT_OPT_MAX
)
349 PUSHSQLERR (pstmt
->herr
, en_S1092
);
354 if (fOption
== SQL_CONCURRENCY
355 || fOption
== SQL_CURSOR_TYPE
356 || fOption
== SQL_SIMULATE_CURSOR
357 || fOption
== SQL_USE_BOOKMARKS
)
359 if (pstmt
->asyn_on
!= en_NullProc
)
361 if (pstmt
->prep_state
)
368 switch (pstmt
->state
)
370 case en_stmt_prepared
:
374 case en_stmt_executed
:
375 case en_stmt_cursoropen
:
376 case en_stmt_fetched
:
377 case en_stmt_xfetched
:
381 case en_stmt_needdata
:
382 case en_stmt_mustput
:
384 if (pstmt
->prep_state
)
397 if (pstmt
->asyn_on
!= en_NullProc
)
399 if (!pstmt
->prep_state
)
406 if (pstmt
->state
>= en_stmt_needdata
)
413 if (sqlstat
!= en_00000
)
415 PUSHSQLERR (pstmt
->herr
, sqlstat
);
420 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_SetStmtOption
);
422 if (hproc
== SQL_NULL_HPROC
)
424 PUSHSQLERR (pstmt
->herr
, en_IM001
);
429 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_SetStmtOption
,
430 (pstmt
->dhstmt
, fOption
, vParam
))
442 STMT_t FAR
*pstmt
= (STMT_t
*) hstmt
;
444 int sqlstat
= en_00000
;
447 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
449 return SQL_INVALID_HANDLE
;
453 if ( /* fOption < SQL_STMT_OPT_MIN || */
454 fOption
> SQL_STMT_OPT_MAX
)
456 PUSHSQLERR (pstmt
->herr
, en_S1092
);
462 if (pstmt
->state
>= en_stmt_needdata
463 || pstmt
->asyn_on
!= en_NullProc
)
469 switch (pstmt
->state
)
471 case en_stmt_allocated
:
472 case en_stmt_prepared
:
473 case en_stmt_executed
:
474 case en_stmt_cursoropen
:
475 if (fOption
== SQL_ROW_NUMBER
|| fOption
== SQL_GET_BOOKMARK
)
486 if (sqlstat
!= en_00000
)
488 PUSHSQLERR (pstmt
->herr
, sqlstat
);
493 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_GetStmtOption
);
495 if (hproc
== SQL_NULL_HPROC
)
497 PUSHSQLERR (pstmt
->herr
, en_IM001
);
501 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_GetStmtOption
,
502 (pstmt
->dhstmt
, fOption
, pvParam
))
509 SQLCancel (HSTMT hstmt
)
511 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
515 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
517 return SQL_INVALID_HANDLE
;
524 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Cancel
);
526 if (hproc
== SQL_NULL_HPROC
)
528 PUSHSQLERR (pstmt
->herr
, en_IM001
);
533 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Cancel
,
536 /* state transition */
537 if (retcode
!= SQL_SUCCESS
&& retcode
!= SQL_SUCCESS_WITH_INFO
)
542 switch (pstmt
->state
)
544 case en_stmt_allocated
:
545 case en_stmt_prepared
:
548 case en_stmt_executed
:
549 if (pstmt
->prep_state
)
551 pstmt
->state
= en_stmt_prepared
;
555 pstmt
->state
= en_stmt_allocated
;
559 case en_stmt_cursoropen
:
560 case en_stmt_fetched
:
561 case en_stmt_xfetched
:
562 if (pstmt
->prep_state
)
564 pstmt
->state
= en_stmt_prepared
;
568 pstmt
->state
= en_stmt_allocated
;
572 case en_stmt_needdata
:
573 case en_stmt_mustput
:
575 switch (pstmt
->need_on
)
578 pstmt
->state
= en_stmt_allocated
;
582 pstmt
->state
= en_stmt_prepared
;
586 pstmt
->state
= en_stmt_xfetched
;
592 pstmt
->need_on
= en_NullProc
;