]>
git.saurik.com Git - wxWidgets.git/blob - src/iodbc/prepare.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 RETCODE SQL_API
SQLPrepare (
35 STMT_t FAR
* pstmt
= (STMT_t
*)hstmt
;
37 HPROC hproc
= SQL_NULL_HPROC
;
38 RETCODE retcode
= SQL_SUCCESS
;
39 int sqlstat
= en_00000
;
41 if( hstmt
== SQL_NULL_HSTMT
42 || pstmt
->hdbc
== SQL_NULL_HDBC
)
44 return SQL_INVALID_HANDLE
;
48 if( pstmt
->asyn_on
== en_NullProc
)
50 /* not on asyn state */
51 switch( pstmt
->state
)
54 case en_stmt_xfetched
:
58 case en_stmt_needdata
:
68 else if( pstmt
->asyn_on
!= en_Prepare
)
74 if( sqlstat
!= en_00000
)
76 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
81 if( szSqlStr
== NULL
)
83 PUSHSQLERR ( pstmt
->herr
, en_S1009
);
88 if( cbSqlStr
< 0 && cbSqlStr
!= SQL_NTS
)
90 PUSHSQLERR ( pstmt
->herr
, en_S1090
);
95 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Prepare
);
97 if( hproc
== SQL_NULL_HPROC
)
99 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
103 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Prepare
, (
104 pstmt
->dhstmt
, szSqlStr
, cbSqlStr
) )
107 retcode
= hproc ( pstmt
->dhstmt
, szSqlStr
, cbSqlStr
);
110 /* stmt state transition */
111 if( pstmt
->asyn_on
== en_Prepare
)
116 case SQL_SUCCESS_WITH_INFO
:
118 pstmt
->asyn_on
= en_NullProc
;
121 case SQL_STILL_EXECUTING
:
129 case SQL_STILL_EXECUTING
:
130 pstmt
->asyn_on
= en_Prepare
;
134 case SQL_SUCCESS_WITH_INFO
:
135 pstmt
->state
= en_stmt_prepared
;
136 pstmt
->prep_state
= 1;
140 switch( pstmt
->state
)
142 case en_stmt_prepared
:
143 case en_stmt_executed
:
144 pstmt
->state
= en_stmt_allocated
;
145 pstmt
->prep_state
= 0;
159 RETCODE SQL_API
SQLSetCursorName (
164 STMT_t FAR
* pstmt
= (STMT_t
*)hstmt
;
165 HPROC hproc
= SQL_NULL_HPROC
;
167 RETCODE retcode
= SQL_SUCCESS
;
168 int sqlstat
= en_00000
;
170 if( hstmt
== SQL_NULL_HSTMT
171 || pstmt
->hdbc
== SQL_NULL_HDBC
)
173 return SQL_INVALID_HANDLE
;
176 if( szCursor
== NULL
)
178 PUSHSQLERR ( pstmt
->herr
, en_S1009
);
183 if( cbCursor
< 0 && cbCursor
!= SQL_NTS
)
185 PUSHSQLERR ( pstmt
->herr
, en_S1090
);
191 if( pstmt
->asyn_on
!= en_NullProc
)
197 switch( pstmt
->state
)
199 case en_stmt_executed
:
200 case en_stmt_cursoropen
:
201 case en_stmt_fetched
:
202 case en_stmt_xfetched
:
206 case en_stmt_needdata
:
207 case en_stmt_mustput
:
217 if( sqlstat
!= en_00000
)
219 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
224 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_SetCursorName
);
226 if( hproc
== SQL_NULL_HPROC
)
228 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
233 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_SetCursorName
, (
234 pstmt
->dhstmt
, szCursor
, cbCursor
) )
237 retcode
= hproc ( pstmt
->dhstmt
, szCursor
, cbCursor
);
240 if( retcode
== SQL_SUCCESS
241 || retcode
== SQL_SUCCESS_WITH_INFO
)
243 pstmt
->cursor_state
= en_stmt_cursor_named
;
249 RETCODE SQL_API
SQLBindParameter (
259 SDWORD FAR
* pcbValue
)
261 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
262 HPROC hproc
= SQL_NULL_HPROC
;
264 int sqlstat
= en_00000
;
265 RETCODE retcode
= SQL_SUCCESS
;
267 if( hstmt
== SQL_NULL_HSTMT
268 || pstmt
->hdbc
== SQL_NULL_HDBC
)
270 return SQL_INVALID_HANDLE
;
274 if( fSqlType
> SQL_TYPE_MAX
275 || ( fSqlType
< SQL_TYPE_MIN
276 && fSqlType
> SQL_TYPE_DRIVER_START
) )
277 /* Note: SQL_TYPE_DRIVER_START is a nagtive number
286 else if( (rgbValue
== NULL
&& pcbValue
== NULL
)
287 && fParamType
!= SQL_PARAM_OUTPUT
)
290 /* This means, I allow output to nowhere
291 * (i.e. * junk output result). But I can't
292 * allow input from nowhere.
296 else if( cbValueMax < 0L && cbValueMax != SQL_SETPARAM_VALUE_MAX )
301 else if( fParamType
!= SQL_PARAM_INPUT
302 && fParamType
!= SQL_PARAM_OUTPUT
303 && fParamType
!= SQL_PARAM_INPUT_OUTPUT
)
328 case SQL_C_TIMESTAMP
:
337 if(sqlstat
!= en_00000
)
339 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
345 if( pstmt
->state
>= en_stmt_needdata
346 || pstmt
->asyn_on
!= en_NullProc
)
348 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
353 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_BindParameter
);
355 if( hproc
== SQL_NULL_HPROC
)
357 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
362 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_BindParameter
, (
363 pstmt
->dhstmt
, ipar
, fParamType
, fCType
, fSqlType
,
364 cbColDef
, ibScale
, rgbValue
, cbValueMax
, pcbValue
) )
367 retcode
= hproc(pstmt
->dhstmt
, ipar
, fParamType
, fCType
, fSqlType
,
368 cbColDef
, ibScale
, rgbValue
, cbValueMax
, pcbValue
);
374 RETCODE SQL_API
SQLParamOptions(
379 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
383 if( hstmt
== SQL_NULL_HSTMT
384 || 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
397 || pstmt
->asyn_on
!= en_NullProc
)
399 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
404 hproc
= _iodbcdm_getproc ( pstmt
->hdbc
, en_ParamOptions
);
406 if( hproc
== SQL_NULL_HPROC
)
408 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
413 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ParamOptions
, (
414 pstmt
->dhstmt
, crow
, pirow
) )
417 retcode
= hproc ( pstmt
->dhstmt
, crow
, pirow
);
423 RETCODE SQL_API
SQLSetScrollOptions(
429 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
431 int sqlstat
= en_00000
;
434 if( hstmt
== SQL_NULL_HSTMT
435 || pstmt
->hdbc
== SQL_NULL_HDBC
)
437 return SQL_INVALID_HANDLE
;
442 if( crowRowset
== (UWORD
)0 )
448 if( crowKeyset
> (SDWORD
)0L && crowKeyset
< (SDWORD
)crowRowset
)
456 if( crowKeyset
!= SQL_SCROLL_FORWARD_ONLY
457 && crowKeyset
!= SQL_SCROLL_STATIC
458 && crowKeyset
!= SQL_SCROLL_KEYSET_DRIVEN
459 && crowKeyset
!= SQL_SCROLL_DYNAMIC
)
466 if( fConcurrency
!= SQL_CONCUR_READ_ONLY
467 && fConcurrency
!= SQL_CONCUR_LOCK
468 && fConcurrency
!= SQL_CONCUR_ROWVER
469 && fConcurrency
!= SQL_CONCUR_VALUES
)
475 if( pstmt
->state
!= en_stmt_allocated
)
481 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_SetScrollOptions
);
483 if( hproc
== SQL_NULL_HPROC
)
490 if( 1 ) /* turn off solaris warning message */
494 if( sqlstat
!= en_00000
)
496 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
501 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_SetScrollOptions
, (
508 retcode
= hproc(pstmt
->dhstmt
,
517 RETCODE SQL_API
SQLSetParam (
525 SDWORD FAR
*pcbValue
)
527 return SQLBindParameter(hstmt
,
529 (SWORD
)SQL_PARAM_INPUT_OUTPUT
,
535 SQL_SETPARAM_VALUE_MAX
,