从oracle数据库上传、下载文件

在stdafx.h加入 #import "C:Program FilesCommon FilesSystemadomsado15.dll" no_namespace rename("EOF","rsEOF")
void CtestblobDlg::OnBnClickedOk()
{
_ConnectionPtr  m_pConnection;//假设已得到   
CString filePath;  
filePath="C:/1.dll";
CFile m_file;  
CFileException e;  
_RecordsetPtr  m_pRecordset;  
m_pRecordset.CreateInstance(__uuidof(Recordset));  
m_pConnection.CreateInstance(__uuidof(Connection)); 
try
{
m_pConnection->Open("Provider=OraOLEDB.Oracle;Password=123456;User ID=system;Data Source=orcl;Persist Security Info=True","","",adModeUnknown);
}
catch(_com_error e)
{
CStringA temp;


::MessageBoxA(NULL,temp,"提示信息",NULL);


}
HRESULT hr = m_pRecordset->Open("select id,name,word from blob_test",m_pConnection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);  
if(SUCCEEDED(hr)){  
m_pRecordset->AddNew();  
m_pRecordset->PutCollect("id",_variant_t(5));   
m_pRecordset->PutCollect("name",_variant_t("1.dll"));
        
if(m_file.Open(filePath,CFile::modeRead | CFile::typeBinary,&e)){  
int nsize = m_file.GetLength();  
byte *fileBuffer = new byte[nsize + 1];   
m_file.Read(fileBuffer, nsize);  
//file.Close();
char *m_pbuff = NULL;  
SAFEARRAYBOUND rgs[1];  
rgs[0].lLbound = 0;  
rgs[0].cElements = nsize;  
SAFEARRAY *pas;  
pas = SafeArrayCreate(VT_UI1,1,rgs);  
//SafeArrayAccessData(pas,(void **)&m_pbuff);  
for (long i = 0; i <nsize; i++)  
{  
SafeArrayPutElement (pas, &i, fileBuffer++);   
}  
//m_file.ReadHuge(m_pbuff,nsize);  
m_file.Close();  
variant_t varBLOB;  
varBLOB.vt = VT_ARRAY | VT_UI1;  
varBLOB.parray = pas;  
m_pRecordset->GetFields()->GetItem("word")->AppendChunk(varBLOB);  
}  
m_pRecordset->Update();  
//SafeArrayUnaccessData(pas);  
}  
m_pRecordset->Close();  
m_pRecordset.Release(); 


CDialogEx::OnOK();




}


void CtestblobDlg::OnBnClickedCancel()
{
// TODO: 在此添加控件通知处理程序代码
CString strSql;   
variant_t var;   
CString filename; 
CString filePath;  
filePath="C:/";
_ConnectionPtr  m_pConnection;
_RecordsetPtr  m_pRecordset; 
m_pRecordset.CreateInstance(__uuidof(Recordset));  
m_pConnection.CreateInstance(__uuidof(Connection));
try
{
m_pConnection->Open("Provider=OraOLEDB.Oracle;Password=123456;User ID=system;Data Source=orcl;Persist Security Info=True","","",adModeUnknown);
}
catch(_com_error e)
{
CStringA temp;


::MessageBoxA(NULL,temp,"提示信息",NULL);


}
strSql.Format(L"select name,word from blob_test where id=4");  
m_pRecordset = m_pConnection->Execute((_bstr_t)strSql,NULL,adCmdText);   
if(!m_pRecordset->BOF)  
{   
m_pRecordset->MoveFirst();  
}   
while(!m_pRecordset->rsEOF)   
{   
var = m_pRecordset->GetCollect("name");  
if(var.vt != NULL)   
{  
filename = (LPCTSTR)(_bstr_t)var;  
}   
long lDataSize = m_pRecordset->GetFields()->GetItem("word")->ActualSize;  
_variant_t varBLOB = m_pRecordset->GetFields()->GetItem("word")->GetChunk(lDataSize);  
filePath+=(CString)var;
CFile outFile( filePath,CFile::modeWrite | CFile::modeCreate);//XXX+"//"+fileName 文件据对路径   
   
if(varBLOB.vt == (VT_ARRAY | VT_UI1))  
{  
char * pbuf = NULL;  
SafeArrayAccessData(varBLOB.parray,(void **)&pbuf);  
outFile.Write(pbuf,lDataSize);
//outFile.WriteHuge(pbuf,lDataSize);  
SafeArrayUnaccessData(varBLOB.parray);  
}  
m_pRecordset->MoveNext();  
}  
m_pRecordset->Close();   
m_pRecordset.Release();  




CDialogEx::OnCancel();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值