]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/execute.c
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 do_cursoropen (STMT_t FAR
* pstmt
)
47 pstmt
->state
= en_stmt_executed
;
49 retcode
= SQLNumResultCols (pstmt
, &ncol
);
51 if (retcode
== SQL_SUCCESS
|| retcode
== SQL_SUCCESS_WITH_INFO
)
55 pstmt
->state
= en_stmt_cursoropen
;
56 pstmt
->cursor_state
= en_stmt_cursor_opened
;
60 pstmt
->state
= en_stmt_executed
;
61 pstmt
->cursor_state
= en_stmt_cursor_no
;
68 SQLExecute (HSTMT hstmt
)
70 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
71 HPROC hproc
= SQL_NULL_HPROC
;
74 int sqlstat
= en_00000
;
76 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
78 return SQL_INVALID_HANDLE
;
82 if (pstmt
->asyn_on
== en_NullProc
)
86 case en_stmt_allocated
:
90 case en_stmt_executed
:
91 if (!pstmt
->prep_state
)
97 case en_stmt_cursoropen
:
98 if (!pstmt
->prep_state
)
104 case en_stmt_fetched
:
105 case en_stmt_xfetched
:
106 if (!pstmt
->prep_state
)
116 case en_stmt_needdata
:
117 case en_stmt_mustput
:
126 else if (pstmt
->asyn_on
!= en_Execute
)
131 if (sqlstat
== en_00000
)
133 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Execute
);
135 if (hproc
== SQL_NULL_HPROC
)
141 if (sqlstat
!= en_00000
)
143 PUSHSQLERR (pstmt
->herr
, sqlstat
);
148 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Execute
,
151 /* stmt state transition */
152 if (pstmt
->asyn_on
== en_Execute
)
157 case SQL_SUCCESS_WITH_INFO
:
160 pstmt
->asyn_on
= en_NullProc
;
163 case SQL_STILL_EXECUTING
:
169 switch (pstmt
->state
)
171 case en_stmt_prepared
:
175 case SQL_SUCCESS_WITH_INFO
:
176 do_cursoropen (hstmt
);
180 pstmt
->state
= en_stmt_needdata
;
181 pstmt
->need_on
= en_Execute
;
184 case SQL_STILL_EXECUTING
:
185 pstmt
->asyn_on
= en_Execute
;
193 case en_stmt_executed
:
197 pstmt
->state
= en_stmt_allocated
;
198 pstmt
->cursor_state
= en_stmt_cursor_no
;
199 pstmt
->prep_state
= 0;
203 pstmt
->state
= en_stmt_needdata
;
204 pstmt
->need_on
= en_Execute
;
207 case SQL_STILL_EXECUTING
:
208 pstmt
->asyn_on
= en_Execute
;
227 UCHAR FAR
* szSqlStr
,
230 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
231 HPROC hproc
= SQL_NULL_HPROC
;
233 int sqlstat
= en_00000
;
234 RETCODE retcode
= SQL_SUCCESS
;
236 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
238 return SQL_INVALID_HANDLE
;
241 /* check arguments */
242 if (szSqlStr
== NULL
)
246 else if (cbSqlStr
< 0 && cbSqlStr
!= SQL_NTS
)
251 if (sqlstat
!= en_00000
)
253 PUSHSQLERR (pstmt
->herr
, sqlstat
);
259 if (pstmt
->asyn_on
== en_NullProc
)
261 switch (pstmt
->state
)
263 case en_stmt_fetched
:
264 case en_stmt_xfetched
:
268 case en_stmt_needdata
:
269 case en_stmt_mustput
:
278 else if (pstmt
->asyn_on
!= en_ExecDirect
)
283 if (sqlstat
!= en_00000
)
285 PUSHSQLERR (pstmt
->herr
, sqlstat
);
290 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_ExecDirect
);
292 if (hproc
== SQL_NULL_HPROC
)
294 PUSHSQLERR (pstmt
->herr
, en_IM001
);
299 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_ExecDirect
,
300 (pstmt
->dhstmt
, szSqlStr
, cbSqlStr
))
302 /* stmt state transition */
303 if (pstmt
->asyn_on
== en_ExecDirect
)
308 case SQL_SUCCESS_WITH_INFO
:
311 pstmt
->asyn_on
= en_NullProc
;
314 case SQL_STILL_EXECUTING
:
320 if (pstmt
->state
<= en_stmt_executed
)
325 case SQL_SUCCESS_WITH_INFO
:
326 do_cursoropen (hstmt
);
330 pstmt
->state
= en_stmt_needdata
;
331 pstmt
->need_on
= en_ExecDirect
;
334 case SQL_STILL_EXECUTING
:
335 pstmt
->asyn_on
= en_ExecDirect
;
339 pstmt
->state
= en_stmt_allocated
;
340 pstmt
->cursor_state
= en_stmt_cursor_no
;
341 pstmt
->prep_state
= 0;
359 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
363 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
365 return SQL_INVALID_HANDLE
;
368 /* check argument value */
369 if (rgbValue
== NULL
&&
370 (cbValue
!= SQL_DEFAULT_PARAM
&& cbValue
!= SQL_NULL_DATA
))
372 PUSHSQLERR (pstmt
->herr
, en_S1009
);
378 if (pstmt
->asyn_on
== en_NullProc
)
380 if (pstmt
->state
<= en_stmt_xfetched
)
382 PUSHSQLERR (pstmt
->herr
, en_S1010
);
387 else if (pstmt
->asyn_on
!= en_PutData
)
389 PUSHSQLERR (pstmt
->herr
, en_S1010
);
395 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_PutData
);
397 if (hproc
== SQL_NULL_HPROC
)
399 PUSHSQLERR (pstmt
->herr
, en_IM001
);
404 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_PutData
,
405 (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
;
475 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
479 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
481 return SQL_INVALID_HANDLE
;
487 if (pstmt
->asyn_on
== en_NullProc
)
489 if (pstmt
->state
<= en_stmt_xfetched
)
491 PUSHSQLERR (pstmt
->herr
, en_S1010
);
496 else if (pstmt
->asyn_on
!= en_ParamData
)
498 PUSHSQLERR (pstmt
->herr
, en_S1010
);
504 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_ParamData
);
506 if (hproc
== SQL_NULL_HPROC
)
508 PUSHSQLERR (pstmt
->herr
, en_IM001
);
513 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_ParamData
,
514 (pstmt
->dhstmt
, prgbValue
))
516 /* state transition */
517 if (pstmt
->asyn_on
== en_ParamData
)
522 case SQL_SUCCESS_WITH_INFO
:
524 pstmt
->asyn_on
= en_NullProc
;
527 case SQL_STILL_EXECUTING
:
533 if (pstmt
->state
< en_stmt_needdata
)
541 switch (pstmt
->need_on
)
544 pstmt
->state
= en_stmt_allocated
;
548 pstmt
->state
= en_stmt_prepared
;
552 pstmt
->state
= en_stmt_xfetched
;
554 = en_stmt_cursor_xfetched
;
560 pstmt
->need_on
= en_NullProc
;
564 case SQL_SUCCESS_WITH_INFO
:
565 switch (pstmt
->state
)
567 case en_stmt_needdata
:
568 pstmt
->state
= en_stmt_mustput
;
572 switch (pstmt
->need_on
)
578 = en_stmt_cursor_xfetched
;
583 do_cursoropen (hstmt
);
594 pstmt
->need_on
= en_NullProc
;
598 pstmt
->state
= en_stmt_mustput
;
614 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
618 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
620 return SQL_INVALID_HANDLE
;
626 if (pstmt
->asyn_on
== en_NullProc
)
628 switch (pstmt
->state
)
630 case en_stmt_allocated
:
631 case en_stmt_needdata
:
632 case en_stmt_mustput
:
634 PUSHSQLERR (pstmt
->herr
, en_S1010
);
641 else if (pstmt
->asyn_on
!= en_NumParams
)
643 PUSHSQLERR (pstmt
->herr
, en_S1010
);
649 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_NumParams
);
651 if (hproc
== SQL_NULL_HPROC
)
653 PUSHSQLERR (pstmt
->herr
, en_IM001
);
658 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_NumParams
,
659 (pstmt
->dhstmt
, pcpar
))
661 /* state transition */
662 if (pstmt
->asyn_on
== en_NumParams
)
667 case SQL_SUCCESS_WITH_INFO
:
676 if (retcode
== SQL_STILL_EXECUTING
)
678 pstmt
->asyn_on
= en_NumParams
;
689 SWORD FAR
* pfSqlType
,
690 UDWORD FAR
* pcbColDef
,
691 SWORD FAR
* pibScale
,
692 SWORD FAR
* pfNullable
)
694 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
698 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
700 return SQL_INVALID_HANDLE
;
706 PUSHSQLERR (pstmt
->herr
, en_S1093
);
712 if (pstmt
->asyn_on
== en_NullProc
)
714 switch (pstmt
->state
)
716 case en_stmt_allocated
:
717 case en_stmt_needdata
:
718 case en_stmt_mustput
:
720 PUSHSQLERR (pstmt
->herr
, en_S1010
);
727 else if (pstmt
->asyn_on
!= en_DescribeParam
)
729 PUSHSQLERR (pstmt
->herr
, en_S1010
);
735 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_DescribeParam
);
737 if (hproc
== SQL_NULL_HPROC
)
739 PUSHSQLERR (pstmt
->herr
, en_IM001
);
744 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_DescribeParam
,
745 (pstmt
->dhstmt
, ipar
, pfSqlType
, pcbColDef
, pibScale
, pfNullable
))
747 /* state transition */
748 if (pstmt
->asyn_on
== en_DescribeParam
)
753 case SQL_SUCCESS_WITH_INFO
:
762 if (retcode
== SQL_STILL_EXECUTING
)
764 pstmt
->asyn_on
= en_DescribeParam
;