RETCODE SQL_API SQLDrivers ( HENV henv, UWORD fDir, UCHAR FAR * szDrvDesc, SWORD cbDrvDescMax, SWORD FAR * pcbDrvDesc, UCHAR FAR * szDrvAttr, SWORD cbDrvAttrMax, SWORD FAR * pcbDrvAttr) { GENV_t FAR *genv = (GENV_t FAR *) henv; if (henv == SQL_NULL_HENV) { return SQL_INVALID_HANDLE; } if (cbDrvDescMax < 0 || cbDrvAttrMax < 0 || cbDrvAttrMax == 1) { PUSHSQLERR (genv->herr, en_S1090); return SQL_ERROR; } if (fDir != SQL_FETCH_FIRST || fDir != SQL_FETCH_NEXT) { PUSHSQLERR (genv->herr, en_S1103); return SQL_ERROR; } /*********************/ return SQL_NO_DATA_FOUND; }
RETCODE SQL_API SQLGetCursorName ( HSTMT hstmt, UCHAR FAR * szCursor, SWORD cbCursorMax, SWORD FAR * pcbCursor) { 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 */ if (cbCursorMax < (SWORD) 0) { PUSHSQLERR (pstmt->herr, en_S1090); return SQL_ERROR; } /* check state */ if (pstmt->state >= en_stmt_needdata || pstmt->asyn_on != en_NullProc) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } if (pstmt->state < en_stmt_cursoropen && pstmt->cursor_state == en_stmt_cursor_no) { PUSHSQLERR (pstmt->herr, en_S1015); return SQL_ERROR; } /* call driver's function */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_GetCursorName); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_GetCursorName, (pstmt->dhstmt, szCursor, cbCursorMax, pcbCursor)) return retcode; }
SQLRETURN SQLFreeEnv_Internal (SQLHENV henv) { GENV (genv, henv); if (!IS_VALID_HENV (genv)) { return SQL_INVALID_HANDLE; } CLEAR_ERRORS (genv); if (genv->hdbc != SQL_NULL_HDBC) { PUSHSQLERR (genv->herr, en_S1010); return SQL_ERROR; } #if (ODBCVER >= 0x300) /* Drop connections from the pool */ while (genv->pdbc_pool != NULL) _iodbcdm_pool_drop_conn (genv->pdbc_pool, NULL); #endif /* * Invalidate this handle */ genv->type = 0; return SQL_SUCCESS; }
RETCODE SQL_API SQLFreeConnect (HDBC hdbc) { GENV_t FAR *genv; DBC_t FAR *pdbc = (DBC_t FAR *) hdbc; DBC_t FAR *tpdbc; if (hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check state */ if (pdbc->state != en_dbc_allocated) { PUSHSQLERR (pdbc->herr, en_S1010); return SQL_ERROR; } genv = (GENV_t FAR *) pdbc->genv; for (tpdbc = (DBC_t FAR *) genv->hdbc; tpdbc != NULL; tpdbc = tpdbc->next) { if (pdbc == tpdbc) { genv->hdbc = pdbc->next; break; } if (pdbc == tpdbc->next) { tpdbc->next = pdbc->next; break; } } /* free this dbc */ _iodbcdm_driverunload (pdbc); _iodbcdm_freesqlerrlist (pdbc->herr); if (pdbc->tfile) { MEM_FREE (pdbc->tfile); } SQLSetConnectOption (pdbc, SQL_OPT_TRACE, SQL_OPT_TRACE_OFF); MEM_FREE (pdbc); return SQL_SUCCESS; }
RETCODE SQL_API SQLRowCount ( HSTMT hstmt, SDWORD FAR * pcrow) { 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 state */ if (pstmt->state >= en_stmt_needdata || pstmt->state <= en_stmt_prepared || pstmt->asyn_on != en_NullProc) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_RowCount); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_RowCount, (pstmt->dhstmt, pcrow)) return retcode; }
int nnodbc_attach_stmt(void* hdbc, void* hstmt) { dbc_t* pdbc = hdbc; gstmt_t* pstmt; pstmt = (gstmt_t*)MEM_ALLOC(sizeof(gstmt_t)); if( ! pstmt ) { PUSHSQLERR( pdbc->herr, en_S1001 ); return SQL_ERROR; } pstmt->next = pdbc->stmt; pdbc->stmt = pstmt; pstmt->hstmt= hstmt; pstmt->hdbc = pdbc; return SQL_SUCCESS; }
RETCODE SQL_API SQLFreeEnv (HENV henv) { GENV_t FAR *genv = (GENV_t *) henv; if (henv == SQL_NULL_HENV) { return SQL_INVALID_HANDLE; } if (genv->hdbc != SQL_NULL_HDBC) { PUSHSQLERR (genv->herr, en_S1010); return SQL_ERROR; } _iodbcdm_freesqlerrlist (genv->herr); MEM_FREE (henv); return SQL_SUCCESS; }
static SQLRETURN SQLParamOptions_Internal ( SQLHSTMT hstmt, SQLULEN crow, SQLULEN * pirow) { STMT (pstmt, hstmt); HPROC hproc2 = SQL_NULL_HPROC; HPROC hproc3 = SQL_NULL_HPROC; SQLRETURN retcode; CONN (pdbc, pstmt->hdbc); SQLUINTEGER odbc_ver = ((GENV_t *) pdbc->genv)->odbc_ver; SQLUINTEGER dodbc_ver = ((ENV_t *) pdbc->henv)->dodbc_ver; if (crow == (SQLULEN) 0UL) { PUSHSQLERR (pstmt->herr, en_S1107); return SQL_ERROR; } if (pstmt->state >= en_stmt_needdata || pstmt->asyn_on != en_NullProc) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } hproc2 = _iodbcdm_getproc (pstmt->hdbc, en_ParamOptions); #if (ODBCVER >= 0x0300) hproc3 = _iodbcdm_getproc (pstmt->hdbc, en_SetStmtAttr); #endif if (odbc_ver == SQL_OV_ODBC2 && ( dodbc_ver == SQL_OV_ODBC2 || (dodbc_ver == SQL_OV_ODBC3 && hproc2 != SQL_NULL_HPROC))) hproc3 = SQL_NULL_HPROC; #if (ODBCVER >= 0x0300) if (hproc3 != SQL_NULL_HPROC) { CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc3, (pstmt->dhstmt, SQL_ATTR_PARAMSET_SIZE, crow, 0)); if (SQL_SUCCEEDED (retcode)) { CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc3, (pstmt->dhstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, pirow, 0)); } } else #endif { if (hproc2 == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc2, (pstmt->dhstmt, crow, pirow)); } pstmt->paramset_size = crow; return retcode; }
static SQLRETURN SQLSetScrollOptions_Internal ( SQLHSTMT hstmt, SQLUSMALLINT fConcurrency, SQLLEN crowKeyset, SQLUSMALLINT crowRowset) { STMT (pstmt, hstmt); CONN (pdbc, pstmt->hdbc); HPROC hproc = SQL_NULL_HPROC; sqlstcode_t sqlstat = en_00000; SQLRETURN retcode = SQL_SUCCESS; SQLUINTEGER odbc_ver = ((GENV_t *) pdbc->genv)->odbc_ver; SQLUINTEGER dodbc_ver = ((ENV_t *) pdbc->henv)->dodbc_ver; for (;;) { if (crowRowset == (UWORD) 0) { sqlstat = en_S1107; break; } if (crowKeyset > (SDWORD) 0L && crowKeyset < (SDWORD) crowRowset) { sqlstat = en_S1107; break; } if (crowKeyset < 1) { if (crowKeyset != SQL_SCROLL_FORWARD_ONLY && crowKeyset != SQL_SCROLL_STATIC && crowKeyset != SQL_SCROLL_KEYSET_DRIVEN && crowKeyset != SQL_SCROLL_DYNAMIC) { sqlstat = en_S1107; break; } } if (fConcurrency != SQL_CONCUR_READ_ONLY && fConcurrency != SQL_CONCUR_LOCK && fConcurrency != SQL_CONCUR_ROWVER && fConcurrency != SQL_CONCUR_VALUES) { sqlstat = en_S1108; break; } #if (ODBCVER < 0x0300) if (pstmt->state != en_stmt_allocated) { sqlstat = en_S1010; break; } #endif hproc = _iodbcdm_getproc (pstmt->hdbc, en_SetScrollOptions); if (dodbc_ver == SQL_OV_ODBC3 && odbc_ver == SQL_OV_ODBC3) hproc = SQL_NULL_HPROC; if (hproc != SQL_NULL_HPROC) { CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc, (pstmt->dhstmt, fConcurrency, crowKeyset, crowRowset)); } else { #if (ODBCVER >= 0x0300) SQLINTEGER InfoValue, InfoType, Value; HPROC hproc1 = _iodbcdm_getproc (pstmt->hdbc, en_SetStmtAttr); HPROC hproc2 = _iodbcdm_getproc (pstmt->hdbc, en_GetInfo); if (hproc1 == SQL_NULL_HPROC || hproc2 == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } switch (crowKeyset) { case SQL_SCROLL_FORWARD_ONLY: InfoType = SQL_FORWARD_ONLY_CURSOR_ATTRIBUTES2; Value = SQL_CURSOR_FORWARD_ONLY; break; case SQL_SCROLL_STATIC: InfoType = SQL_STATIC_CURSOR_ATTRIBUTES2; Value = SQL_CURSOR_STATIC; break; case SQL_SCROLL_DYNAMIC: InfoType = SQL_DYNAMIC_CURSOR_ATTRIBUTES2; Value = SQL_CURSOR_DYNAMIC; break; case SQL_SCROLL_KEYSET_DRIVEN: default: InfoType = SQL_KEYSET_CURSOR_ATTRIBUTES2; Value = SQL_CURSOR_KEYSET_DRIVEN; break; } CALL_DRIVER (pstmt->hdbc, pdbc, retcode, hproc2, (pdbc->dhdbc, InfoType, &InfoValue, 0, NULL)); if (retcode != SQL_SUCCESS) { return retcode; } switch (fConcurrency) { case SQL_CONCUR_READ_ONLY: if (!(InfoValue & SQL_CA2_READ_ONLY_CONCURRENCY)) { PUSHSQLERR (pstmt->herr, en_S1C00); return SQL_ERROR; } break; case SQL_CONCUR_LOCK: if (!(InfoValue & SQL_CA2_LOCK_CONCURRENCY)) { PUSHSQLERR (pstmt->herr, en_S1C00); return SQL_ERROR; } break; case SQL_CONCUR_ROWVER: if (!(InfoValue & SQL_CA2_OPT_ROWVER_CONCURRENCY)) { PUSHSQLERR (pstmt->herr, en_S1C00); return SQL_ERROR; } break; case SQL_CONCUR_VALUES: if (!(InfoValue & SQL_CA2_OPT_VALUES_CONCURRENCY)) { PUSHSQLERR (pstmt->herr, en_S1C00); return SQL_ERROR; } break; } CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc1, (pstmt->dhstmt, SQL_ATTR_CURSOR_TYPE, Value, 0)); if (retcode != SQL_SUCCESS) return retcode; CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc1, (pstmt->dhstmt, SQL_ATTR_CONCURRENCY, fConcurrency, 0)); if (retcode != SQL_SUCCESS) return retcode; if (crowKeyset > 0) { CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc1, (pstmt->dhstmt, SQL_ATTR_KEYSET_SIZE, crowKeyset, 0)); if (retcode != SQL_SUCCESS) return retcode; } CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc1, (pstmt->dhstmt, SQL_ROWSET_SIZE, crowRowset, 0)); if (retcode != SQL_SUCCESS) return retcode; #else sqlstat = en_IM001; break; #endif } sqlstat = en_00000; if (1) /* turn off solaris warning message */ break; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } return retcode; }
RETCODE SQL_API SQLGetData ( HSTMT hstmt, UWORD icol, SWORD fCType, PTR rgbValue, SDWORD cbValueMax, SDWORD FAR * pcbValue) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc; RETCODE retcode; int sqlstat = en_00000; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check argument */ if (rgbValue == NULL) { sqlstat = en_S1009; } else if (cbValueMax < 0) { sqlstat = en_S1090; } else { switch (fCType) { case SQL_C_DEFAULT: case SQL_C_CHAR: case SQL_C_BINARY: case SQL_C_BIT: case SQL_C_TINYINT: case SQL_C_STINYINT: case SQL_C_UTINYINT: case SQL_C_SHORT: case SQL_C_SSHORT: case SQL_C_USHORT: case SQL_C_LONG: case SQL_C_SLONG: case SQL_C_ULONG: case SQL_C_FLOAT: case SQL_C_DOUBLE: case SQL_C_DATE: case SQL_C_TIME: case SQL_C_TIMESTAMP: break; default: sqlstat = en_S1003; break; } } 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_allocated: case en_stmt_prepared: case en_stmt_needdata: case en_stmt_mustput: case en_stmt_canput: sqlstat = en_S1010; break; case en_stmt_executed: case en_stmt_cursoropen: sqlstat = en_24000; break; default: break; } } else if (pstmt->asyn_on != en_GetData) { sqlstat = en_S1010; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_GetData); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_GetData, (pstmt->dhstmt, icol, fCType, rgbValue, cbValueMax, pcbValue)) /* state transition */ if (pstmt->asyn_on == en_GetData) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_NO_DATA_FOUND: case SQL_ERROR: pstmt->asyn_on = en_NullProc; break; case SQL_STILL_EXECUTING: default: return retcode; } } switch (pstmt->state) { case en_stmt_fetched: case en_stmt_xfetched: if (retcode == SQL_STILL_EXECUTING) { pstmt->asyn_on = en_GetData; break; } break; default: break; } return retcode; }
static SQLRETURN SQLBindParameter_Internal ( SQLHSTMT hstmt, SQLUSMALLINT ipar, SQLSMALLINT fParamType, SQLSMALLINT fCType, SQLSMALLINT fSqlType, SQLULEN cbColDef, SQLSMALLINT ibScale, SQLPOINTER rgbValue, SQLLEN cbValueMax, SQLLEN * pcbValue) { STMT (pstmt, hstmt); CONN (pdbc, pstmt->hdbc); ENVR (penv, pdbc->henv); HPROC hproc2 = SQL_NULL_HPROC; HPROC hproc3 = SQL_NULL_HPROC; SQLSMALLINT nCType; SQLSMALLINT nSqlType; sqlstcode_t sqlstat = en_00000; SQLRETURN retcode = SQL_SUCCESS; SQLUINTEGER odbc_ver = ((GENV_t *) pdbc->genv)->odbc_ver; SQLUINTEGER dodbc_ver = ((ENV_t *) pdbc->henv)->dodbc_ver; PPARM newparam; TPARM parm; int size; #if (ODBCVER >= 0x0300) if (0) #else /* check param */ if (fSqlType > SQL_TYPE_MAX || (fSqlType < SQL_TYPE_MIN && fSqlType > SQL_TYPE_DRIVER_START)) /* Note: SQL_TYPE_DRIVER_START is a negative number * So, we use ">" */ #endif { sqlstat = en_S1004; } else if (ipar < 1) { sqlstat = en_S1093; } else if ((rgbValue == NULL && pcbValue == NULL) && fParamType != SQL_PARAM_OUTPUT) { sqlstat = en_S1009; /* This means, I allow output to nowhere * (i.e. * junk output result). But I can't * allow input from nowhere. */ } /********** else if( cbValueMax < 0L && cbValueMax != SQL_SETPARAM_VALUE_MAX ) { sqlstat = en_S1090; } **********/ else if (fParamType != SQL_PARAM_INPUT && fParamType != SQL_PARAM_OUTPUT && fParamType != SQL_PARAM_INPUT_OUTPUT) { sqlstat = en_S1105; } else { switch (fCType) { case SQL_C_DEFAULT: case SQL_C_BINARY: case SQL_C_BIT: case SQL_C_CHAR: case SQL_C_DATE: case SQL_C_DOUBLE: case SQL_C_FLOAT: case SQL_C_LONG: case SQL_C_SHORT: case SQL_C_SLONG: case SQL_C_SSHORT: case SQL_C_STINYINT: case SQL_C_TIME: case SQL_C_TIMESTAMP: case SQL_C_TINYINT: case SQL_C_ULONG: case SQL_C_USHORT: case SQL_C_UTINYINT: #if (ODBCVER >= 0x0300) case SQL_C_GUID: case SQL_C_INTERVAL_DAY: case SQL_C_INTERVAL_DAY_TO_HOUR: case SQL_C_INTERVAL_DAY_TO_MINUTE: case SQL_C_INTERVAL_DAY_TO_SECOND: case SQL_C_INTERVAL_HOUR: case SQL_C_INTERVAL_HOUR_TO_MINUTE: case SQL_C_INTERVAL_HOUR_TO_SECOND: case SQL_C_INTERVAL_MINUTE: case SQL_C_INTERVAL_MINUTE_TO_SECOND: case SQL_C_INTERVAL_MONTH: case SQL_C_INTERVAL_SECOND: case SQL_C_INTERVAL_YEAR: case SQL_C_INTERVAL_YEAR_TO_MONTH: case SQL_C_NUMERIC: case SQL_C_SBIGINT: case SQL_C_TYPE_DATE: case SQL_C_TYPE_TIME: case SQL_C_TYPE_TIMESTAMP: case SQL_C_UBIGINT: case SQL_C_WCHAR: #endif break; default: sqlstat = en_S1003; break; } } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* check state */ if (pstmt->state >= en_stmt_needdata || pstmt->asyn_on != en_NullProc) { PUSHSQLERR (pstmt->herr, en_S1010); retcode = SQL_ERROR; } /* * Convert C type to ODBC version of driver */ nCType = _iodbcdm_map_c_type (fCType, penv->dodbc_ver); /* * Convert SQL type to ODBC version of driver */ nSqlType = _iodbcdm_map_sql_type (fSqlType, penv->dodbc_ver); hproc2 = _iodbcdm_getproc (pstmt->hdbc, en_BindParameter); #if (ODBCVER >=0x0300) hproc3 = _iodbcdm_getproc (pstmt->hdbc, en_BindParam); #endif parm.pm_par = ipar; parm.pm_c_type = nCType; parm.pm_c_type_orig = nCType; parm.pm_sql_type = fSqlType; parm.pm_precision = cbColDef; parm.pm_scale = ibScale; parm.pm_data = rgbValue; parm.pm_pOctetLength = pcbValue; parm.pm_pInd = pcbValue; parm.pm_size = size; parm.pm_usage = fParamType; parm.pm_cbValueMax = cbValueMax; #if (ODBCVER >=0x0300) if (fCType == SQL_C_WCHAR && !penv->unicode_driver && pcbValue && *pcbValue != SQL_DATA_AT_EXEC) nCType = SQL_C_CHAR; #endif if (ipar < 1 || ipar > STMT_MAX_PARAM) { PUSHSQLERR (pstmt->herr, en_S1093); return SQL_ERROR; } if (ipar > pstmt->st_nparam) { size_t newsize = ipar + 10; if (newsize > STMT_MAX_PARAM) newsize = STMT_MAX_PARAM; if ((newparam = calloc (newsize, sizeof (TPARM))) == NULL) { PUSHSQLERR (pstmt->herr, en_S1001); return SQL_ERROR; } if (pstmt->st_pparam) { memcpy (newparam, pstmt->st_pparam, pstmt->st_nparam * sizeof (TPARM)); free (pstmt->st_pparam); } pstmt->st_pparam = newparam; pstmt->st_nparam = (u_short) newsize; } pstmt->st_pparam[ipar-1] = parm; if (odbc_ver == SQL_OV_ODBC2 && ( dodbc_ver == SQL_OV_ODBC2 || (dodbc_ver == SQL_OV_ODBC3 && hproc2 != SQL_NULL_HPROC))) hproc3 = SQL_NULL_HPROC; #if (ODBCVER >=0x0300) if (fParamType == SQL_PARAM_INPUT && hproc3 != SQL_NULL_HPROC) { CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc3, (pstmt->dhstmt, ipar, nCType, nSqlType, cbColDef, ibScale, rgbValue, pcbValue)); } else #endif { if (hproc2 == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, pstmt, retcode, hproc2, (pstmt->dhstmt, ipar, fParamType, nCType, nSqlType, cbColDef, ibScale, rgbValue, cbValueMax, pcbValue)); } return retcode; }
RETCODE SQL_API SQLDescribeCol ( HSTMT hstmt, UWORD icol, UCHAR FAR * szColName, SWORD cbColNameMax, SWORD FAR * pcbColName, SWORD FAR * pfSqlType, UDWORD FAR * pcbColDef, SWORD FAR * pibScale, SWORD FAR * pfNullable) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc; RETCODE retcode; int sqlstat = en_00000; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check arguments */ if (icol == 0) { sqlstat = en_S1002; } else if (cbColNameMax < 0) { sqlstat = en_S1090; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* check state */ if (pstmt->asyn_on == en_NullProc) { if (pstmt->asyn_on == en_stmt_allocated || pstmt->asyn_on >= en_stmt_needdata) { sqlstat = en_S1010; } } else if (pstmt->asyn_on != en_DescribeCol) { sqlstat = en_S1010; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_DescribeCol); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_DescribeCol, (pstmt->dhstmt, icol, szColName, cbColNameMax, pcbColName, pfSqlType, pcbColDef, pibScale, pfNullable)) /* state transition */ if (pstmt->asyn_on == en_DescribeCol) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_ERROR: pstmt->asyn_on = en_NullProc; break; default: return retcode; } } switch (pstmt->state) { case en_stmt_prepared: case en_stmt_cursoropen: case en_stmt_fetched: case en_stmt_xfetched: if (retcode == SQL_STILL_EXECUTING) { pstmt->asyn_on = en_DescribeCol; } break; default: break; } return retcode; }
RETCODE SQL_API SQLColAttributes ( HSTMT hstmt, UWORD icol, UWORD fDescType, PTR rgbDesc, SWORD cbDescMax, SWORD FAR * pcbDesc, SDWORD FAR * pfDesc) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc; RETCODE retcode; int sqlstat = en_00000; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check arguments */ if (icol == 0 && fDescType != SQL_COLUMN_COUNT) { sqlstat = en_S1002; } else if (cbDescMax < 0) { sqlstat = en_S1090; } else if ( /* fDescType < SQL_COLATT_OPT_MIN || *//* turnoff warning */ (fDescType > SQL_COLATT_OPT_MAX && fDescType < SQL_COLUMN_DRIVER_START)) { sqlstat = en_S1091; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* check state */ if (pstmt->asyn_on == en_NullProc) { if (pstmt->asyn_on == en_stmt_allocated || pstmt->asyn_on >= en_stmt_needdata) { sqlstat = en_S1010; } } else if (pstmt->asyn_on != en_ColAttributes) { sqlstat = en_S1010; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_ColAttributes); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_ColAttributes, (pstmt->dhstmt, icol, fDescType, rgbDesc, cbDescMax, pcbDesc, pfDesc)) /* state transition */ if (pstmt->asyn_on == en_ColAttributes) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_ERROR: pstmt->asyn_on = en_NullProc; break; default: return retcode; } } switch (pstmt->state) { case en_stmt_prepared: case en_stmt_cursoropen: case en_stmt_fetched: case en_stmt_xfetched: if (retcode == SQL_STILL_EXECUTING) { pstmt->asyn_on = en_ColAttributes; } break; default: break; } return retcode; }
RETCODE SQL_API SQLParamData ( HSTMT hstmt, PTR FAR * prgbValue) { 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 */ /* 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_ParamData) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_ParamData); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_ParamData, (pstmt->dhstmt, prgbValue)) /* state transition */ if (pstmt->asyn_on == en_ParamData) { 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; } } if (pstmt->state < en_stmt_needdata) { return retcode; } switch (retcode) { case SQL_ERROR: switch (pstmt->need_on) { case en_ExecDirect: pstmt->state = en_stmt_allocated; break; case en_Execute: pstmt->state = en_stmt_prepared; break; case en_SetPos: pstmt->state = en_stmt_xfetched; pstmt->cursor_state = en_stmt_cursor_xfetched; break; default: break; } pstmt->need_on = en_NullProc; break; case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: switch (pstmt->state) { case en_stmt_needdata: pstmt->state = en_stmt_mustput; break; case en_stmt_canput: switch (pstmt->need_on) { case en_SetPos: pstmt->state = en_stmt_xfetched; pstmt->cursor_state = en_stmt_cursor_xfetched; break; case en_ExecDirect: case en_Execute: do_cursoropen (hstmt); break; default: break; } break; default: break; } pstmt->need_on = en_NullProc; break; case SQL_NEED_DATA: pstmt->state = en_stmt_mustput; break; default: break; } return retcode; }
RETCODE SQL_API SQLParamData( HSTMT hstmt, PTR* prgbValue) { stmt_t* pstmt = hstmt; int ipar; param_t* ppar; fptr_t cvt; char* data; date_t dt; UNSET_ERROR( pstmt->herr ); ipar = pstmt->putipar; ppar = pstmt->ppar + ipar - 1; if ( ipar ) { ppar->need = 0; pstmt->ndelay --; if ( ppar->ctype == SQL_C_CHAR ) { if ( ! ppar->putdtbuf && ! ppar->putdtlen ) data = 0; else { cvt = ppar->cvt; data= cvt(ppar->putdtbuf, ppar->putdtlen, &dt); } MEM_FREE( ppar->putdtbuf ); ppar->putdtbuf = 0; ppar->putdtlen = 0; if ( data == (char*)(-1) ) { PUSHSQLERR( pstmt->herr, en_S1000 ); return SQL_ERROR; } sqlputdata( pstmt, ipar, data ); } } if ( pstmt->ndelay ) { for (ipar++, ppar++;;) { if ( ppar->need ) { *prgbValue = (PTR)(ppar->userbuf); pstmt->putipar = ipar; return SQL_NEED_DATA; } } } if ( nnsql_execute(pstmt->yystmt) ) { int code; code = nnsql_errcode( pstmt->yystmt ); if ( code == -1 ) code = errno; PUSHSYSERR( pstmt->herr, code, nnsql_errmsg(pstmt->yystmt)); return SQL_ERROR; } if ( ! nnsql_getcolnum(pstmt->yystmt) && nnsql_getrowcount(pstmt->yystmt) > 1 ) { PUSHSQLERR( pstmt->herr, en_01S04); return SQL_SUCCESS_WITH_INFO; } return SQL_SUCCESS; }
RETCODE SQL_API SQLExecDirect ( HSTMT hstmt, UCHAR FAR * szSqlStr, SDWORD cbSqlStr) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc = SQL_NULL_HPROC; int sqlstat = en_00000; RETCODE retcode = SQL_SUCCESS; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* 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; } hproc = _iodbcdm_getproc (pstmt->hdbc, en_ExecDirect); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_ExecDirect, (pstmt->dhstmt, szSqlStr, cbSqlStr)) /* 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 (pstmt->state <= en_stmt_executed) { 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_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; }
RETCODE SQL_API SQLPutData ( HSTMT hstmt, PTR rgbValue, SDWORD cbValue) { 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)) /* 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; }
RETCODE SQL_API SQLError ( HENV henv, HDBC hdbc, HSTMT hstmt, UCHAR FAR * szSqlstate, SDWORD FAR * pfNativeError, UCHAR FAR * szErrorMsg, SWORD cbErrorMsgMax, SWORD FAR * pcbErrorMsg) { GENV_t FAR *genv = (GENV_t FAR *) henv; DBC_t FAR *pdbc = (DBC_t FAR *) hdbc; STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HDBC thdbc; HENV dhenv = SQL_NULL_HENV; HDBC dhdbc = SQL_NULL_HDBC; HSTMT dhstmt = SQL_NULL_HSTMT; HERR herr = SQL_NULL_HERR; HPROC hproc = SQL_NULL_HPROC; char FAR *errmsg = NULL; char FAR *ststr = NULL; int handle = 0; RETCODE retcode = SQL_SUCCESS; if (hstmt != SQL_NULL_HSTMT) /* retrive stmt err */ { herr = pstmt->herr; thdbc = pstmt->hdbc; if (thdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } hproc = _iodbcdm_getproc (thdbc, en_Error); dhstmt = pstmt->dhstmt; handle = 3; } else if (hdbc != SQL_NULL_HDBC) /* retrive dbc err */ { herr = pdbc->herr; thdbc = hdbc; if (thdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } hproc = _iodbcdm_getproc (thdbc, en_Error); dhdbc = pdbc->dhdbc; handle = 2; if (herr == SQL_NULL_HERR && pdbc->henv == SQL_NULL_HENV) { return SQL_NO_DATA_FOUND; } } else if (henv != SQL_NULL_HENV) /* retrive env err */ { herr = genv->herr; /* Drivers shouldn't push error message * on envoriment handle */ if (herr == SQL_NULL_HERR) { return SQL_NO_DATA_FOUND; } handle = 1; } else { return SQL_INVALID_HANDLE; } if (szErrorMsg != NULL) { if (cbErrorMsgMax < 0 || cbErrorMsgMax > SQL_MAX_MESSAGE_LENGTH - 1) { return SQL_ERROR; /* SQLError() doesn't post error for itself */ } } if (herr == SQL_NULL_HERR) /* no err on drv mng */ { /* call driver */ if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (thdbc, retcode, hproc, en_Error, (dhenv, dhdbc, dhstmt, szSqlstate, pfNativeError, szErrorMsg, cbErrorMsgMax, pcbErrorMsg)) return retcode; } if (szSqlstate != NULL) { int len; /* get sql state string */ ststr = (char FAR *) _iodbcdm_getsqlstate (herr, (void FAR *) sqlerrmsg_tab); if (ststr == NULL) { len = 0; } else { len = (int) STRLEN (ststr); } STRNCPY (szSqlstate, ststr, len); szSqlstate[len] = 0; /* buffer size of szSqlstate is not checked. Applications * suppose provide enough ( not less than 6 bytes ) buffer * or NULL for it. */ } if (pfNativeError != NULL) { /* native error code is specific to data source */ *pfNativeError = (SDWORD) 0L; } if (szErrorMsg == NULL || cbErrorMsgMax == 0) { if (pcbErrorMsg != NULL) { *pcbErrorMsg = (SWORD) 0; } } else { int len; char msgbuf[256] = {'\0'}; /* get sql state message */ errmsg = _iodbcdm_getsqlerrmsg (herr, (void FAR *) sqlerrmsg_tab); if (errmsg == NULL) { errmsg = (char FAR *) ""; } sprintf (msgbuf, "%s%s", sqlerrhd, errmsg); len = STRLEN (msgbuf); if (len < cbErrorMsgMax - 1) { retcode = SQL_SUCCESS; } else { len = cbErrorMsgMax - 1; retcode = SQL_SUCCESS_WITH_INFO; /* and not posts error for itself */ } STRNCPY ((char *) szErrorMsg, msgbuf, len); szErrorMsg[len] = 0; if (pcbErrorMsg != NULL) { *pcbErrorMsg = (SWORD) len; } } switch (handle) /* free this err */ { case 1: genv->herr = _iodbcdm_popsqlerr (genv->herr); break; case 2: pdbc->herr = _iodbcdm_popsqlerr (pdbc->herr); break; case 3: pstmt->herr = _iodbcdm_popsqlerr (pstmt->herr); break; default: break; } return retcode; }
RETCODE SQL_API SQLSetPos ( HSTMT hstmt, UWORD irow, UWORD fOption, UWORD fLock) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc; RETCODE retcode; int sqlstat = en_00000; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check argument value */ if (fOption > SQL_ADD || fLock > SQL_LOCK_UNLOCK) { PUSHSQLERR (pstmt->herr, en_S1009); } /* check state */ if (pstmt->asyn_on == en_NullProc) { switch (pstmt->state) { case en_stmt_allocated: case en_stmt_prepared: case en_stmt_fetched: case en_stmt_needdata: case en_stmt_mustput: case en_stmt_canput: sqlstat = en_S1010; break; case en_stmt_executed: case en_stmt_cursoropen: sqlstat = en_24000; break; default: break; } } else if (pstmt->asyn_on != en_SetPos) { sqlstat = en_S1010; } if (sqlstat != en_00000) { PUSHSQLERR (pstmt->herr, sqlstat); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_SetPos); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_SetPos, (pstmt->dhstmt, irow, fOption, fLock)) /* state transition */ if (pstmt->asyn_on == en_SetPos) { 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; } } /* now, the only possible init state is 'xfetched' */ switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: break; case SQL_NEED_DATA: pstmt->state = en_stmt_needdata; pstmt->need_on = en_SetPos; break; case SQL_STILL_EXECUTING: pstmt->asyn_on = en_SetPos; break; default: break; } return retcode; }
RETCODE SQL_API SQLMoreResults (HSTMT hstmt) { 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 state */ if (pstmt->asyn_on == en_NullProc) { switch (pstmt->state) { case en_stmt_allocated: case en_stmt_prepared: return SQL_NO_DATA_FOUND; case en_stmt_needdata: case en_stmt_mustput: case en_stmt_canput: PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; default: break; } } else if (pstmt->asyn_on != en_MoreResults) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_MoreResults); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_MoreResults, (pstmt->dhstmt)) /* state transition */ if (pstmt->asyn_on == en_MoreResults) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_NO_DATA_FOUND: case SQL_ERROR: pstmt->asyn_on = en_NullProc; break; case SQL_STILL_EXECUTING: default: return retcode; } } switch (pstmt->state) { case en_stmt_allocated: case en_stmt_prepared: /* driver should return SQL_NO_DATA_FOUND */ break; case en_stmt_executed: if (retcode == SQL_NO_DATA_FOUND) { if (pstmt->prep_state) { pstmt->state = en_stmt_prepared; } else { pstmt->state = en_stmt_allocated; } } else if (retcode == SQL_STILL_EXECUTING) { pstmt->asyn_on = en_MoreResults; } break; case en_stmt_cursoropen: case en_stmt_fetched: case en_stmt_xfetched: if (retcode == SQL_SUCCESS) { break; } else if (retcode == SQL_NO_DATA_FOUND) { if (pstmt->prep_state) { pstmt->state = en_stmt_prepared; } else { pstmt->state = en_stmt_allocated; } } else if (retcode == SQL_STILL_EXECUTING) { pstmt->asyn_on = en_MoreResults; } break; default: break; } return retcode; }
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; }
RETCODE SQL_API SQLAllocConnect ( HENV henv, HDBC FAR * phdbc) { GENV_t FAR *genv = (GENV_t FAR *) henv; DBC_t FAR *pdbc; #if (ODBCVER >= 0x0300) if (henv == SQL_NULL_HENV || genv->type != SQL_HANDLE_ENV) #else if (henv == SQL_NULL_HENV) #endif { return SQL_INVALID_HANDLE; } if (phdbc == NULL) { PUSHSQLERR (genv->herr, en_S1009); return SQL_ERROR; } pdbc = (DBC_t FAR *) MEM_ALLOC (sizeof (DBC_t)); if (pdbc == NULL) { *phdbc = SQL_NULL_HDBC; PUSHSQLERR (genv->herr, en_S1001); return SQL_ERROR; } #if (ODBCVER >= 0x0300) pdbc->type = SQL_HANDLE_DBC; #endif /* insert this dbc entry into the link list */ pdbc->next = genv->hdbc; genv->hdbc = pdbc; pdbc->genv = henv; pdbc->henv = SQL_NULL_HENV; pdbc->hstmt = SQL_NULL_HSTMT; pdbc->herr = SQL_NULL_HERR; pdbc->dhdbc = SQL_NULL_HDBC; pdbc->state = en_dbc_allocated; pdbc->trace = 0; pdbc->tstm = NULL; pdbc->tfile = NULL; /* set connect options to default values */ pdbc->access_mode = SQL_MODE_DEFAULT; pdbc->autocommit = SQL_AUTOCOMMIT_DEFAULT; pdbc->current_qualifier = NULL; pdbc->login_timeout = 0UL; pdbc->odbc_cursors = SQL_CUR_DEFAULT; pdbc->packet_size = 0UL; pdbc->quiet_mode = (UDWORD) NULL; pdbc->txn_isolation = SQL_TXN_READ_UNCOMMITTED; pdbc->cb_commit = (SWORD) SQL_CB_DELETE; pdbc->cb_rollback = (SWORD) SQL_CB_DELETE; *phdbc = (HDBC) pdbc; return SQL_SUCCESS; }
RETCODE SQL_API SQLSetConnectOption ( HDBC hdbc, UWORD fOption, UDWORD vParam) { DBC_t FAR *pdbc = (DBC_t FAR *) hdbc; STMT_t FAR *pstmt; HPROC hproc = SQL_NULL_HPROC; int sqlstat = en_00000; RETCODE retcode = SQL_SUCCESS; if (hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check option */ if (fOption < SQL_CONN_OPT_MIN || (fOption > SQL_CONN_OPT_MAX && fOption < SQL_CONNECT_OPT_DRVR_START)) { PUSHSQLERR (pdbc->herr, en_S1092); return SQL_ERROR; } /* check state of connection handle */ switch (pdbc->state) { case en_dbc_allocated: if (fOption == SQL_TRANSLATE_DLL || fOption == SQL_TRANSLATE_OPTION) { /* This two options are only meaningful * for specified driver. So, has to be * set after a dirver has been loaded. */ sqlstat = en_08003; break; } if (fOption >= SQL_CONNECT_OPT_DRVR_START && pdbc->henv == SQL_NULL_HENV) /* An option only meaningful for drivers * is passed before loading a driver. * We classify this as an invalid option error. * This is not documented by MS SDK guide. */ { sqlstat = en_S1092; break; } break; case en_dbc_needdata: sqlstat = en_S1010; break; case en_dbc_connected: case en_dbc_hstmt: if (fOption == SQL_ODBC_CURSORS) { sqlstat = en_08002; } break; default: break; } /* check state of statement handle(s) */ for (pstmt = (STMT_t FAR *) pdbc->hstmt; pstmt != NULL && sqlstat == en_00000; pstmt = (STMT_t FAR *) pstmt->next) { if (pstmt->state >= en_stmt_needdata || pstmt->asyn_on != en_NullProc) { sqlstat = en_S1010; } } if (sqlstat != en_00000) { PUSHSQLERR (pdbc->herr, sqlstat); return SQL_ERROR; } if (fOption == SQL_OPT_TRACE) /* tracing flag can be set before and after connect * and only meaningful for driver manager(actually * there is only one tracing file under one global * environment). */ { switch (vParam) { case SQL_OPT_TRACE_ON: if (pdbc->tfile == NULL) { pdbc->tfile = (char FAR *) MEM_ALLOC (1 + STRLEN (SQL_OPT_TRACE_FILE_DEFAULT)); if (pdbc->tfile == NULL) { PUSHSQLERR (pdbc->herr, en_S1001); return SQL_ERROR; } STRCPY (pdbc->tfile, SQL_OPT_TRACE_FILE_DEFAULT); } if (pdbc->tstm == NULL) { #if defined(stderr) && defined(stdout) if (STREQ (pdbc->tfile, "stderr")) { pdbc->tstm = stderr; } else if (STREQ (pdbc->tfile, "stdout")) { pdbc->tstm = stdout; } else #endif { pdbc->tstm = fopen (pdbc->tfile, "a+"); } if (pdbc->tstm) { pdbc->trace = 1; } else { pdbc->trace = 0; sqlstat = en_IM013; retcode = SQL_ERROR; } } break; case SQL_OPT_TRACE_OFF: if (pdbc->trace && pdbc->tstm) { #if defined(stderr) && defined(stdout) if (stderr != (FILE FAR *) (pdbc->tstm) && stdout != (FILE FAR *) (pdbc->tstm)) #endif { fclose (pdbc->tstm); } } pdbc->tstm = NULL; pdbc->trace = 0; break; default: PUSHSQLERR (pdbc->herr, en_S1009); retcode = SQL_ERROR; } if (sqlstat != en_00000) { PUSHSQLERR (pdbc->herr, sqlstat); } return retcode; } if (fOption == SQL_OPT_TRACEFILE) /* Tracing file can be set before and after connect * and only meaningful for driver manager. */ { if (vParam == 0UL || ((char FAR *) vParam)[0] == 0) { PUSHSQLERR (pdbc->herr, en_S1009); return SQL_ERROR; } if (pdbc->tfile && STREQ (pdbc->tfile, vParam)) { return SQL_SUCCESS; } if (pdbc->trace) { PUSHSQLERR (pdbc->herr, en_IM014); return SQL_ERROR; } if (pdbc->tfile) { MEM_FREE (pdbc->tfile); } pdbc->tfile = (char FAR *) MEM_ALLOC (1 + STRLEN (vParam)); if (pdbc->tfile == NULL) { PUSHSQLERR (pdbc->herr, en_S1001); return SQL_ERROR; } STRCPY (pdbc->tfile, vParam); return SQL_SUCCESS; } if (pdbc->state != en_dbc_allocated) { /* If already connected, then, driver's odbc call * will be invoked. Otherwise, we only save the options * and delay the setting process until the connection * been established. */ hproc = _iodbcdm_getproc (hdbc, en_SetConnectOption); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pdbc->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (hdbc, retcode, hproc, en_SetConnectOption, (pdbc->dhdbc, fOption, vParam)) if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO) { return retcode; } }
RETCODE SQL_API SQLExecute (HSTMT hstmt) { 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; }
RETCODE SQL_API SQLNumResultCols ( HSTMT hstmt, SWORD FAR * pccol) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc; RETCODE retcode; SWORD ccol; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check state */ if (pstmt->asyn_on == en_NullProc) { if (pstmt->state == en_stmt_allocated || pstmt->state >= en_stmt_needdata) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } } else if (pstmt->asyn_on != en_NumResultCols) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_NumResultCols); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_NumResultCols, (pstmt->dhstmt, &ccol)) /* state transition */ if (pstmt->asyn_on == en_NumResultCols) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_ERROR: pstmt->asyn_on = en_NullProc; case SQL_STILL_EXECUTING: default: break; } } switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: break; case SQL_STILL_EXECUTING: ccol = 0; pstmt->asyn_on = en_NumResultCols; break; default: ccol = 0; break; } if (pccol) { *pccol = ccol; } return retcode; }
RETCODE SQL_API SQLDescribeParam ( HSTMT hstmt, UWORD ipar, SWORD FAR * pfSqlType, UDWORD FAR * pcbColDef, SWORD FAR * pibScale, SWORD FAR * pfNullable) { 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 */ if (ipar == 0) { PUSHSQLERR (pstmt->herr, en_S1093); return SQL_ERROR; } /* check state */ if (pstmt->asyn_on == en_NullProc) { switch (pstmt->state) { case en_stmt_allocated: case en_stmt_needdata: case en_stmt_mustput: case en_stmt_canput: PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; default: break; } } else if (pstmt->asyn_on != en_DescribeParam) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_DescribeParam); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_DescribeParam, (pstmt->dhstmt, ipar, pfSqlType, pcbColDef, pibScale, pfNullable)) /* state transition */ if (pstmt->asyn_on == en_DescribeParam) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_ERROR: break; default: return retcode; } } if (retcode == SQL_STILL_EXECUTING) { pstmt->asyn_on = en_DescribeParam; } return retcode; }
RETCODE SQL_API SQLBindCol ( HSTMT hstmt, UWORD icol, SWORD fCType, PTR rgbValue, SDWORD cbValueMax, SDWORD FAR * pcbValue) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc = SQL_NULL_HPROC; RETCODE retcode; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check argument */ switch (fCType) { case SQL_C_DEFAULT: case SQL_C_CHAR: case SQL_C_BINARY: case SQL_C_BIT: case SQL_C_TINYINT: case SQL_C_STINYINT: case SQL_C_UTINYINT: case SQL_C_SHORT: case SQL_C_SSHORT: case SQL_C_USHORT: case SQL_C_LONG: case SQL_C_SLONG: case SQL_C_ULONG: case SQL_C_FLOAT: case SQL_C_DOUBLE: case SQL_C_DATE: case SQL_C_TIME: case SQL_C_TIMESTAMP: break; default: PUSHSQLERR (pstmt->herr, en_S1003); return SQL_ERROR; } if (cbValueMax < 0) { PUSHSQLERR (pstmt->herr, en_S1090); return SQL_ERROR; } /* check state */ if (pstmt->state > en_stmt_needdata || pstmt->asyn_on != en_NullProc) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } /* call driver's function */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_BindCol); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_BindCol, (pstmt->dhstmt, icol, fCType, rgbValue, cbValueMax, pcbValue)) return retcode; }
SQLRETURN SQL_API SQLSetCursorName_Internal ( SQLHSTMT hstmt, SQLPOINTER szCursor, SQLSMALLINT cbCursor, 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 * _Cursor = NULL; if (szCursor == NULL) { PUSHSQLERR (pstmt->herr, en_S1009); return SQL_ERROR; } if (cbCursor < 0 && cbCursor != SQL_NTS) { PUSHSQLERR (pstmt->herr, en_S1090); return SQL_ERROR; } /* check state */ if (pstmt->asyn_on != en_NullProc) { sqlstat = en_S1010; } else { switch (pstmt->state) { case en_stmt_executed_with_info: case en_stmt_executed: case en_stmt_cursoropen: 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; } } 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*/ _Cursor = dm_SQL_A2W ((SQLCHAR *) szCursor, cbCursor); } else { /* unicode=>ansi*/ _Cursor = dm_SQL_W2A ((SQLWCHAR *) szCursor, cbCursor); } szCursor = _Cursor; cbCursor = SQL_NTS; } CALL_UDRIVER(pstmt->hdbc, pstmt, retcode, hproc, penv->unicode_driver, en_SetCursorName, ( pstmt->dhstmt, szCursor, cbCursor)); MEM_FREE(_Cursor); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } if (SQL_SUCCEEDED (retcode)) { pstmt->cursor_state = en_stmt_cursor_named; } return retcode; }
RETCODE SQL_API SQLNumParams ( HSTMT hstmt, SWORD FAR * pcpar) { 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 */ /* check state */ if (pstmt->asyn_on == en_NullProc) { switch (pstmt->state) { case en_stmt_allocated: case en_stmt_needdata: case en_stmt_mustput: case en_stmt_canput: PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; default: break; } } else if (pstmt->asyn_on != en_NumParams) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } /* call driver */ hproc = _iodbcdm_getproc (pstmt->hdbc, en_NumParams); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_NumParams, (pstmt->dhstmt, pcpar)) /* state transition */ if (pstmt->asyn_on == en_NumParams) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_ERROR: break; default: return retcode; } } if (retcode == SQL_STILL_EXECUTING) { pstmt->asyn_on = en_NumParams; } return retcode; }
RETCODE SQL_API SQLExtendedFetch ( HSTMT hstmt, UWORD fFetchType, SDWORD irow, UDWORD FAR * pcrow, UWORD FAR * rgfRowStatus) { STMT_t FAR *pstmt = (STMT_t FAR *) hstmt; HPROC hproc = SQL_NULL_HPROC; RETCODE retcode; if (hstmt == SQL_NULL_HSTMT || pstmt->hdbc == SQL_NULL_HDBC) { return SQL_INVALID_HANDLE; } /* check fetch type */ if (fFetchType < SQL_FETCH_NEXT || fFetchType > SQL_FETCH_BOOKMARK) { /* Unlike MS driver manager(i.e. DM), * we don't check driver's ODBC version * against SQL_FETCH_RESUME (only 1.0) * and SQL_FETCH_BOOKMARK (only 2.0). */ PUSHSQLERR (pstmt->herr, en_S1106); return SQL_ERROR; } /* check state */ if (pstmt->asyn_on == en_NullProc) { switch (pstmt->state) { case en_stmt_allocated: case en_stmt_prepared: case en_stmt_fetched: case en_stmt_needdata: case en_stmt_mustput: case en_stmt_canput: PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; default: break; } } else if (pstmt->asyn_on != en_ExtendedFetch) { PUSHSQLERR (pstmt->herr, en_S1010); return SQL_ERROR; } hproc = _iodbcdm_getproc (pstmt->hdbc, en_ExtendedFetch); if (hproc == SQL_NULL_HPROC) { PUSHSQLERR (pstmt->herr, en_IM001); return SQL_ERROR; } CALL_DRIVER (pstmt->hdbc, retcode, hproc, en_ExtendedFetch, (pstmt->dhstmt, fFetchType, irow, pcrow, rgfRowStatus)) /* state transition */ if (pstmt->asyn_on == en_ExtendedFetch) { switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_NO_DATA_FOUND: case SQL_ERROR: pstmt->asyn_on = en_NullProc; break; case SQL_STILL_EXECUTING: default: return retcode; } } switch (pstmt->state) { case en_stmt_cursoropen: case en_stmt_xfetched: switch (retcode) { case SQL_SUCCESS: case SQL_SUCCESS_WITH_INFO: case SQL_NO_DATA_FOUND: pstmt->state = en_stmt_xfetched; pstmt->cursor_state = en_stmt_cursor_xfetched; break; case SQL_STILL_EXECUTING: pstmt->asyn_on = en_ExtendedFetch; break; default: break; } break; default: break; } return retcode; }