BOOL CADORecordset::GetFieldInfo(FieldPtr pField, CADOFieldInfo* fldInfo) { memset(fldInfo, 0, sizeof(CADOFieldInfo)); strcpy(fldInfo->m_strName, (LPCTSTR)pField->GetName()); fldInfo->m_lDefinedSize = pField->GetDefinedSize(); fldInfo->m_nType = pField->GetType(); fldInfo->m_lAttributes = pField->GetAttributes(); if(!IsEof()) fldInfo->m_lSize = pField->GetActualSize(); return TRUE; }
BOOL CFoxBase::CopyData(_RecordsetPtr &IRecordS, _RecordsetPtr &IRecordD) { _variant_t TempValue; short Item; FieldsPtr IFields; FieldPtr IField; if(IRecordS==NULL || IRecordD==NULL) { ExceptionInfo(_T("Source Recordset or destination Recordset cann't be empty")); return FALSE; } if(IRecordS->adoEOF && IRecordS->BOF) { return TRUE; } if(!IRecordD->adoEOF || !IRecordD->BOF) { try { IRecordD->MoveLast(); } catch(_com_error &e) { ExceptionInfo(e); return FALSE; } } try { IRecordS->MoveFirst(); } catch(_com_error &e) { ExceptionInfo(e); return FALSE; } try { while(!IRecordS->adoEOF) { IRecordS->get_Fields(&IFields); IRecordD->AddNew(); for(Item=0;Item<IFields->GetCount();Item++) { IFields->get_Item(_variant_t(Item),&IField); TempValue=IRecordS->GetCollect(_variant_t(IField->GetName())); IRecordD->PutCollect(_variant_t(IField->GetName()),TempValue); IField.Release(); } IRecordD->Update(); IFields.Release(); IRecordS->MoveNext(); } } catch(_com_error &e) { ExceptionInfo(e); return FALSE; } return TRUE; }
CString CFoxBase::CreateTableSQL(_RecordsetPtr &IRecord,LPCTSTR pTableName) { short Item; CString CreateSQL; CString DefList; FieldsPtr IFields; FieldPtr IField; CreateSQL=_T(""); if(IRecord==NULL) { ExceptionInfo(_T("Recordset interface cann't be NULL")); return CreateSQL; } if(pTableName==NULL) { ExceptionInfo(_T("Table name cann't be NULL")); return CreateSQL; } IRecord->get_Fields(&IFields); DefList=_T(""); for(Item=0;Item<IFields->GetCount();Item++) { IFields->get_Item(_variant_t(Item),&IField); DefList+=IField->GetName(); DefList+=_T(" "); switch(IField->GetType()) { case adVarWChar: { CString Temp; Temp.Format(_T("varchar(%d)"),IField->GetDefinedSize()); DefList+=Temp; break; } case adLongVarWChar: DefList+=_T("text"); break; case adVarBinary: { CString Temp; Temp.Format(_T("varbinary(%d)"),IField->GetDefinedSize()); DefList+=Temp; break; } // case adNumeric: // case adGUID: // case adLongVarBinary: // { // ExceptionInfo(_T("不支持LongVarBinary")); // return CreateSQL; // } // break; case adInteger: DefList+=_T("int"); break; case adUnsignedTinyInt: case adSmallInt: DefList+=_T("smallint"); break; case adSingle: case adDouble: DefList+=_T("float"); break; case adDBTimeStamp: case adDate: DefList+=_T("date"); break; // case adBoolean: // break; default: { ExceptionInfo(_T("不支持此类型")); return CreateSQL; } } if(Item < IFields->GetCount()-1) { DefList+=_T(","); } IField.Release(); } CreateSQL.Format(_T("CREATE TABLE %s(%s)"),pTableName,DefList); return CreateSQL; }