Re: How to retrieve blob data size?
Posted by: Michal Kozusznik
Date: March 10, 2007 10:45AM

OK. Reading doc for IDataRecord.GetBytes method I've found the solution.
We can retrieve blob data size directly from datareader passing null instead of buffer object.

long file_size;
file_size = dr.GetBytes(dr.GetOrdinal("file_content"), 0, null, 0, 0); // here we are retrieving size
byte[] buffer = new Byte[file_size]; // allocating buffer

if (File.Exists(path)) File.Delete(path); // remove old file if exists
out_file = File.OpenWrite(path);           // open new stream for write
file_size = dr.GetBytes(dr.GetOrdinal("file_content"), 0, buffer, 0, (int)file_size); // get whole blob into buffer
out_file.Write(buffer, 0, (int)file_size); // write buffer into file

please note, that GetBytes returns long but size of grabbed data is given by int. So, notation in my code is correct only for blobs up to 2GB. For larger blobs you have to do loop and dump data partialy.

best regards



Edited 1 time(s). Last edit at 03/10/2007 11:10AM by Michal Kozusznik.

Options: ReplyQuote


Subject
Written By
Posted
Re: How to retrieve blob data size?
March 10, 2007 10:45AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.