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; }
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; }