]>
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>
31 RETCODE SQL_API
SQLPrepare (
36 STMT_t FAR
* pstmt
= (STMT_t
*)hstmt
;
38 HPROC hproc
= SQL_NULL_HPROC
;
39 RETCODE retcode
= SQL_SUCCESS
;
40 int sqlstat
= en_00000
;
42 if( hstmt
== SQL_NULL_HSTMT
43 || pstmt
->hdbc
== SQL_NULL_HDBC
)
45 return SQL_INVALID_HANDLE
;
49 if( pstmt
->asyn_on
== en_NullProc
)
51 /* not on asyn state */
52 switch( pstmt
->state
)
55 case en_stmt_xfetched
:
59 case en_stmt_needdata
:
69 else if( pstmt
->asyn_on
!= en_Prepare
)
75 if( sqlstat
!= en_00000
)
77 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
82 if( szSqlStr
== NULL
)
84 PUSHSQLERR ( pstmt
->herr
, en_S1009
);
89 if( cbSqlStr
< 0 && cbSqlStr
!= SQL_NTS
)
91 PUSHSQLERR ( pstmt
->herr
, en_S1090
);
96 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_Prepare
);
98 if( hproc
== SQL_NULL_HPROC
)
100 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
104 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_Prepare
, (
105 pstmt
->dhstmt
, szSqlStr
, cbSqlStr
) )
108 retcode
= hproc ( pstmt
->dhstmt
, szSqlStr
, cbSqlStr
);
111 /* stmt state transition */
112 if( pstmt
->asyn_on
== en_Prepare
)
117 case SQL_SUCCESS_WITH_INFO
:
119 pstmt
->asyn_on
= en_NullProc
;
122 case SQL_STILL_EXECUTING
:
130 case SQL_STILL_EXECUTING
:
131 pstmt
->asyn_on
= en_Prepare
;
135 case SQL_SUCCESS_WITH_INFO
:
136 pstmt
->state
= en_stmt_prepared
;
137 pstmt
->prep_state
= 1;
141 switch( pstmt
->state
)
143 case en_stmt_prepared
:
144 case en_stmt_executed
:
145 pstmt
->state
= en_stmt_allocated
;
146 pstmt
->prep_state
= 0;
160 RETCODE SQL_API
SQLSetCursorName (
165 STMT_t FAR
* pstmt
= (STMT_t
*)hstmt
;
166 HPROC hproc
= SQL_NULL_HPROC
;
168 RETCODE retcode
= SQL_SUCCESS
;
169 int sqlstat
= en_00000
;
171 if( hstmt
== SQL_NULL_HSTMT
172 || pstmt
->hdbc
== SQL_NULL_HDBC
)
174 return SQL_INVALID_HANDLE
;
177 if( szCursor
== NULL
)
179 PUSHSQLERR ( pstmt
->herr
, en_S1009
);
184 if( cbCursor
< 0 && cbCursor
!= SQL_NTS
)
186 PUSHSQLERR ( pstmt
->herr
, en_S1090
);
192 if( pstmt
->asyn_on
!= en_NullProc
)
198 switch( pstmt
->state
)
200 case en_stmt_executed
:
201 case en_stmt_cursoropen
:
202 case en_stmt_fetched
:
203 case en_stmt_xfetched
:
207 case en_stmt_needdata
:
208 case en_stmt_mustput
:
218 if( sqlstat
!= en_00000
)
220 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
225 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_SetCursorName
);
227 if( hproc
== SQL_NULL_HPROC
)
229 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
234 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_SetCursorName
, (
235 pstmt
->dhstmt
, szCursor
, cbCursor
) )
238 retcode
= hproc ( pstmt
->dhstmt
, szCursor
, cbCursor
);
241 if( retcode
== SQL_SUCCESS
242 || retcode
== SQL_SUCCESS_WITH_INFO
)
244 pstmt
->cursor_state
= en_stmt_cursor_named
;
250 RETCODE SQL_API
SQLBindParameter (
260 SDWORD FAR
* pcbValue
)
262 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
263 HPROC hproc
= SQL_NULL_HPROC
;
265 int sqlstat
= en_00000
;
266 RETCODE retcode
= SQL_SUCCESS
;
268 if( hstmt
== SQL_NULL_HSTMT
269 || pstmt
->hdbc
== SQL_NULL_HDBC
)
271 return SQL_INVALID_HANDLE
;
275 if( fSqlType
> SQL_TYPE_MAX
276 || ( fSqlType
< SQL_TYPE_MIN
277 && fSqlType
> SQL_TYPE_DRIVER_START
) )
278 /* Note: SQL_TYPE_DRIVER_START is a nagtive number
287 else if( (rgbValue
== NULL
&& pcbValue
== NULL
)
288 && fParamType
!= SQL_PARAM_OUTPUT
)
291 /* This means, I allow output to nowhere
292 * (i.e. * junk output result). But I can't
293 * allow input from nowhere.
297 else if( cbValueMax < 0L && cbValueMax != SQL_SETPARAM_VALUE_MAX )
302 else if( fParamType
!= SQL_PARAM_INPUT
303 && fParamType
!= SQL_PARAM_OUTPUT
304 && fParamType
!= SQL_PARAM_INPUT_OUTPUT
)
329 case SQL_C_TIMESTAMP
:
338 if(sqlstat
!= en_00000
)
340 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
346 if( pstmt
->state
>= en_stmt_needdata
347 || pstmt
->asyn_on
!= en_NullProc
)
349 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
354 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_BindParameter
);
356 if( hproc
== SQL_NULL_HPROC
)
358 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
363 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_BindParameter
, (
364 pstmt
->dhstmt
, ipar
, fParamType
, fCType
, fSqlType
,
365 cbColDef
, ibScale
, rgbValue
, cbValueMax
, pcbValue
) )
368 retcode
= hproc(pstmt
->dhstmt
, ipar
, fParamType
, fCType
, fSqlType
,
369 cbColDef
, ibScale
, rgbValue
, cbValueMax
, pcbValue
);
375 RETCODE SQL_API
SQLParamOptions(
380 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
384 if( hstmt
== SQL_NULL_HSTMT
385 || pstmt
->hdbc
== SQL_NULL_HDBC
)
387 return SQL_INVALID_HANDLE
;
390 if( crow
== (UDWORD
)0UL )
392 PUSHSQLERR ( pstmt
->herr
, en_S1107
);
397 if( pstmt
->state
>= en_stmt_needdata
398 || pstmt
->asyn_on
!= en_NullProc
)
400 PUSHSQLERR ( pstmt
->herr
, en_S1010
);
405 hproc
= _iodbcdm_getproc ( pstmt
->hdbc
, en_ParamOptions
);
407 if( hproc
== SQL_NULL_HPROC
)
409 PUSHSQLERR ( pstmt
->herr
, en_IM001
);
414 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_ParamOptions
, (
415 pstmt
->dhstmt
, crow
, pirow
) )
418 retcode
= hproc ( pstmt
->dhstmt
, crow
, pirow
);
424 RETCODE SQL_API
SQLSetScrollOptions(
430 STMT_t FAR
* pstmt
= (STMT_t FAR
*)hstmt
;
432 int sqlstat
= en_00000
;
435 if( hstmt
== SQL_NULL_HSTMT
436 || pstmt
->hdbc
== SQL_NULL_HDBC
)
438 return SQL_INVALID_HANDLE
;
443 if( crowRowset
== (UWORD
)0 )
449 if( crowKeyset
> (SDWORD
)0L && crowKeyset
< (SDWORD
)crowRowset
)
457 if( crowKeyset
!= SQL_SCROLL_FORWARD_ONLY
458 && crowKeyset
!= SQL_SCROLL_STATIC
459 && crowKeyset
!= SQL_SCROLL_KEYSET_DRIVEN
460 && crowKeyset
!= SQL_SCROLL_DYNAMIC
)
467 if( fConcurrency
!= SQL_CONCUR_READ_ONLY
468 && fConcurrency
!= SQL_CONCUR_LOCK
469 && fConcurrency
!= SQL_CONCUR_ROWVER
470 && fConcurrency
!= SQL_CONCUR_VALUES
)
476 if( pstmt
->state
!= en_stmt_allocated
)
482 hproc
= _iodbcdm_getproc( pstmt
->hdbc
, en_SetScrollOptions
);
484 if( hproc
== SQL_NULL_HPROC
)
491 if( 1 ) /* turn off solaris warning message */
495 if( sqlstat
!= en_00000
)
497 PUSHSQLERR ( pstmt
->herr
, sqlstat
);
502 CALL_DRIVER ( pstmt
->hdbc
, retcode
, hproc
, en_SetScrollOptions
, (
509 retcode
= hproc(pstmt
->dhstmt
,
518 RETCODE SQL_API
SQLSetParam (
526 SDWORD FAR
*pcbValue
)
528 return SQLBindParameter(hstmt
,
530 (SWORD
)SQL_PARAM_INPUT_OUTPUT
,
536 SQL_SETPARAM_VALUE_MAX
,