Can I read BLOB as stream by DBI 
Author Message
 Can I read BLOB as stream by DBI

I can have a blob value saved in a file like this

     while(($a=$Data->fetchrow_array)){
        open A,">a.gif";
        binmode(A);
        print A $a;
        close A;
     }
but I'm afraid that the data is too large to be stored in a variable.
Is there any method that I can manipulate the data as stream like

     $handle=$Data->fetchrow??
     while(<$handle>){
         #save data to file
     }

BTW,I still can't understand how to use {LongTruncOk} .Is it used for judging
if my data is stored in the variable succesfully?But if it fails,it will break
the while loop,why do I need it ?Thanks.

Derek



Sat, 10 Apr 2004 10:48:37 GMT  
 Can I read BLOB as stream by DBI

Quote:
>I can have a blob value saved in a file like this
>but I'm afraid that the data is too large to be stored in a variable.
>Is there any method that I can manipulate the data as stream like

Depending on the database/DBD combination, you may be able to use the
undocumented $sth->blob_read($id,$offset,$len) method, or use the database
servers own support for putting blobs into files.

Quote:
>BTW,I still can't understand how to use {LongTruncOk} .Is it used for judging
>if my data is stored in the variable succesfully?But if it fails,it will break
>the while loop,why do I need it ?Thanks.

LongTruncOk is used together with LongReadLen, if you set LongReadLen to some
value, such as 1024, and LongTruncOk is true, then you will only get the
first 1024 bytes of that field, even though it may have been much longer.

--
Jason S Kohles



Sat, 10 Apr 2004 16:16:11 GMT  
 Can I read BLOB as stream by DBI

<snip>

Quote:
> LongTruncOk is used together with LongReadLen, if you set LongReadLen to some
> value, such as 1024, and LongTruncOk is true, then you will only get the
> first 1024 bytes of that field, even though it may have been much longer.

> --
> Jason S Kohles


On a side note, you probably don't want to use a power of 2 (i.e. 1024 as
mentioned above) as the LongReadLen value.  To quote the footnote from Tim Bunce's
"Using the Perl DBI", p.142 (O'Reilly & Associates):

"Using a value which is a power of two, such as 64 KB, 512 KB, 8MB, etc., can
actually cause twice that amount to be taken on systems that have poor memory
allocators.  That's because a few extra bytes are needed for housekeeping
information and, because the dumb allocator only works with powers of two, it has
to double the allocation to make room for it."

Regards,

Mr. Sunblade

--
"Evil will always triumph because Good is *dumb*."
-- Dark Helmet, 'Spaceballs: The Movie'



Sat, 10 Apr 2004 18:16:30 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. DBI - Writing blobs - blob types

2. DBI:mysql blob/text access

3. get blob to web with dbi

4. Perl DBI::DB2 inserting blob data

5. How to access BLOB field from DBI

6. Bad free() with perl, DBI, Informix and blobs

7. How can I insert blob data using DBI?

8. DBI/DBD::Informix and retrieving BLOB data

9. To Blob or not To Blob

10. inserting a binary scalar into a DBI blob

11. Retrieving BLOBs from Oracle using DBI

12. Select BLOB In Oracle with DBI

 

 
Powered by phpBB® Forum Software