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.
42 SQLFetch (HSTMT hstmt
)
44 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
45 HPROC hproc
= SQL_NULL_HPROC
;
48 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
50 return SQL_INVALID_HANDLE
;
54 if (pstmt
->asyn_on
== en_NullProc
)
58 case en_stmt_allocated
:
59 case en_stmt_prepared
:
60 case en_stmt_xfetched
:
61 case en_stmt_needdata
:
64 PUSHSQLERR (pstmt
->herr
, en_S1010
);
71 else if (pstmt
->asyn_on
!= en_Fetch
)
73 PUSHSQLERR (pstmt
->herr
, en_S1010
);
77 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Fetch
);
79 if (hproc
== SQL_NULL_HPROC
)
81 PUSHSQLERR (pstmt
->herr
, en_IM001
);
86 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Fetch
,
89 /* state transition */
90 if (pstmt
->asyn_on
== en_Fetch
)
95 case SQL_SUCCESS_WITH_INFO
:
96 case SQL_NO_DATA_FOUND
:
98 pstmt
->asyn_on
= en_NullProc
;
101 case SQL_STILL_EXECUTING
:
107 switch (pstmt
->state
)
109 case en_stmt_cursoropen
:
110 case en_stmt_fetched
:
114 case SQL_SUCCESS_WITH_INFO
:
115 pstmt
->state
= en_stmt_fetched
;
116 pstmt
->cursor_state
= en_stmt_cursor_fetched
;
119 case SQL_NO_DATA_FOUND
:
120 if (pstmt
->prep_state
)
122 pstmt
->state
= en_stmt_prepared
;
127 pstmt
->state
= en_stmt_allocated
;
129 pstmt
->cursor_state
= en_stmt_cursor_no
;
132 case SQL_STILL_EXECUTING
:
133 pstmt
->asyn_on
= en_Fetch
;
155 UWORD FAR
* rgfRowStatus
)
157 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
158 HPROC hproc
= SQL_NULL_HPROC
;
161 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
163 return SQL_INVALID_HANDLE
;
166 /* check fetch type */
167 if (fFetchType
< SQL_FETCH_NEXT
|| fFetchType
> SQL_FETCH_BOOKMARK
)
169 /* Unlike MS driver manager(i.e. DM),
170 * we don't check driver's ODBC version
171 * against SQL_FETCH_RESUME (only 1.0)
172 * and SQL_FETCH_BOOKMARK (only 2.0).
174 PUSHSQLERR (pstmt
->herr
, en_S1106
);
180 if (pstmt
->asyn_on
== en_NullProc
)
182 switch (pstmt
->state
)
184 case en_stmt_allocated
:
185 case en_stmt_prepared
:
186 case en_stmt_fetched
:
187 case en_stmt_needdata
:
188 case en_stmt_mustput
:
190 PUSHSQLERR (pstmt
->herr
, en_S1010
);
197 else if (pstmt
->asyn_on
!= en_ExtendedFetch
)
199 PUSHSQLERR (pstmt
->herr
, en_S1010
);
203 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_ExtendedFetch
);
205 if (hproc
== SQL_NULL_HPROC
)
207 PUSHSQLERR (pstmt
->herr
, en_IM001
);
212 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_ExtendedFetch
,
213 (pstmt
->dhstmt
, fFetchType
, irow
, pcrow
, rgfRowStatus
))
215 /* state transition */
216 if (pstmt
->asyn_on
== en_ExtendedFetch
)
221 case SQL_SUCCESS_WITH_INFO
:
222 case SQL_NO_DATA_FOUND
:
224 pstmt
->asyn_on
= en_NullProc
;
227 case SQL_STILL_EXECUTING
:
233 switch (pstmt
->state
)
235 case en_stmt_cursoropen
:
236 case en_stmt_xfetched
:
240 case SQL_SUCCESS_WITH_INFO
:
241 case SQL_NO_DATA_FOUND
:
242 pstmt
->state
= en_stmt_xfetched
;
243 pstmt
->cursor_state
= en_stmt_cursor_xfetched
;
246 case SQL_STILL_EXECUTING
:
247 pstmt
->asyn_on
= en_ExtendedFetch
;
270 SDWORD FAR
* pcbValue
)
272 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
275 int sqlstat
= en_00000
;
277 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
279 return SQL_INVALID_HANDLE
;
283 if (rgbValue
== NULL
)
287 else if (cbValueMax
< 0)
312 case SQL_C_TIMESTAMP
:
321 if (sqlstat
!= en_00000
)
323 PUSHSQLERR (pstmt
->herr
, sqlstat
);
329 if (pstmt
->asyn_on
== en_NullProc
)
331 switch (pstmt
->state
)
333 case en_stmt_allocated
:
334 case en_stmt_prepared
:
335 case en_stmt_needdata
:
336 case en_stmt_mustput
:
341 case en_stmt_executed
:
342 case en_stmt_cursoropen
:
350 else if (pstmt
->asyn_on
!= en_GetData
)
355 if (sqlstat
!= en_00000
)
357 PUSHSQLERR (pstmt
->herr
, sqlstat
);
363 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_GetData
);
365 if (hproc
== SQL_NULL_HPROC
)
367 PUSHSQLERR (pstmt
->herr
, en_IM001
);
372 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_GetData
,
373 (pstmt
->dhstmt
, icol
, fCType
, rgbValue
, cbValueMax
, pcbValue
))
375 /* state transition */
376 if (pstmt
->asyn_on
== en_GetData
)
381 case SQL_SUCCESS_WITH_INFO
:
382 case SQL_NO_DATA_FOUND
:
384 pstmt
->asyn_on
= en_NullProc
;
387 case SQL_STILL_EXECUTING
:
393 switch (pstmt
->state
)
395 case en_stmt_fetched
:
396 case en_stmt_xfetched
:
397 if (retcode
== SQL_STILL_EXECUTING
)
399 pstmt
->asyn_on
= en_GetData
;
413 SQLMoreResults (HSTMT hstmt
)
415 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
419 if (hstmt
== SQL_NULL_HSTMT
420 || pstmt
->hdbc
== SQL_NULL_HDBC
)
422 return SQL_INVALID_HANDLE
;
426 if (pstmt
->asyn_on
== en_NullProc
)
428 switch (pstmt
->state
)
430 case en_stmt_allocated
:
431 case en_stmt_prepared
:
432 return SQL_NO_DATA_FOUND
;
434 case en_stmt_needdata
:
435 case en_stmt_mustput
:
437 PUSHSQLERR (pstmt
->herr
, en_S1010
);
444 else if (pstmt
->asyn_on
!= en_MoreResults
)
446 PUSHSQLERR (pstmt
->herr
, en_S1010
);
452 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_MoreResults
);
454 if (hproc
== SQL_NULL_HPROC
)
456 PUSHSQLERR (pstmt
->herr
, en_IM001
);
461 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_MoreResults
,
464 /* state transition */
465 if (pstmt
->asyn_on
== en_MoreResults
)
470 case SQL_SUCCESS_WITH_INFO
:
471 case SQL_NO_DATA_FOUND
:
473 pstmt
->asyn_on
= en_NullProc
;
476 case SQL_STILL_EXECUTING
:
482 switch (pstmt
->state
)
484 case en_stmt_allocated
:
485 case en_stmt_prepared
:
486 /* driver should return SQL_NO_DATA_FOUND */
489 case en_stmt_executed
:
490 if (retcode
== SQL_NO_DATA_FOUND
)
492 if (pstmt
->prep_state
)
494 pstmt
->state
= en_stmt_prepared
;
498 pstmt
->state
= en_stmt_allocated
;
501 else if (retcode
== SQL_STILL_EXECUTING
)
503 pstmt
->asyn_on
= en_MoreResults
;
507 case en_stmt_cursoropen
:
508 case en_stmt_fetched
:
509 case en_stmt_xfetched
:
510 if (retcode
== SQL_SUCCESS
)
514 else if (retcode
== SQL_NO_DATA_FOUND
)
516 if (pstmt
->prep_state
)
518 pstmt
->state
= en_stmt_prepared
;
522 pstmt
->state
= en_stmt_allocated
;
525 else if (retcode
== SQL_STILL_EXECUTING
)
527 pstmt
->asyn_on
= en_MoreResults
;
546 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
549 int sqlstat
= en_00000
;
551 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
553 return SQL_INVALID_HANDLE
;
556 /* check argument value */
557 if (fOption
> SQL_ADD
|| fLock
> SQL_LOCK_UNLOCK
)
559 PUSHSQLERR (pstmt
->herr
, en_S1009
);
563 if (pstmt
->asyn_on
== en_NullProc
)
565 switch (pstmt
->state
)
567 case en_stmt_allocated
:
568 case en_stmt_prepared
:
569 case en_stmt_fetched
:
570 case en_stmt_needdata
:
571 case en_stmt_mustput
:
576 case en_stmt_executed
:
577 case en_stmt_cursoropen
:
585 else if (pstmt
->asyn_on
!= en_SetPos
)
590 if (sqlstat
!= en_00000
)
592 PUSHSQLERR (pstmt
->herr
, sqlstat
);
598 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_SetPos
);
600 if (hproc
== SQL_NULL_HPROC
)
602 PUSHSQLERR (pstmt
->herr
, en_IM001
);
607 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_SetPos
,
608 (pstmt
->dhstmt
, irow
, fOption
, fLock
))
610 /* state transition */
611 if (pstmt
->asyn_on
== en_SetPos
)
616 case SQL_SUCCESS_WITH_INFO
:
619 pstmt
->asyn_on
= en_NullProc
;
622 case SQL_STILL_EXECUTING
:
628 /* now, the only possible init state is 'xfetched' */
632 case SQL_SUCCESS_WITH_INFO
:
636 pstmt
->state
= en_stmt_needdata
;
637 pstmt
->need_on
= en_SetPos
;
640 case SQL_STILL_EXECUTING
:
641 pstmt
->asyn_on
= en_SetPos
;