]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/fetch.c
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
SQLFetch ( HSTMT hstmt
)
32 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
33 HPROC hproc
= SQL_NULL_HPROC
;
36 if( hstmt
== SQL_NULL_HSTMT
37 || pstmt
->hdbc
== SQL_NULL_HDBC
)
39 return SQL_INVALID_HANDLE
;
43 if( pstmt
->asyn_on
== en_NullProc
)
45 switch( pstmt
->state
)
47 case en_stmt_allocated
:
48 case en_stmt_prepared
:
49 case en_stmt_xfetched
:
50 case en_stmt_needdata
:
53 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
60 else if( pstmt
->asyn_on
!= en_Fetch
)
62 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
66 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Fetch
);
68 if( hproc
== SQL_NULL_HPROC
)
70 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
75 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Fetch
, (pstmt
->dhstmt
) )
78 retcode
= hproc( pstmt
->dhstmt
);
80 /* state transition */
81 if( pstmt
->asyn_on
== en_Fetch
)
86 case SQL_SUCCESS_WITH_INFO
:
87 case SQL_NO_DATA_FOUND
:
89 pstmt
->asyn_on
= en_NullProc
;
92 case SQL_STILL_EXECUTING
:
98 switch( pstmt
->state
)
100 case en_stmt_cursoropen
:
101 case en_stmt_fetched
:
105 case SQL_SUCCESS_WITH_INFO
:
106 pstmt
->state
= en_stmt_fetched
;
107 pstmt
->cursor_state
= en_stmt_cursor_fetched
;
110 case SQL_NO_DATA_FOUND
:
111 if( pstmt
->prep_state
)
113 pstmt
->state
= en_stmt_prepared
;
118 pstmt
->state
= en_stmt_allocated
;
120 pstmt
->cursor_state
= en_stmt_cursor_no
;
123 case SQL_STILL_EXECUTING
:
124 pstmt
->asyn_on
= en_Fetch
;
139 RETCODE SQL_API
SQLExtendedFetch (
144 UWORD FAR
* rgfRowStatus
)
146 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
147 HPROC hproc
= SQL_NULL_HPROC
;
150 if( hstmt
== SQL_NULL_HSTMT
151 || pstmt
->hdbc
== SQL_NULL_HDBC
)
153 return SQL_INVALID_HANDLE
;
156 /* check fetch type */
157 if( fFetchType
< SQL_FETCH_NEXT
158 || fFetchType
> SQL_FETCH_BOOKMARK
)
160 /* Unlike MS driver manager(i.e. DM),
161 * we don't check driver's ODBC version
162 * against SQL_FETCH_RESUME (only 1.0)
163 * and SQL_FETCH_BOOKMARK (only 2.0).
165 PUSHSQLERR ( pstmt
->herr
, en_S1106
);
171 if( pstmt
->asyn_on
== en_NullProc
)
173 switch( pstmt
->state
)
175 case en_stmt_allocated
:
176 case en_stmt_prepared
:
177 case en_stmt_fetched
:
178 case en_stmt_needdata
:
179 case en_stmt_mustput
:
181 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
188 else if( pstmt
->asyn_on
!= en_ExtendedFetch
)
190 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
194 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_ExtendedFetch
);
196 if( hproc
== SQL_NULL_HPROC
)
198 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
203 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ExtendedFetch
, (
211 retcode
= hproc(pstmt
->dhstmt
,
218 /* state transition */
219 if( pstmt
->asyn_on
== en_ExtendedFetch
)
224 case SQL_SUCCESS_WITH_INFO
:
225 case SQL_NO_DATA_FOUND
:
227 pstmt
->asyn_on
= en_NullProc
;
230 case SQL_STILL_EXECUTING
:
236 switch( pstmt
->state
)
238 case en_stmt_cursoropen
:
239 case en_stmt_xfetched
:
243 case SQL_SUCCESS_WITH_INFO
:
244 case SQL_NO_DATA_FOUND
:
245 pstmt
->state
= en_stmt_xfetched
;
246 pstmt
->cursor_state
= en_stmt_cursor_xfetched
;
249 case SQL_STILL_EXECUTING
:
250 pstmt
->asyn_on
= en_ExtendedFetch
;
265 RETCODE SQL_API
SQLGetData(
271 SDWORD FAR
* pcbValue
)
273 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
276 int sqlstat
= en_00000
;
278 if( hstmt
== SQL_NULL_HSTMT
279 || pstmt
->hdbc
== SQL_NULL_HDBC
)
281 return SQL_INVALID_HANDLE
;
285 if( rgbValue
== NULL
)
289 else if( cbValueMax
< 0 )
314 case SQL_C_TIMESTAMP
:
323 if( sqlstat
!= en_00000
)
325 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
331 if( pstmt
->asyn_on
== en_NullProc
)
333 switch( pstmt
->state
)
335 case en_stmt_allocated
:
336 case en_stmt_prepared
:
337 case en_stmt_needdata
:
338 case en_stmt_mustput
:
343 case en_stmt_executed
:
344 case en_stmt_cursoropen
:
352 else if( pstmt
->asyn_on
!= en_GetData
)
357 if( sqlstat
!= en_00000
)
359 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
365 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_GetData
);
367 if( hproc
== SQL_NULL_HPROC
)
369 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
374 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_GetData
, (
383 retcode
= hproc(pstmt
->dhstmt
,
391 /* state transition */
392 if( pstmt
->asyn_on
== en_GetData
)
397 case SQL_SUCCESS_WITH_INFO
:
398 case SQL_NO_DATA_FOUND
:
400 pstmt
->asyn_on
= en_NullProc
;
403 case SQL_STILL_EXECUTING
:
409 switch( pstmt
->state
)
411 case en_stmt_fetched
:
412 case en_stmt_xfetched
:
413 if( retcode
== SQL_STILL_EXECUTING
)
415 pstmt
->asyn_on
= en_GetData
;
427 RETCODE SQL_API
SQLMoreResults( HSTMT hstmt
)
429 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
433 if( hstmt
== SQL_NULL_HSTMT
434 || pstmt
->hdbc
== SQL_NULL_HDBC
)
436 return SQL_INVALID_HANDLE
;
440 if( pstmt
->asyn_on
== en_NullProc
)
442 switch( pstmt
->state
)
444 case en_stmt_allocated
:
445 case en_stmt_prepared
:
446 return SQL_NO_DATA_FOUND
;
448 case en_stmt_needdata
:
449 case en_stmt_mustput
:
451 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
458 else if( pstmt
->asyn_on
!= en_MoreResults
)
460 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
466 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_MoreResults
);
468 if( hproc
== SQL_NULL_HPROC
)
470 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
475 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_MoreResults
, (pstmt
->dhstmt
) )
478 retcode
= hproc( pstmt
->dhstmt
);
481 /* state transition */
482 if( pstmt
->asyn_on
== en_MoreResults
)
487 case SQL_SUCCESS_WITH_INFO
:
488 case SQL_NO_DATA_FOUND
:
490 pstmt
->asyn_on
= en_NullProc
;
493 case SQL_STILL_EXECUTING
:
499 switch( pstmt
->state
)
501 case en_stmt_allocated
:
502 case en_stmt_prepared
:
503 /* driver should return SQL_NO_DATA_FOUND */
506 case en_stmt_executed
:
507 if( retcode
== SQL_NO_DATA_FOUND
)
509 if( pstmt
->prep_state
)
511 pstmt
->state
= en_stmt_prepared
;
515 pstmt
->state
= en_stmt_allocated
;
518 else if( retcode
== SQL_STILL_EXECUTING
)
520 pstmt
->asyn_on
= en_MoreResults
;
524 case en_stmt_cursoropen
:
525 case en_stmt_fetched
:
526 case en_stmt_xfetched
:
527 if( retcode
== SQL_SUCCESS
)
531 else if( retcode
== SQL_NO_DATA_FOUND
)
533 if( pstmt
->prep_state
)
535 pstmt
->state
= en_stmt_prepared
;
539 pstmt
->state
= en_stmt_allocated
;
542 else if( retcode
== SQL_STILL_EXECUTING
)
544 pstmt
->asyn_on
= en_MoreResults
;
555 RETCODE SQL_API
SQLSetPos (
561 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
564 int sqlstat
= en_00000
;
566 if( hstmt
== SQL_NULL_HSTMT
567 || pstmt
->hdbc
== SQL_NULL_HDBC
)
569 return SQL_INVALID_HANDLE
;
572 /* check argument value */
573 if( fOption
> SQL_ADD
574 || fLock
> SQL_LOCK_UNLOCK
)
576 PUSHSQLERR ( pstmt
->herr
, en_S1009
);
580 if( pstmt
->asyn_on
== en_NullProc
)
582 switch( pstmt
->state
)
584 case en_stmt_allocated
:
585 case en_stmt_prepared
:
586 case en_stmt_fetched
:
587 case en_stmt_needdata
:
588 case en_stmt_mustput
:
593 case en_stmt_executed
:
594 case en_stmt_cursoropen
:
602 else if( pstmt
->asyn_on
!= en_SetPos
)
607 if( sqlstat
!= en_00000
)
609 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
615 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_SetPos
);
617 if( hproc
== SQL_NULL_HPROC
)
619 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
624 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_SetPos
, (
630 retcode
= hproc(pstmt
->dhstmt
,
636 /* state transition */
637 if( pstmt
->asyn_on
== en_SetPos
)
642 case SQL_SUCCESS_WITH_INFO
:
645 pstmt
->asyn_on
= en_NullProc
;
648 case SQL_STILL_EXECUTING
:
654 /* now, the only possible init state is 'xfetched' */
658 case SQL_SUCCESS_WITH_INFO
:
662 pstmt
->state
= en_stmt_needdata
;
663 pstmt
->need_on
= en_SetPos
;
666 case SQL_STILL_EXECUTING
:
667 pstmt
->asyn_on
= en_SetPos
;