SQLRETURN SQL_API SQLPrepare_Internal ( SQLHSTMT hstmt, SQLPOINTER szSqlStr, SQLINTEGER cbSqlStr, SQLCHAR waMode) { STMT (pstmt, hstmt); CONN (pdbc, pstmt->hdbc); ENVR (penv, pdbc->henv); HPROC hproc = SQL_NULL_HPROC; SQLRETURN retcode = SQL_SUCCESS; sqlstcode_t sqlstat = en_00000; void * _SqlStr = NULL; /* check state */ if (pstmt->asyn_on == en_NullProc) { /* not on asyn state */ switch (pstmt->state) { case en_stmt_fetched: case en_stmt_xfetched: 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_Prepare) { /* asyn on other */ sqlstat = en_S1010; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } if (szSqlStr == NULL) { PUSHSQLERR (pstmt->herr, en_S1009); return SQL_ERROR; } if (cbSqlStr < 0 && cbSqlStr != SQL_NTS) { PUSHSQLERR (pstmt->herr, en_S1090); return SQL_ERROR; } if ((penv->unicode_driver && waMode != 'W') || (!penv->unicode_driver && waMode == 'W')) { if (waMode != 'W') { /* ansi=>unicode*/ _SqlStr = _iodbcdm_conv_var_A2W(pstmt, 0, (SQLCHAR *) szSqlStr, cbSqlStr); } else { /* unicode=>ansi*/ _SqlStr = _iodbcdm_conv_var_W2A(pstmt, 0, (SQLWCHAR *) szSqlStr, cbSqlStr); } szSqlStr = _SqlStr; cbSqlStr = SQL_NTS; } CALL_UDRIVER(pstmt->hdbc, pstmt, retcode, hproc, penv->unicode_driver, en_Prepare, ( pstmt->dhstmt, szSqlStr, cbSqlStr)); if (hproc == SQL_NULL_HPROC) { _iodbcdm_FreeStmtVars(pstmt); PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } if (retcode != SQL_STILL_EXECUTING) _iodbcdm_FreeStmtVars(pstmt); /* stmt state transition */ if (pstmt->asyn_on == en_Prepare) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_ERROR: pstmt->asyn_on = en_NullProc; return retcode; case SQL_STILL_EXECUTING: default: return retcode; } } switch (retcode) { case SQL_STILL_EXECUTING: pstmt->asyn_on = en_Prepare; break; case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: pstmt->state = en_stmt_prepared; pstmt->prep_state = 1; break; case SQL_ERROR: switch (pstmt->state) { case en_stmt_prepared: case en_stmt_executed_with_info: case en_stmt_executed: pstmt->state = en_stmt_allocated; pstmt->prep_state = 0; break; default: break; } default: break; } return retcode; }
SQLRETURN SQL_API SQLExecDirect_Internal (SQLHSTMT hstmt, SQLPOINTER szSqlStr, SQLINTEGER cbSqlStr, SQLCHAR waMode) { STMT (pstmt, hstmt); CONN (pdbc, pstmt->hdbc); ENVR (penv, pdbc->henv); HPROC hproc = SQL_NULL_HPROC; SQLRETURN retcode = SQL_SUCCESS; sqlstcode_t sqlstat = en_00000; void * _SqlStr = NULL; /* check arguments */ if (szSqlStr == NULL) { sqlstat = en_S1009; } else if (cbSqlStr < 0 && cbSqlStr != SQL_NTS) { sqlstat = en_S1090; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* check state */ if (pstmt->asyn_on == en_NullProc) { switch (pstmt->state) { case en_stmt_fetched: case en_stmt_xfetched: 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_ExecDirect) { sqlstat = en_S1010; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } if ((penv->unicode_driver && waMode != 'W') || (!penv->unicode_driver && waMode == 'W')) { if (waMode != 'W') { /* ansi=>unicode*/ _SqlStr = _iodbcdm_conv_var_A2W(pstmt, 0, (SQLCHAR *) szSqlStr, cbSqlStr); } else { /* unicode=>ansi*/ _SqlStr = _iodbcdm_conv_var_W2A(pstmt, 0, (SQLWCHAR *) szSqlStr, cbSqlStr); } szSqlStr = _SqlStr; cbSqlStr = SQL_NTS; } if ((retcode = _SQLExecute_ConvParams(hstmt, FALSE)) != SQL_SUCCESS) return retcode; CALL_UDRIVER(pstmt->hdbc, pstmt, retcode, hproc, penv->unicode_driver, en_ExecDirect, ( pstmt->dhstmt, szSqlStr, cbSqlStr)); if (hproc == SQL_NULL_HPROC) { _iodbcdm_FreeStmtVars(pstmt); PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } if (retcode != SQL_STILL_EXECUTING) _iodbcdm_FreeStmtVars(pstmt); /* stmt state transition */ if (pstmt->asyn_on == en_ExecDirect) { 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; } } if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO) retcode = _SQLExecute_ConvParams(hstmt, TRUE); if (pstmt->state <= en_stmt_executed) { switch (retcode) { case SQL_SUCCESS: _iodbcdm_do_cursoropen (pstmt); pstmt->prep_state = 1; break; case SQL_SUCCESS_WITH_INFO: pstmt->state = en_stmt_executed_with_info; pstmt->prep_state = 1; break; case SQL_NEED_DATA: pstmt->state = en_stmt_needdata; pstmt->need_on = en_ExecDirect; break; case SQL_STILL_EXECUTING: pstmt->asyn_on = en_ExecDirect; break; case SQL_ERROR: pstmt->state = en_stmt_allocated; pstmt->cursor_state = en_stmt_cursor_no; pstmt->prep_state = 0; break; default: break; } } return retcode; }