Search the web
Sign In
New User? Sign Up
oo4ole · Oracle Objects for OLE (OO4O) Users List
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
Re: How to use oo4o to save BLob ?[Scanned]   Message List  
Reply | Forward Message #1608 of 1863 |
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;
 }
#endif
 
 ODynaset 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;
  }
#endif
 
  OBlob 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;
  }
#endif
 
  unsigned 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 buffer
 
   oblob.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 all
used oo4ole with Visual C++ ,
How to save image (stored in BLOB data type ) Using OO4O ;
 
thanks
 
alaa

__________________________________________________
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
===================================================================





Tue Jun 22, 2004 2:18 pm

a.capp@...
Send Email Send Email

Forward
Message #1608 of 1863 |
Expand Messages Author Sort by Date

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...
Adrian Capp
a.capp@...
Send Email
Jun 22, 2004
2:18 pm

Adrian : Thank you for your replay and now , I try your code and get the error on fstream sf ; 'fstream' : undeclared identifier thank alaa Adrian Capp...
Alaa Mostafa
alaa210
Offline Send Email
Jun 23, 2004
6:01 am

You need to incluide the fstream library into the code. Try inserting this line in the top of your code:- #include "fstream.h" Adrian _____ From: Alaa Mostafa...
Adrian Capp
a.capp@...
Send Email
Jun 23, 2004
8:50 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help