Thanks. The insert is now working with a memo field but I came across something
else that leaves me puzzled.
After the insert, a select pulls the data out just to confirm the data was
inserted correctly. Problem is that when using SQL_LONGVARBINARY and a jpeg
file, what is returned is exactly half of what went in. Switching to
SQL_LONGVARCHAR and a simple text file, the ouput matched the input exactly.
-Jim
use DBI qw(:sql_types);
my $imagedata;
my $title = "Test run 1"; # change this to make sure both insert and fetch
use same record
undef $/;
open(FILE,'C:\temp\test.jpg'); # switch here for different file type
binmode FILE;
$imagedata = <FILE>;
close(FILE);
print "Insert Length: " . length ($imagedata) . "\n";
$dbh = DBI->connect("dbi:ODBC:mydatabase", "user", "password") or die "Database
connection not made: $DBI::errstr";
$dbh->{LongReadLen} = 64000;
#$dbh->{LongReadTruncOK} = 0;
$sth = $dbh->prepare( "INSERT INTO images (Product_ID, ImageMemo, Title)
VALUES (101, ?, '$title')" );
$sth->bind_param( 1, $imagedata, SQL_LONGVARBINARY );
$sth->execute();
#print $imagedata if defined $imagedata;
# Fetches data from DB. Should be same length as what was just inserted
undef $imagedata;
$sth = $dbh->prepare( "Select ImageMemo From images Where Title = '$title'" );
$sth->execute();
$sth->bind_col( 1, \$imagedata, { type => SQL_LONGVARBINARY } );
$sth->fetch;
print "Fetch Length: " . length ($imagedata) . "\n";
#print $imagedata if defined $imagedata;
$sth->finish;
$dbh->disconnect;
---------------
D:\Webroot\cgi-bin>perl saveimage.cgi
Insert Length: 62082
Fetch Length: 31041