]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/execute.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 static void do_cursoropen(STMT_t FAR
* pstmt
)
35 pstmt
->state
= en_stmt_executed
;
37 retcode
= SQLNumResultCols( pstmt
, &ncol
);
39 if( retcode
== SQL_SUCCESS
40 || retcode
== SQL_SUCCESS_WITH_INFO
)
44 pstmt
->state
= en_stmt_cursoropen
;
45 pstmt
->cursor_state
= en_stmt_cursor_opened
;
49 pstmt
->state
= en_stmt_executed
;
50 pstmt
->cursor_state
= en_stmt_cursor_no
;
55 RETCODE SQL_API
SQLExecute ( HSTMT hstmt
)
57 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
58 HPROC hproc
= SQL_NULL_HPROC
;
61 int sqlstat
= en_00000
;
63 if( hstmt
== SQL_NULL_HSTMT
64 || pstmt
->hdbc
== SQL_NULL_HDBC
)
66 return SQL_INVALID_HANDLE
;
70 if( pstmt
->asyn_on
== en_NullProc
)
72 switch( pstmt
->state
)
74 case en_stmt_allocated
:
78 case en_stmt_executed
:
79 if( ! pstmt
->prep_state
)
85 case en_stmt_cursoropen
:
86 if( ! pstmt
->prep_state
)
93 case en_stmt_xfetched
:
94 if( ! pstmt
->prep_state
)
104 case en_stmt_needdata
:
105 case en_stmt_mustput
:
114 else if( pstmt
->asyn_on
!= en_Execute
)
119 if( sqlstat
== en_00000
)
121 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Execute
);
123 if( hproc
== SQL_NULL_HPROC
)
129 if( sqlstat
!= en_00000
)
131 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
136 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
,
137 en_Execute
, ( pstmt
->dhstmt
) )
140 retcode
= hproc ( pstmt
->dhstmt
);
143 /* stmt state transition */
144 if( pstmt
->asyn_on
== en_Execute
)
149 case SQL_SUCCESS_WITH_INFO
:
152 pstmt
->asyn_on
= en_NullProc
;
155 case SQL_STILL_EXECUTING
:
161 switch( pstmt
->state
)
163 case en_stmt_prepared
:
167 case SQL_SUCCESS_WITH_INFO
:
168 do_cursoropen(hstmt
);
172 pstmt
->state
= en_stmt_needdata
;
173 pstmt
->need_on
= en_Execute
;
176 case SQL_STILL_EXECUTING
:
177 pstmt
->asyn_on
= en_Execute
;
185 case en_stmt_executed
:
189 pstmt
->state
= en_stmt_allocated
;
190 pstmt
->cursor_state
= en_stmt_cursor_no
;
191 pstmt
->prep_state
= 0;
195 pstmt
->state
= en_stmt_needdata
;
196 pstmt
->need_on
= en_Execute
;
199 case SQL_STILL_EXECUTING
:
200 pstmt
->asyn_on
= en_Execute
;
215 RETCODE SQL_API
SQLExecDirect (
220 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
221 HPROC hproc
= SQL_NULL_HPROC
;
223 int sqlstat
= en_00000
;
224 RETCODE retcode
= SQL_SUCCESS
;
226 if( hstmt
== SQL_NULL_HSTMT
227 || pstmt
->hdbc
== SQL_NULL_HDBC
)
229 return SQL_INVALID_HANDLE
;
232 /* check arguments */
233 if( szSqlStr
== NULL
)
237 else if( cbSqlStr
< 0 && cbSqlStr
!= SQL_NTS
)
242 if( sqlstat
!= en_00000
)
244 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
250 if( pstmt
->asyn_on
== en_NullProc
)
252 switch ( pstmt
->state
)
254 case en_stmt_fetched
:
255 case en_stmt_xfetched
:
259 case en_stmt_needdata
:
260 case en_stmt_mustput
:
269 else if( pstmt
->asyn_on
!= en_ExecDirect
)
274 if( sqlstat
!= en_00000
)
276 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
281 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_ExecDirect
);
283 if( hproc
== SQL_NULL_HPROC
)
285 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
290 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ExecDirect
, (
291 pstmt
->dhstmt
, szSqlStr
, cbSqlStr
) )
295 retcode
= hproc ( pstmt
->dhstmt
, szSqlStr
, cbSqlStr
);
298 /* stmt state transition */
299 if( pstmt
->asyn_on
== en_ExecDirect
)
304 case SQL_SUCCESS_WITH_INFO
:
307 pstmt
->asyn_on
= en_NullProc
;
310 case SQL_STILL_EXECUTING
:
316 if( pstmt
->state
<= en_stmt_executed
)
321 case SQL_SUCCESS_WITH_INFO
:
322 do_cursoropen(hstmt
);
326 pstmt
->state
= en_stmt_needdata
;
327 pstmt
->need_on
= en_ExecDirect
;
330 case SQL_STILL_EXECUTING
:
331 pstmt
->asyn_on
= en_ExecDirect
;
335 pstmt
->state
= en_stmt_allocated
;
336 pstmt
->cursor_state
= en_stmt_cursor_no
;
337 pstmt
->prep_state
= 0;
348 RETCODE SQL_API
SQLPutData(
353 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
357 if( hstmt
== SQL_NULL_HSTMT
358 || pstmt
->hdbc
== SQL_NULL_HDBC
)
360 return SQL_INVALID_HANDLE
;
363 /* check argument value */
365 && ( cbValue
!= SQL_DEFAULT_PARAM
366 && cbValue
!= SQL_NULL_DATA
) )
368 PUSHSQLERR ( pstmt
->herr
, en_S1009
);
374 if( pstmt
->asyn_on
== en_NullProc
)
376 if( pstmt
->state
<= en_stmt_xfetched
)
378 PUSHSQLERR( pstmt
->herr
, en_S1010
);
383 else if( pstmt
->asyn_on
!= en_PutData
)
385 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
391 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_PutData
);
393 if( hproc
== SQL_NULL_HPROC
)
395 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
400 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_PutData
, (
401 pstmt
->dhstmt
, rgbValue
, cbValue
) )
404 retcode
= hproc(pstmt
->dhstmt
, rgbValue
, cbValue
);
407 /* state transition */
408 if( pstmt
->asyn_on
== en_PutData
)
413 case SQL_SUCCESS_WITH_INFO
:
415 pstmt
->asyn_on
= en_NullProc
;
418 case SQL_STILL_EXECUTING
:
424 /* must in mustput or canput states */
428 case SQL_SUCCESS_WITH_INFO
:
429 pstmt
->state
= en_stmt_canput
;
433 switch( pstmt
->need_on
)
436 pstmt
->state
= en_stmt_allocated
;
437 pstmt
->need_on
= en_NullProc
;
441 if( pstmt
->prep_state
)
443 pstmt
->state
= en_stmt_prepared
;
444 pstmt
->need_on
= en_NullProc
;
449 /* Is this possible ???? */
450 pstmt
->state
= en_stmt_xfetched
;
458 case SQL_STILL_EXECUTING
:
459 pstmt
->asyn_on
= en_PutData
;
469 RETCODE SQL_API
SQLParamData (
473 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
477 if( hstmt
== SQL_NULL_HSTMT
478 || pstmt
->hdbc
== SQL_NULL_HDBC
)
480 return SQL_INVALID_HANDLE
;
486 if( pstmt
->asyn_on
== en_NullProc
)
488 if( pstmt
->state
<= en_stmt_xfetched
)
490 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
495 else if( pstmt
->asyn_on
!= en_ParamData
)
497 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
503 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_ParamData
);
505 if( hproc
== SQL_NULL_HPROC
)
507 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
512 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ParamData
, (
513 pstmt
->dhstmt
, prgbValue
) )
516 retcode
= hproc ( pstmt
->dhstmt
, prgbValue
);
519 /* state transition */
520 if( pstmt
->asyn_on
== en_ParamData
)
525 case SQL_SUCCESS_WITH_INFO
:
527 pstmt
->asyn_on
= en_NullProc
;
530 case SQL_STILL_EXECUTING
:
536 if( pstmt
->state
< en_stmt_needdata
)
544 switch( pstmt
->need_on
)
547 pstmt
->state
= en_stmt_allocated
;
551 pstmt
->state
= en_stmt_prepared
;
555 pstmt
->state
= en_stmt_xfetched
;
557 = en_stmt_cursor_xfetched
;
563 pstmt
->need_on
= en_NullProc
;
567 case SQL_SUCCESS_WITH_INFO
:
568 switch( pstmt
->state
)
570 case en_stmt_needdata
:
571 pstmt
->state
= en_stmt_mustput
;
575 switch( pstmt
->need_on
)
581 = en_stmt_cursor_xfetched
;
586 do_cursoropen(hstmt
);
597 pstmt
->need_on
= en_NullProc
;
601 pstmt
->state
= en_stmt_mustput
;
612 RETCODE SQL_API
SQLNumParams (
616 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
620 if( hstmt
== SQL_NULL_HSTMT
621 || pstmt
->hdbc
== SQL_NULL_HDBC
)
623 return SQL_INVALID_HANDLE
;
629 if( pstmt
->asyn_on
== en_NullProc
)
631 switch( pstmt
->state
)
633 case en_stmt_allocated
:
634 case en_stmt_needdata
:
635 case en_stmt_mustput
:
637 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
644 else if( pstmt
->asyn_on
!= en_NumParams
)
646 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
652 hproc
= _iodbcdm_getproc ( pstmt
->hdbc
, en_NumParams
);
654 if( hproc
== SQL_NULL_HPROC
)
656 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
661 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_NumParams
, (
662 pstmt
->dhstmt
, pcpar
) )
666 retcode
= hproc ( pstmt
->dhstmt
, pcpar
);
669 /* state transition */
670 if( pstmt
->asyn_on
== en_NumParams
)
675 case SQL_SUCCESS_WITH_INFO
:
684 if( retcode
== SQL_STILL_EXECUTING
)
686 pstmt
->asyn_on
= en_NumParams
;
692 RETCODE SQL_API
SQLDescribeParam (
695 SWORD FAR
* pfSqlType
,
696 UDWORD FAR
* pcbColDef
,
698 SWORD FAR
* pfNullable
)
700 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
704 if( hstmt
== SQL_NULL_HSTMT
705 || pstmt
->hdbc
== SQL_NULL_HDBC
)
707 return SQL_INVALID_HANDLE
;
713 PUSHSQLERR ( pstmt
->herr
, en_S1093
);
719 if( pstmt
->asyn_on
== en_NullProc
)
721 switch( pstmt
->state
)
723 case en_stmt_allocated
:
724 case en_stmt_needdata
:
725 case en_stmt_mustput
:
727 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
734 else if( pstmt
->asyn_on
!= en_DescribeParam
)
736 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
742 hproc
= _iodbcdm_getproc ( pstmt
->hdbc
, en_DescribeParam
);
744 if( hproc
== SQL_NULL_HPROC
)
746 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
751 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_DescribeParam
, (
760 retcode
= hproc(pstmt
->dhstmt
,
768 /* state transition */
769 if( pstmt
->asyn_on
== en_DescribeParam
)
774 case SQL_SUCCESS_WITH_INFO
:
783 if( retcode
== SQL_STILL_EXECUTING
)
785 pstmt
->asyn_on
= en_DescribeParam
;