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: Peter Sinnott <psinnottie at aol dot com>
Subject: Re: DBD::Sybase - Inserting null character
Date: Jul 7 2004 3:12PM

On Wed, Jul 07, 2004 at 03:51:56PM +0200, Michael Peppler wrote:
> On Wed, 2004-07-07 at 15:40, Peter Sinnott wrote:
> > Hi all,
> >      is it possible to quote null characters in order to allow them to be
> >      inserted via a stored procedure(the field is varchar)?
> Do you mean include NULL bytes in a varchar() column?

That is indeed what I mean. I'm not sure what else to call them but it
does cause some confusion and makes searching for answers difficult.
> I'm not sure (haven't tried it) but I suspect that there are various
> problems with this.
> Could you post a minimal example of what you are trying to achieve?

I have a table that I need to update some rows in. The update procedure
available requires that I pass all the fields of the row into it. Some
of the existing rows have null characters. I'd like to preserve 
null characters in the columns I'm not changing.

use DBI;

my $username = "username1\0na\0me";

my $dbh = DBI->connect( "dbi:Sybase:server=black" , "username" ,
"password" );

unless( $dbh )
    print "Connection to server failed : $DBI::err\n";

my $sth = $dbh->prepare( "exec int_null \@names=" .
			  $dbh->quote($username) . ",\@values=" . $dbh->quote( "kentest2" ) );
unless( $sth )
        print "SQL prepare failed : $DBI::err\n";

unless( $sth->execute( ) )
        print "SQL execute failed : $DBI::err\n";

Results in : 

DBD::Sybase::st execute failed: Server message number=105 severity=15
state=1 line=1 server=blackhat text=Unclosed quote before the character
string 'username1'.
Server message number=102 severity=15 state=1 line=1 server=blackhat
text=Incorrect syntax near 'username1'.
SQL execute failed : 102


Our mission is to continually promote ethical meta-services in order that 
we may enthusiastically maintain scalable data in order to solve business