在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();
}
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();
}