// Способ 1
Получить:
TBlobField* bf = dynamic_cast<TBlobField*>(AdoQuery->FieldByName("My_BlobField"));
TADOBlobStream* bl = new TADOBlobStream(bf, bmRead);
try {
bl->SaveToFile("bitmap.bmp");
}
__finally {
delete bl;
}
Положить:
AdoQuery->Edit();
TBlobField* bf = dynamic_cast<TBlobField*>(AdoQuery->FieldByName("BLOBFIELD"));
TADOBlobStream* bl = new TADOBlobStream(bf, bmWrite);
try {
bl->LoadFromFile("bitmap.bmp");
}
__finally {
delete bl;
AdoQuery->Post();
}
-------------------
// Способ 2
Получить:
AdoQuery->SQL->Add( "INSERT INTO MyTable (MyBlob) VALUES (:blob)" );
TMemoryStream *MS = new TMemoryStream;
MS->Write( MyBlobBuffer, sizeof( MyBlobBuffer ) );
MS->Seek( 0, soFromBeginning );
AdoQuery->Parameters->Items[0]->LoadFromStream( MS, ftBlob );
delete MS;
AdoQuery->ExecSQL();
Положить:
AdoQuery->SQL->Add( "SELECT MyBlob FROM MyTable WHERE ..." );
AdoQuery->Open();
TBlobStream *pBlob = (TBlobStream *)AdoQuery->CreateBlobStream(AdoQuery->FieldByName("MyBlob"), Db::bmRead );
pBlob->Position = 0;
pBlob->Read( (void *) MyBlobBuffer, sizeof( MyBlobBuffer ) );
delete pBlob;
MSVC && ADO
))
bool CHBux::ImField2File(FieldPtr &fld, _bstr_t ofile)
{
_variant_t varBLOB;
long lDataLength = 0;
char *pBuf = NULL;
int nDataLenRetrieved = 0;
try {
lDataLength = fld->ActualSize;
if(lDataLength > 0) {
VariantInit(&varBLOB);
varBLOB = fld->GetChunk(lDataLength);
if(varBLOB.vt == (VT_ARRAY | VT_UI1)) {
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
ofstream fo(ofile, ios::out | ios::binary);
fo.write(pBuf,lDataLength);
fo.close();
SafeArrayUnaccessData(varBLOB.parray);
}
}
}
catch(_com_error &e) {
ErrorMessageBox(e.ErrorMessage());
return false;
}
return true;
}