Reading Oracle BLOB columns using OLE-DB

18 09 2007

Reading BLOB columns from a Database using OLE-DB is pretty simple, there’s an MSDN sample which shows you how to do it.

However, for Oracle BLOB columns, the Oracle OLE-DB provider doesn’t bind the length part of the output column binding in the same way that the SQL-Server OLE-DB provider does.

Oracle sets the length part to 4 bytes, indicating the length of the bind value itself, which is an ISequentialStream* pointer, rather than the size of the BLOB column contents itself.

The SQL-Server OLE-DB provider, instead, sets the length part to the size of the Image column contents. Which is convenient in this case as you can make a single call to the ISequentialStream::Read() method using the length part as the 2nd parameter.

To read the Oracle BLOB column contents, you have to make repeated calls to the ISequentialStream::Read() method using some arbitrary value as the 2nd parameter until the stream is completely read, which invariably involves multiple memory reallocations, as shown below:

  ISequentialStream* spStreamToCopyTo = reinterpret_cast<ISequentialStream*>(spSource);
  HRESULT hr = S_OK;

  ULONG ulBytesRead = 0;
  int cbBuf = 0×400000;
  BYTE* pBuf = new BYTE[cbBuf];
  do
  {
    if(SUCCEEDED(hr = spStreamToCopy->Read(pBuf, cbBuf, &ulBytesRead)))
       hr = spStreamToCopyTo->Write(pBuf, ulBytesRead, NULL);
  }
  while((cbBuf == ulBytesRead) && SUCCEEDED(hr));
  delete[] pBuf;





Mobile Phone Resilience

17 09 2007

I dropped my Sony Ericsson P990i into the cats water bowl last week, which is almost exactly how I broke my last SE P900i. Except in that case the water bowl was my cup of tea.

Hats off to SE engineers though, this time after I dried it out, it worked just fine





Marketing

13 09 2007





Dentists

11 09 2007

Visited the dentists yesterday, just for a checkup, no actual work to be done……

£85

The outcome……a course of treatment costing £560