Up Prev Next
From: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Re: help with inserting text
Date: Feb 18 1998 9:48PM
> 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 Peppler -||- Data Migrations Inc.
email@example.com -||- http://www.mbay.net/~mpeppler