From: Alaa Mostafa [mailto:alaa210@...]
Sent: 23 June 2004 07:01
To: oo4ole@yahoogroups.com
Subject: RE: [oo4ole] How to use oo4o to save BLob ?[Scanned]
Adrian Capp <a.capp@...> wrote:
This is code that we used. It is quite old as we no longer use oo4o and prefer to use OCI directly.The method is taken from a class that encapsulated this kind of functionallity. m_pDatabase is a member pointer to an ODatabase object.BOOL CBlobHander::CreateFileFromBlob(LPCSTR pszTableName, LPCTSTR pszBlobField, LPCTSTR pszWhereClause, LPCTSTR pszFilename)
{
#ifdef _DEBUG
if (m_pDatabase && !m_pDatabase->m_Database.IsOpen())
{
MessageBox(NULL, "Can not Create File - Database Not Connected", "Error", MB_ICONINFORMATION | MB_OK);
return FALSE;
}
#endifODynaset dyn;
CString strSQL;strSQL.Format("SELECT %s FROM %s WHERE %s", pszBlobField, pszTableName, pszWhereClause);
if (_BOOL(dyn.Open(m_pDatabase->m_Database, strSQL)))
{#ifdef _DEBUG
if (dyn.GetRecordCount() == 0)
{
MessageBox(NULL, "Can not find Object Record.", "Error", MB_ICONINFORMATION | MB_OK);
return FALSE;
}
else if (dyn.GetRecordCount() > 1)
{
MessageBox(NULL, "Query returned more than one record. Can not update.", "Error", MB_ICONINFORMATION | MB_OK);
return FALSE;
}
#endifOBlob oblob;
dyn.GetFieldValue(0, &oblob);#ifdef _DEBUG
if (oblob.IsNull() || (oblob.GetSize() == 0))
{
MessageBox(NULL, "Can not Create File - Blob is Empty.", "Error", MB_ICONINFORMATION | MB_OK);
return FALSE;
}
#endifunsigned char *buffer = 0;try
{
fstream fs;fs.open(pszFilename, ios::out);
fs.setmode(filebuf::binary);unsigned long size = oblob.GetSize();// calculate an optimum buffersize of approximately 32k bytes
unsigned long optchunk = oblob.GetOptimumChunkSize();
unsigned int bufsize = ((int)(32768/optchunk)) *optchunk;
if (bufsize > size)
bufsize = size;buffer = (unsigned char *)malloc(bufsize);//By taking advantage of streaming we get the best performance
//and do not need to allocate a large bufferoblob.EnableStreaming(size);short status= OLOB_NEED_DATA;
unsigned long amtread=0;while(status == OLOB_NEED_DATA)
{
amtread = oblob.Read(&status, buffer, bufsize);
//if (status != OLOB_NODATA)
if (amtread == 0)
fs.write(buffer, bufsize);
else
fs.write(buffer, amtread);
}oblob.DisableStreaming();fs.close();
}
catch(OException E)
{
CString strMsg;
strMsg.Format("%s Error: %s", E.GetFailedMethodName(), E.GetErrorText());
MessageBox(NULL, strMsg, "Error", MB_ICONINFORMATION | MB_OK);
}if (buffer)
free(buffer);
return TRUE;
}
else
{
int n = dyn.ErrorNumber();
MessageBox(NULL, dyn.GetErrorText(), "Failed To Open Object Record", MB_ICONINFORMATION | MB_OK);return FALSE;
}
}
From: Alaa Mostafa [mailto:alaa210@...]
Sent: 22 June 2004 06:04
To: oo4ole@yahoogroups.com
Subject: [oo4ole] How to use oo4o to save BLob ?[Scanned]Hi allused oo4ole with Visual C++ ,How to save image (stored in BLOB data type ) Using OO4O ;thanksalaa__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
===================================================================
To post a message, send email to: oo4ole@yahoogroups.com
To subscribe, send an email to: oo4ole-subscribe@yahoogroups.com
To unsubscribe, send an email to: oo4ole-unsubscribe@yahoogroups.com
To contact the list owner, send an email to: oo4ole-owner@yahoogroups.com
To view Yahoo! Groups info about this newsgroup: http://groups.yahoo.com/group/oo4ole
===================================================================
===================================================================
To post a message, send email to: oo4ole@yahoogroups.com
To subscribe, send an email to: oo4ole-subscribe@yahoogroups.com
To unsubscribe, send an email to: oo4ole-unsubscribe@yahoogroups.com
To contact the list owner, send an email to: oo4ole-owner@yahoogroups.com
To view Yahoo! Groups info about this newsgroup: http://groups.yahoo.com/group/oo4ole
===================================================================
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
===================================================================
To post a message, send email to: oo4ole@yahoogroups.com
To subscribe, send an email to: oo4ole-subscribe@yahoogroups.com
To unsubscribe, send an email to: oo4ole-unsubscribe@yahoogroups.com
To contact the list owner, send an email to: oo4ole-owner@yahoogroups.com
To view Yahoo! Groups info about this newsgroup: http://groups.yahoo.com/group/oo4ole
===================================================================