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: Michael Peppler <mpeppler at peppler dot org>
Subject: RE: using sybperl, how to insert data that contains a quote with in it
Date: Jan 5 2001 5:10PM

Kiriakos Georgiou writes:
 > DBI/DBD-Sybase has the very cool quote function so you can do things
 > like:
 > $dbh->do(sprintf "INSERT INTO table (a, b) values(%s, %s)",
 > $dbh->quote($a), $dbh->quote($b));
 > 
 > If sybperl lacks this function (I don't use sybperl) you probably want
 > to define your own and call it like above.

In case anyone wonders, quote() goes like so (done from memory):

sub quote {
    my $dbh = shift;    # not really needed - but here because called
			# as a method
    my $string = shift;

    return "NULL" unless defined($string);
    $string =~ s/"/""/g;

    "$string";
}

So that if the $string is undefined you get NULL (without the quotes)
and if it is defined you get "$string" (with the surrounding quotes).

Michael
-- 
Michael Peppler - Data Migrations Inc. - mpeppler@peppler.org
http://www.mbay.net/~mpeppler - mpeppler@mbay.net
International Sybase User Group - http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com