BOOL CColumns::Open(UINT nOpenType /* = snapshot */, LPCSTR lpszSQL /* = NULL */, DWORD dwOptions /* = none */) { #ifdef WIN32 ASSERT(lpszSQL == NULL); RETCODE nRetCode; // Cache state info and allocate hstmt SetState(nOpenType,NULL,noDirtyFieldCheck | dwOptions); if (!AllocHstmt()) return FALSE; TRY { OnSetOptions(m_hstmt); AllocStatusArrays(); // call the ODBC catalog function with data member params AFX_SQL_ASYNC(this, ::SQLColumns(m_hstmt, (m_strQualifierParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strQualifierParam), SQL_NTS, (m_strOwnerParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strOwnerParam), SQL_NTS, (m_strTableNameParam.IsEmpty()? (UCHAR FAR *)NULL: (UCHAR FAR *)(const char*)m_strTableNameParam), SQL_NTS, NULL, SQL_NTS)); if (!Check(nRetCode)) ThrowDBException(nRetCode, m_hstmt); // Allocate memory and cache info AllocAndCacheFieldInfo(); AllocRowset(); // Fetch the first row of data MoveNext(); // If EOF, result set is empty, set BOF as well m_bBOF = m_bEOF; } CATCH_ALL(e) { Close(); THROW_LAST(); } END_CATCH_ALL return TRUE; #else // WIN16 RETCODE nRetCode; ASSERT(lpszSQL == NULL); // Allocation and opening of database not supported if (m_hstmt == SQL_NULL_HSTMT) { CString strDefaultConnect; TRY { if (m_pDatabase == NULL) { m_pDatabase = new CDatabase(); m_bRecordsetDb = TRUE; } strDefaultConnect = GetDefaultConnect(); // If not already opened, attempt to open if (!m_pDatabase->IsOpen() && !m_pDatabase->Open("", FALSE, FALSE, strDefaultConnect)) return FALSE; AFX_SQL_SYNC(::SQLAllocStmt(m_pDatabase->m_hdbc, &m_hstmt)); if (!Check(nRetCode)) ThrowDBException(SQL_INVALID_HANDLE); // return FALSE; #JB951122 } CATCH_ALL(e) { #ifdef _DEBUG if (afxTraceFlags & 0x20) TRACE0("Error: CDatabase create for CRecordset failed\n"); #endif // _DEBUG strDefaultConnect.Empty(); if (m_bRecordsetDb) { DELETE_OBJ (m_pDatabase); } ASSERT(m_hstmt == SQL_NULL_HSTMT); THROW_LAST(); } END_CATCH_ALL }
BOOL CCurRecordset::Open(UINT nOpenType, LPCTSTR lpszSQL, DWORD dwOptions) { ASSERT(!IsOpen()); ASSERT_VALID(this); ASSERT(lpszSQL == NULL || AfxIsValidString(lpszSQL)); ASSERT(nOpenType == AFX_DB_USE_DEFAULT_TYPE || nOpenType == dynaset || nOpenType == snapshot || nOpenType == forwardOnly || nOpenType == dynamic); ASSERT(!(dwOptions & readOnly && dwOptions & appendOnly)); // Can only use optimizeBulkAdd with appendOnly recordsets ASSERT((dwOptions & optimizeBulkAdd && dwOptions & appendOnly) || !(dwOptions & optimizeBulkAdd)); // forwardOnly recordsets have limited functionality ASSERT(!(nOpenType == forwardOnly && dwOptions & skipDeletedRecords)); // Cache state info and allocate hstmt SetState(nOpenType, lpszSQL, dwOptions); if (!AllocHstmt()) return FALSE; // Check if bookmarks upported (CanBookmark depends on open DB) ASSERT(dwOptions & useBookmarks ? CanBookmark() : TRUE); TRY { OnSetOptions(m_hstmt); // Allocate the field/param status arrays, if necessary BOOL bUnbound = FALSE; if (m_nFields > 0 || m_nParams > 0) AllocStatusArrays(); else bUnbound = TRUE; // Build SQL and prep/execute or just execute direct m_strSQL = lpszSQL; PrepareAndExecute(); // Cache some field info and prepare the rowset AllocAndCacheFieldInfo(); AllocRowset(); // If late binding, still need to allocate status arrays if (bUnbound && (m_nFields > 0 || m_nParams > 0)) AllocStatusArrays(); // Give derived classes a call before binding PreBindFields(); if (m_nResultCols) MoveNext(); // If EOF, then result set empty, so set BOF as well m_bBOF = m_bEOF; } CATCH_ALL(e) { Close(); THROW_LAST(); } END_CATCH_ALL return TRUE; }