]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/prepare.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.
49 STMT_t FAR
*pstmt
= (STMT_t
*) hstmt
;
51 HPROC hproc
= SQL_NULL_HPROC
;
52 RETCODE retcode
= SQL_SUCCESS
;
53 int sqlstat
= en_00000
;
55 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
57 return SQL_INVALID_HANDLE
;
61 if (pstmt
->asyn_on
== en_NullProc
)
63 /* not on asyn state */
67 case en_stmt_xfetched
:
71 case en_stmt_needdata
:
81 else if (pstmt
->asyn_on
!= en_Prepare
)
87 if (sqlstat
!= en_00000
)
89 PUSHSQLERR (pstmt
->herr
, sqlstat
);
96 PUSHSQLERR (pstmt
->herr
, en_S1009
);
101 if (cbSqlStr
< 0 && cbSqlStr
!= SQL_NTS
)
103 PUSHSQLERR (pstmt
->herr
, en_S1090
);
108 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_Prepare
);
110 if (hproc
== SQL_NULL_HPROC
)
112 PUSHSQLERR (pstmt
->herr
, en_IM001
);
116 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_Prepare
,
117 (pstmt
->dhstmt
, szSqlStr
, cbSqlStr
))
119 /* stmt state transition */
120 if (pstmt
->asyn_on
== en_Prepare
)
125 case SQL_SUCCESS_WITH_INFO
:
127 pstmt
->asyn_on
= en_NullProc
;
130 case SQL_STILL_EXECUTING
:
138 case SQL_STILL_EXECUTING
:
139 pstmt
->asyn_on
= en_Prepare
;
143 case SQL_SUCCESS_WITH_INFO
:
144 pstmt
->state
= en_stmt_prepared
;
145 pstmt
->prep_state
= 1;
149 switch (pstmt
->state
)
151 case en_stmt_prepared
:
152 case en_stmt_executed
:
153 pstmt
->state
= en_stmt_allocated
;
154 pstmt
->prep_state
= 0;
172 UCHAR FAR
* szCursor
,
175 STMT_t FAR
*pstmt
= (STMT_t
*) hstmt
;
176 HPROC hproc
= SQL_NULL_HPROC
;
178 RETCODE retcode
= SQL_SUCCESS
;
179 int sqlstat
= en_00000
;
181 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
183 return SQL_INVALID_HANDLE
;
186 if (szCursor
== NULL
)
188 PUSHSQLERR (pstmt
->herr
, en_S1009
);
193 if (cbCursor
< 0 && cbCursor
!= SQL_NTS
)
195 PUSHSQLERR (pstmt
->herr
, en_S1090
);
201 if (pstmt
->asyn_on
!= en_NullProc
)
207 switch (pstmt
->state
)
209 case en_stmt_executed
:
210 case en_stmt_cursoropen
:
211 case en_stmt_fetched
:
212 case en_stmt_xfetched
:
216 case en_stmt_needdata
:
217 case en_stmt_mustput
:
227 if (sqlstat
!= en_00000
)
229 PUSHSQLERR (pstmt
->herr
, sqlstat
);
234 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_SetCursorName
);
236 if (hproc
== SQL_NULL_HPROC
)
238 PUSHSQLERR (pstmt
->herr
, en_IM001
);
243 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_SetCursorName
,
244 (pstmt
->dhstmt
, szCursor
, cbCursor
))
246 if (retcode
== SQL_SUCCESS
|| retcode
== SQL_SUCCESS_WITH_INFO
)
248 pstmt
->cursor_state
= en_stmt_cursor_named
;
266 SDWORD FAR
* pcbValue
)
268 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
269 HPROC hproc
= SQL_NULL_HPROC
;
271 int sqlstat
= en_00000
;
272 RETCODE retcode
= SQL_SUCCESS
;
274 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
276 return SQL_INVALID_HANDLE
;
280 if (fSqlType
> SQL_TYPE_MAX
||
281 (fSqlType
< SQL_TYPE_MIN
&& fSqlType
> SQL_TYPE_DRIVER_START
))
282 /* Note: SQL_TYPE_DRIVER_START is a nagtive number
291 else if ((rgbValue
== NULL
&& pcbValue
== NULL
)
292 && fParamType
!= SQL_PARAM_OUTPUT
)
295 /* This means, I allow output to nowhere
296 * (i.e. * junk output result). But I can't
297 * allow input from nowhere.
301 else if( cbValueMax < 0L && cbValueMax != SQL_SETPARAM_VALUE_MAX )
306 else if (fParamType
!= SQL_PARAM_INPUT
307 && fParamType
!= SQL_PARAM_OUTPUT
308 && fParamType
!= SQL_PARAM_INPUT_OUTPUT
)
333 case SQL_C_TIMESTAMP
:
342 if (sqlstat
!= en_00000
)
344 PUSHSQLERR (pstmt
->herr
, sqlstat
);
350 if (pstmt
->state
>= en_stmt_needdata
|| pstmt
->asyn_on
!= en_NullProc
)
352 PUSHSQLERR (pstmt
->herr
, en_S1010
);
357 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_BindParameter
);
359 if (hproc
== SQL_NULL_HPROC
)
361 PUSHSQLERR (pstmt
->herr
, en_IM001
);
366 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_BindParameter
,
367 (pstmt
->dhstmt
, ipar
, fParamType
, fCType
, fSqlType
, cbColDef
,
368 ibScale
, rgbValue
, cbValueMax
, pcbValue
))
380 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
384 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
386 return SQL_INVALID_HANDLE
;
389 if (crow
== (UDWORD
) 0UL)
391 PUSHSQLERR (pstmt
->herr
, en_S1107
);
396 if (pstmt
->state
>= en_stmt_needdata
|| pstmt
->asyn_on
!= en_NullProc
)
398 PUSHSQLERR (pstmt
->herr
, en_S1010
);
403 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_ParamOptions
);
405 if (hproc
== SQL_NULL_HPROC
)
407 PUSHSQLERR (pstmt
->herr
, en_IM001
);
412 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_ParamOptions
,
413 (pstmt
->dhstmt
, crow
, pirow
))
420 SQLSetScrollOptions (
426 STMT_t FAR
*pstmt
= (STMT_t FAR
*) hstmt
;
428 int sqlstat
= en_00000
;
431 if (hstmt
== SQL_NULL_HSTMT
|| pstmt
->hdbc
== SQL_NULL_HDBC
)
433 return SQL_INVALID_HANDLE
;
438 if (crowRowset
== (UWORD
) 0)
444 if (crowKeyset
> (SDWORD
) 0L && crowKeyset
< (SDWORD
) crowRowset
)
452 if (crowKeyset
!= SQL_SCROLL_FORWARD_ONLY
453 && crowKeyset
!= SQL_SCROLL_STATIC
454 && crowKeyset
!= SQL_SCROLL_KEYSET_DRIVEN
455 && crowKeyset
!= SQL_SCROLL_DYNAMIC
)
462 if (fConcurrency
!= SQL_CONCUR_READ_ONLY
463 && fConcurrency
!= SQL_CONCUR_LOCK
464 && fConcurrency
!= SQL_CONCUR_ROWVER
465 && fConcurrency
!= SQL_CONCUR_VALUES
)
471 if (pstmt
->state
!= en_stmt_allocated
)
477 hproc
= _iodbcdm_getproc (pstmt
->hdbc
, en_SetScrollOptions
);
479 if (hproc
== SQL_NULL_HPROC
)
486 if (1) /* turn off solaris warning message */
490 if (sqlstat
!= en_00000
)
492 PUSHSQLERR (pstmt
->herr
, sqlstat
);
497 CALL_DRIVER (pstmt
->hdbc
, retcode
, hproc
, en_SetScrollOptions
,
498 (pstmt
->dhstmt
, fConcurrency
, crowKeyset
, crowRowset
))
513 SDWORD FAR
* pcbValue
)
515 return SQLBindParameter (hstmt
,
517 (SWORD
) SQL_PARAM_INPUT_OUTPUT
,
523 SQL_SETPARAM_VALUE_MAX
,