//*************************************************************************** BOOL CBCGPDAOGridCtrl::GetFieldList (LPCTSTR lpszTable, CStringList& lstField) { ASSERT (lpszTable != NULL); lstField.RemoveAll (); try { if (m_pDataBase == NULL) { ASSERT (FALSE); return FALSE; } ASSERT_VALID (m_pDataBase); if (!m_pDataBase->IsOpen ()) { ASSERT (FALSE); return FALSE; } CDaoRecordset* pRecordSet = new CDaoRecordset (m_pDataBase); CString strSQL = _T("SELECT * FROM "); strSQL += lpszTable; pRecordSet->Open (AFX_DAO_USE_DEFAULT_TYPE, strSQL); if (!pRecordSet->IsOpen ()) { delete pRecordSet; return FALSE; } const short nColumns = pRecordSet->GetFieldCount (); for (short nColumn = 0; nColumn < nColumns; nColumn++) { CDaoFieldInfo info; pRecordSet->GetFieldInfo (nColumn, info); lstField.AddTail (info.m_strName); } pRecordSet->Close (); delete pRecordSet; } catch (CDaoException* pEx) { OnDaoException (pEx); pEx->Delete (); return FALSE; } return TRUE; }
int GetFieldPos(CDaoRecordset& recs, LPCTSTR fieldName) { CDaoFieldInfo fi; int count = recs.GetFieldCount(); for( int i = 0; i < count; i++ ) { recs.GetFieldInfo(i, fi); if( fi.m_strName.Compare( fieldName ) == 0 ) return i; // when found a match, return it } return -1; }
// globale Funktion // richtiger Tabellentyp BOOL CheckTable (CDaoRecordset &Set, FieldKonvert *pInfo, const CString& strTableName) { try { CWaitCursor wc; CMutex mt; ASSERT (Set.IsOpen ()); ASSERT (NULL != pInfo); // Suche alle Felder CDaoFieldInfo FieldInfo; CString strError; while (pInfo && pInfo -> pFieldName && *pInfo -> pFieldName) { try { Set.GetFieldInfo (pInfo -> pFieldName, FieldInfo); } catch (CMemoryException *me) { me -> ReportError (); me -> Delete (); return FALSE; } catch (CDaoException *de) { de -> Delete (); AfxFormatString1 (strError, IDS_FIELD_NOT_FOUND, pInfo -> pFieldName); throw strError; } // Datentyp ok ? if (FieldInfo.m_nType != pInfo -> sType) { AfxFormatString1 (strError, IDS_FIELD_NO_TYPE, pInfo -> pFieldName); throw strError; } // ggf. auch Länge vergleichen if ((pInfo -> sLen > 0) && (pInfo -> sLen < FieldInfo.m_lSize)) // angeg. Länge muß kleiner gleich tatsächlicher sein { CString strLen; strLen.Format ("%ld", pInfo -> sLen); AfxFormatString2 (strError, IDS_FIELD_NO_LEN, pInfo -> pFieldName, strLen); throw strError; } pInfo++; } return TRUE; } catch (CString str) { // Struktur stimmt nicht: Meldung an Nutzer CString strOutput; AfxFormatString2 (strOutput, IDS_NO_VALID_STRUCTUR, strTableName, str); ((CGakApp *) AfxGetApp ()) -> OutputMessage (strOutput); } return FALSE; }