in reply to Extracting long raw data from Oracle

As far as SQL goes, as long as the data you provide to the INSERT call fits in the target columns, it will go in the table as planned. "Raw" fields, or BINARY, or BLOB or whatever you happen to call them, are just the same as your regular run-of-the-mill strings -- You still have to "escape" the content.
# $blob_a_data is a GIF, or other binary data $db->do("INSERT INTO blob_table (blob_a) VALUES (?)", {}, $blob_a_data); # Later on... my ($blob_a_fromdb) = $db->selectrow_array("SELECT blob_a FROM blob_table"); # $blob_a_fromdb and $blob_a_data should be the same.
Or you can use $db->quote($blob_a_value) to force the proper conversion. DBI should "decode" any of the inserted data back into its original format for you when you use any of the fetch() or select()-type functions. Calls such as the $db->do() above do automatic quotation of your data for '?' identified parameters. Experiment with $db->quote() to see how it behaves, as it escapes any potentially dangerous characters such as '\n', or " ' ".

It sounds too good to be true, but it isn't.

Replies are listed 'Best First'.
Re: Re: Extracting long raw data from Oracle
by rrwo (Friar) on Feb 13, 2001 at 06:52 UTC

    Careful. When you do an insert for LONG datatypes, you may need to use bind_param. Otherwise data over 255 or so bytes gets cut off when inserted.

    UPDATE: Some example code is below:

      my $sql = qq{ INSERT INTO Object (Key, LongData) VALUES (?, ?) };
      my $sth = $dbh->prepare( $sql ) or croak $DBI::errstr;
    
      $sth->bind_param(1, $key,      { TYPE=>DBI::SQL_INTEGER } );
      $sth->bind_param(2, $longdata, { TYPE=>DBI::SQL_LONGVARCHAR } );
    
      to make this a little shorter you can add
      use DBI qw(:sql_types);
      then instead of { TYPE=>DBI::SQL_INTEGER } you can just type SQL_INTEGER

      --BigJoe

      Learn patience, you must.
      Young PerlMonk, craves Not these things.
      Use the source Luke.