- STMT_t FAR* pstmt = (STMT_t FAR*)hstmt;
- HPROC hproc;
- RETCODE retcode;
-
- if( hstmt == SQL_NULL_HSTMT
- || pstmt->hdbc == SQL_NULL_HDBC )
- {
- return SQL_INVALID_HANDLE;
- }
-
- /* check argument value */
- if( rgbValue == NULL
- && ( cbValue != SQL_DEFAULT_PARAM
- && cbValue != SQL_NULL_DATA ) )
- {
- PUSHSQLERR ( pstmt->herr, en_S1009 );
-
- return SQL_ERROR;
- }
-
- /* check state */
- if( pstmt->asyn_on == en_NullProc )
- {
- if( pstmt->state <= en_stmt_xfetched )
- {
- PUSHSQLERR( pstmt->herr, en_S1010 );
-
- return SQL_ERROR;
- }
- }
- else if( pstmt->asyn_on != en_PutData )
- {
- PUSHSQLERR ( pstmt->herr, en_S1010 );
-
- return SQL_ERROR;
- }
-
- /* call driver */
- hproc = _iodbcdm_getproc( pstmt->hdbc, en_PutData );
-
- if( hproc == SQL_NULL_HPROC )
- {
- PUSHSQLERR ( pstmt->herr, en_IM001 );
-
- return SQL_ERROR;
- }
-
- CALL_DRIVER ( pstmt->hdbc, retcode, hproc, en_PutData, (
- pstmt->dhstmt, rgbValue, cbValue ) )
-
-#if 0
- retcode = hproc(pstmt->dhstmt, rgbValue, cbValue );
-#endif
-
- /* state transition */
- if( pstmt->asyn_on == en_PutData )
- {
- switch( retcode )
- {
- case SQL_SUCCESS:
- case SQL_SUCCESS_WITH_INFO:
- case SQL_ERROR:
- pstmt->asyn_on = en_NullProc;
- break;
-
- case SQL_STILL_EXECUTING:
- default:
- return retcode;
- }
- }
-
- /* must in mustput or canput states */
- switch( retcode )
- {
- case SQL_SUCCESS:
- case SQL_SUCCESS_WITH_INFO:
- pstmt->state = en_stmt_canput;
- break;
-
- case SQL_ERROR:
- switch( pstmt->need_on )
- {
- case en_ExecDirect:
- pstmt->state = en_stmt_allocated;
- pstmt->need_on = en_NullProc;
- break;
-
- case en_Execute:
- if( pstmt->prep_state )
- {
- pstmt->state = en_stmt_prepared;
- pstmt->need_on = en_NullProc;
- }
- break;
-
- case en_SetPos:
- /* Is this possible ???? */
- pstmt->state = en_stmt_xfetched;
- break;
-
- default:
- break;
- }
- break;
-
- case SQL_STILL_EXECUTING:
- pstmt->asyn_on = en_PutData;
- break;
-
- default:
- break;
- }
-
- return retcode;
+ STMT_t FAR *pstmt = (STMT_t FAR *) hstmt;
+ HPROC hproc = SQL_NULL_HPROC;
+ RETCODE retcode;
+
+ int sqlstat = en_00000;
+
+ if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC)
+ {
+ return SQL_INVALID_HANDLE;
+ }
+
+ /* check state */
+ if (pstmt->asyn_on == en_NullProc)
+ {
+ switch (pstmt->state)
+ {
+ case en_stmt_allocated:
+ sqlstat = en_S1010;
+ break;
+
+ case en_stmt_executed:
+ if (!pstmt->prep_state)
+ {
+ sqlstat = en_S1010;
+ }
+ break;
+
+ case en_stmt_cursoropen:
+ if (!pstmt->prep_state)
+ {
+ sqlstat = en_S1010;
+ }
+ break;
+
+ case en_stmt_fetched:
+ case en_stmt_xfetched:
+ if (!pstmt->prep_state)
+ {
+ sqlstat = en_S1010;
+ }
+ else
+ {
+ sqlstat = en_24000;
+ }
+ break;
+
+ case en_stmt_needdata:
+ case en_stmt_mustput:
+ case en_stmt_canput:
+ sqlstat = en_S1010;
+ break;
+
+ default:
+ break;
+ }
+ }
+ else if (pstmt->asyn_on != en_Execute)
+ {
+ sqlstat = en_S1010;
+ }
+
+ if (sqlstat == en_00000)
+ {
+ hproc = _iodbcdm_getproc (pstmt->hdbc, en_Execute);
+
+ if (hproc == SQL_NULL_HPROC)
+ {
+ sqlstat = en_IM001;
+ }
+ }
+
+ if (sqlstat != en_00000)
+ {
+ PUSHSQLERR (pstmt->herr, sqlstat);
+
+ return SQL_ERROR;
+ }
+
+ CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_Execute,
+ (pstmt->dhstmt))
+
+ /* stmt state transition */
+ if (pstmt->asyn_on == en_Execute)
+ {
+ switch (retcode)
+ {
+ case SQL_SUCCESS:
+ case SQL_SUCCESS_WITH_INFO:
+ case SQL_NEED_DATA:
+ case SQL_ERROR:
+ pstmt->asyn_on = en_NullProc;
+ break;
+
+ case SQL_STILL_EXECUTING:
+ default:
+ return retcode;
+ }
+ }
+
+ switch (pstmt->state)
+ {
+ case en_stmt_prepared:
+ switch (retcode)
+ {
+ case SQL_SUCCESS:
+ case SQL_SUCCESS_WITH_INFO:
+ do_cursoropen (hstmt);
+ break;
+
+ case SQL_NEED_DATA:
+ pstmt->state = en_stmt_needdata;
+ pstmt->need_on = en_Execute;
+ break;
+
+ case SQL_STILL_EXECUTING:
+ pstmt->asyn_on = en_Execute;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ case en_stmt_executed:
+ switch (retcode)
+ {
+ case SQL_ERROR:
+ pstmt->state = en_stmt_allocated;
+ pstmt->cursor_state = en_stmt_cursor_no;
+ pstmt->prep_state = 0;
+ break;
+
+ case SQL_NEED_DATA:
+ pstmt->state = en_stmt_needdata;
+ pstmt->need_on = en_Execute;
+ break;
+
+ case SQL_STILL_EXECUTING:
+ pstmt->asyn_on = en_Execute;
+ break;
+
+ default:
+ break;
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ return retcode;