]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/result.c
1 /** Prepare for getting query result
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
SQLBindCol (
36 SDWORD FAR
* pcbValue
)
38 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
39 HPROC hproc
= SQL_NULL_HPROC
;
42 if( hstmt
== SQL_NULL_HSTMT
43 || pstmt
->hdbc
== SQL_NULL_HDBC
)
45 return SQL_INVALID_HANDLE
;
72 PUSHSQLERR ( pstmt
->herr
, en_S1003
);
78 PUSHSQLERR ( pstmt
->herr
, en_S1090
);
84 if( pstmt
->state
> en_stmt_needdata
85 || pstmt
->asyn_on
!= en_NullProc
)
87 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
91 /* call driver's function */
92 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_BindCol
);
94 if( hproc
== SQL_NULL_HPROC
)
96 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
101 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_BindCol
, (
110 retcode
= hproc(pstmt
->dhstmt
,
121 RETCODE SQL_API
SQLGetCursorName(
125 SWORD FAR
* pcbCursor
)
127 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
131 if( hstmt
== SQL_NULL_HSTMT
132 || pstmt
->hdbc
== SQL_NULL_HDBC
)
134 return SQL_INVALID_HANDLE
;
138 if( cbCursorMax
< (SWORD
)0 )
140 PUSHSQLERR ( pstmt
->herr
, en_S1090
);
146 if( pstmt
->state
>= en_stmt_needdata
147 || pstmt
->asyn_on
!= en_NullProc
)
149 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
154 if( pstmt
->state
< en_stmt_cursoropen
155 && pstmt
->cursor_state
== en_stmt_cursor_no
)
157 PUSHSQLERR ( pstmt
->herr
, en_S1015
);
162 /* call driver's function */
163 hproc
= _iodbcdm_getproc ( pstmt
->hdbc
, en_GetCursorName
);
165 if( hproc
== SQL_NULL_HPROC
)
167 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
172 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_GetCursorName
, (
179 retcode
= hproc(pstmt
->dhstmt
,
188 RETCODE SQL_API
SQLRowCount(
192 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
196 if( hstmt
== SQL_NULL_HSTMT
197 || pstmt
->hdbc
== SQL_NULL_HDBC
)
199 return SQL_INVALID_HANDLE
;
203 if( pstmt
->state
>= en_stmt_needdata
204 || pstmt
->state
<= en_stmt_prepared
205 || pstmt
->asyn_on
!= en_NullProc
)
207 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
213 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_RowCount
);
215 if( hproc
== SQL_NULL_HPROC
)
217 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
222 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_RowCount
, (
223 pstmt
->dhstmt
, pcrow
) )
226 retcode
= hproc ( pstmt
->dhstmt
, pcrow
);
232 RETCODE SQL_API
SQLNumResultCols(
236 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
241 if( hstmt
== SQL_NULL_HSTMT
242 || pstmt
->hdbc
== SQL_NULL_HDBC
)
244 return SQL_INVALID_HANDLE
;
248 if( pstmt
->asyn_on
== en_NullProc
)
250 if( pstmt
->state
== en_stmt_allocated
251 || pstmt
->state
>= en_stmt_needdata
)
253 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
257 else if( pstmt
->asyn_on
!= en_NumResultCols
)
259 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
265 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_NumResultCols
);
267 if( hproc
== SQL_NULL_HPROC
)
269 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
274 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_NumResultCols
, (
275 pstmt
->dhstmt
, &ccol
) )
278 retcode
= hproc( pstmt
->dhstmt
, &ccol
);
281 /* state transition */
282 if( pstmt
->asyn_on
== en_NumResultCols
)
287 case SQL_SUCCESS_WITH_INFO
:
289 pstmt
->asyn_on
= en_NullProc
;
291 case SQL_STILL_EXECUTING
:
300 case SQL_SUCCESS_WITH_INFO
:
303 case SQL_STILL_EXECUTING
:
305 pstmt
->asyn_on
= en_NumResultCols
;
321 RETCODE SQL_API
SQLDescribeCol(
324 UCHAR FAR
* szColName
,
326 SWORD FAR
* pcbColName
,
327 SWORD FAR
* pfSqlType
,
328 UDWORD FAR
* pcbColDef
,
330 SWORD FAR
* pfNullable
)
332 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
335 int sqlstat
= en_00000
;
337 if( hstmt
== SQL_NULL_HSTMT
338 || pstmt
->hdbc
== SQL_NULL_HDBC
)
340 return SQL_INVALID_HANDLE
;
343 /* check arguments */
348 else if( cbColNameMax
< 0 )
353 if( sqlstat
!= en_00000
)
355 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
361 if( pstmt
->asyn_on
== en_NullProc
)
363 if( pstmt
->asyn_on
== en_stmt_allocated
364 || pstmt
->asyn_on
>= en_stmt_needdata
)
369 else if( pstmt
->asyn_on
!= en_DescribeCol
)
374 if( sqlstat
!= en_00000
)
376 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
382 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_DescribeCol
);
384 if( hproc
== SQL_NULL_HPROC
)
386 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
391 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_DescribeCol
, (
403 retcode
= hproc(pstmt
->dhstmt
,
414 /* state transition */
415 if( pstmt
->asyn_on
== en_DescribeCol
)
420 case SQL_SUCCESS_WITH_INFO
:
422 pstmt
->asyn_on
= en_NullProc
;
430 switch( pstmt
->state
)
432 case en_stmt_prepared
:
433 case en_stmt_cursoropen
:
434 case en_stmt_fetched
:
435 case en_stmt_xfetched
:
436 if( retcode
== SQL_STILL_EXECUTING
)
438 pstmt
->asyn_on
= en_DescribeCol
;
449 RETCODE SQL_API
SQLColAttributes(
458 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
461 int sqlstat
= en_00000
;
463 if( hstmt
== SQL_NULL_HSTMT
464 || pstmt
->hdbc
== SQL_NULL_HDBC
)
466 return SQL_INVALID_HANDLE
;
469 /* check arguments */
470 if( icol
== 0 && fDescType
!= SQL_COLUMN_COUNT
)
474 else if( cbDescMax
< 0 )
478 else if(/* fDescType < SQL_COLATT_OPT_MIN || */ /* turnoff warning */
479 ( fDescType
> SQL_COLATT_OPT_MAX
480 && fDescType
< SQL_COLUMN_DRIVER_START
) )
485 if( sqlstat
!= en_00000
)
487 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
493 if( pstmt
->asyn_on
== en_NullProc
)
495 if( pstmt
->asyn_on
== en_stmt_allocated
496 || pstmt
->asyn_on
>= en_stmt_needdata
)
501 else if( pstmt
->asyn_on
!= en_ColAttributes
)
506 if( sqlstat
!= en_00000
)
508 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
514 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_ColAttributes
);
516 if( hproc
== SQL_NULL_HPROC
)
518 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
523 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ColAttributes
, (
533 retcode
= hproc(pstmt
->dhstmt
,
542 /* state transition */
543 if( pstmt
->asyn_on
== en_ColAttributes
)
548 case SQL_SUCCESS_WITH_INFO
:
550 pstmt
->asyn_on
= en_NullProc
;
558 switch( pstmt
->state
)
560 case en_stmt_prepared
:
561 case en_stmt_cursoropen
:
562 case en_stmt_fetched
:
563 case en_stmt_xfetched
:
564 if( retcode
== SQL_STILL_EXECUTING
)
566 pstmt
->asyn_on
= en_ColAttributes
;