PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Steve Sabljak <steve at cpc dot net dot au>
Subject: Re: Insertion of BINARY/VARBINARY values with DBD::Sybase?
Date: Aug 3 2001 3:25PM

> 
> Steve Sabljak writes:
>  > Would anyone be able to an example of inserting binary values
>  > (with embedded nuls) into a Sybase ASE Database (v12) using
>  > DBD::Sybase 0.91? I've tried several different ways and still
>  > can't get it to work without truncating the data at the first
>  > nul byte.
> 
> Have you tried converting the binary data to a hex string?
> 
> Michael
> -- 
> Michael Peppler - Data Migrations Inc. - http://www.mbay.net/~mpeppler
> mpeppler@peppler.org - mpeppler@mbay.net
> International Sybase User Group - http://www.isug.com
> 

Yes, I have, and it does work but only in the case where placeholders
are not used. If I use placeholders and convert the binary data to a hex
string, it's the hex string which is treated as the data itself, which
is not the behaviour I'm seeking.

e.g. say I want to insert the binary value 0x110011 into a varbinary field

     $hexstr = "0x110011";
     $sth = $dbh->prepare("insert into sometable (bin) values (?)");
     $sth->execute($hexstr);

     The value 0x3078313130303131 is inserted when what I want is 0x110011

     $hexstr = "0x110011";
     $sth = $dbh->prepare("insert into sometable (bin) values ($hexstr)");
     $sth->execute();

     This yields the correct results, but is too slow. I need to be able to
     prepare the statement just once and then do a large number of inserts
     quickly.

     $rawstr = pack("H*", "110011");
     $sth = $dbh->prepare("insert into sometable (bin) values (?)");
     $sth->execute($rawstr);

     The value 0x11 is inserted when what I want is 0x110011.
     It's truncated at the first nul byte.

Does the current version of DBD::Sybase support insertion of BINARY/VARBINARY
values using placeholders?

Thanks,
-Steve
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Steve Sabljak
Web Developer
The Cooee Phone Company Pty Ltd