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: philip mikal <philipm at nafohq dot hp dot com>
Subject: Re: help with inserting text
Date: Feb 19 1998 12:47AM

Hello again!

FYI, after much frustration and lots of help from this list, the final solution
for my problem is listed below.  I would have been lost without everyone's 
help - especially Michael, for recommending the qq() method, which was the 
final element to functionality.


Philip Mikal

sub loadindexdata {

open (LINKS, "") || &CgiDie ("I am sorry, but I was
	not able to open the link database.   The value I have is Would you please check the path and the permission.");

while ()
	$_ = $dbh->dbsafestr($_);
	($link_title, $id, $unique_id, $link_url, $link_description, $author_email, $author_name) = split (/\|/, $_);
	$select = qq(insert into link_table values ("$link_title", $id, $unique_id, "$link_url", "$link_description"));
	$select = qq(insert into link_owners_table values ($unique_id, "$author_name", "$author_email"));
close (LINKS);


> wrote:
> > 
> > It looks like Philip forgot to surround the character strings with quotes.
> > I believe single quotes will work without confusing Perl.
> > 
> > My example:
> > 
> > $select = "insert into link_table values ('$link_title', '$id',
> > '$unique_id', '$link_url', '$link_description')"
> > 
> > Quoting isn't necessary for numeric datatypes like int, float, decimal, and
> > so on. So, in this example, if the column for $id is an int, it doesn't
> > need quotes.
> Note that T-SQL becomes confused if the strings being inserted
> (say $link_title) itself contains the ' or " character.
> To minimize this problem I usually use the qq() quoting operator
> to quote the entire string, and then use " to quote strings in the
> insert statement. Any string that is to be inserted that
> contains the " character needs to be checked, and the " duplicated, eg
> 	$link_title =~ s/"/""/g;
> Michael
> -- 
> Michael Peppler       -||-  Data Migrations Inc.
>  -||-