|
|
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 = ;
close(FILE);
# Assumes image_table(id identity, name varchar, data image)
$dbh->dbcmd("insert image_table(name, data) ('$file', NULL)");
$dbh->dbsqlexec;
$dbh->dbresults;
$dbh->dbcmd("select data from image_table where id = \@\@identity");
$dbh->dbsqlexec;
$dbh->dbresults;
$dbh->dbnextrow;
$dbh->dbwritetext("image_table.data", $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
page.
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
--
Michael Peppler -||- Data Migrations Inc.
mpeppler@peppler.org -||- http://www.mbay.net/~mpeppler
Int. Sybase User Group -||- http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com
|