Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Michael Peppler <mpeppler at peppler dot org>
Subject: Re: How to read binary image files and store image in Sybase?
Date: Jan 17 2000 3:54PM

Robert Banniza writes:
 > Guys,
 > 	Quick question. I'm trying to read binary image files in sybperl and want
 > to store the image in a Sybase field (image type). Does anyone have a little
 > sample program that does this that they would be willing to share? I think I
 > need the binmode function in Perl and I think I need the routine in sybperl
 > that handles text/image processing but I'm having a hard time putting it all
 > together. I'm using Sybperl 2.11 and ASE 11.9.2 for Linux. Thanks for any
 > help...

The follwing should work:

open(FILE, $filename) || die "Can't open $file: $!";
$/ = undef;
my $data = ;

# Assumes image_table(id identity, name varchar, data image)
$dbh->dbcmd("insert image_table(name, data) ('$file', NULL)");
$dbh->dbcmd("select data from image_table where id = \@\@identity");
$dbh->dbwritetext("", $dbh, 3, $data, TRUE);

And that's it.

If you want to use Sybase::CTlib then there is a similar method using
ct_send_data() that I think is relatively well explained in the man

You only need the binmode() function if you do this on a Win32
platform (where the physical line endings are converted from \r\n to
\n on input)

Michael Peppler         -||-  Data Migrations Inc.    -||-
Int. Sybase User Group  -||-
Sybase on Linux mailing list: