Add # import "C: Program filescommon filessystemadomsado15.dll" no_namespace Rename ("EOF", "rseof") to stdafx. h ")
Void ctestblobdlg: onbnclickedok ()
{
_ Connectionptr m_pconnection; // assume that you have obtained
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, "prompt message", null );
}
Hresult hR = m_precordset-> open ("select ID, name, word from blob_test", m_pconnection.getinterfaceptr (), adopendynamic, adlockoptimistic, ad1_text );
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: add the control notification handler code here
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, "prompt message", null );
}
Strsql. Format (L "Select name, word from blob_test where id = 4 ");
M_precordset = m_pconnection-> execute (_ bstr_t) strsql, null, ad1_text );
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 ();
}