SQL Server requires a doubling of the apostrophes, not a \ escape. So the regexp should be
$Title=~s|'|\'\'|g; > -----Original Message----- > From: Ailes, Kevin [mailto:[EMAIL PROTECTED]] > Sent: Tuesday, June 11, 2002 2:57 PM > To: Perl-win32-admin list ([EMAIL PROTECTED]) > Subject: Apostrophe's > > > I have a bit of code that uses Win32::ODBC to connect to a > Microsoft SQL > database to retrieve some info. It performs the look-up > using data from a > different database that may or may not have special characters in it. > > How do I create the sql statement to prevent any erroneous readings of > special characters? > > Here is an example of what errors in my code. > ********** > if ($db->Sql("select name from computer where description = > \'".$Title."\'")){ > print "SQL failed.\n"; > print "Error: " . $db->Error() . "\n"; > } else { > while($db->FetchRow()){ > undef %Data; > %Data = $db->DataHash(); > ($computer)=$db->Data("name"); > push(@Computers,$computer); > } > ********** > > If a $Title is submitted that contains several apostrophes > there will be a > look-up failure. I have tried inserting > > $Title=~s/'/\\'/g; > > to fix the apostrophes and it did, but the Sql object or the > datasource must > require some other massaging? > > Can anyone help out here? > > Kevin Ailes > Administrator > OTTO Engineering > _______________________________________________ > Perl-Win32-Admin mailing list > [EMAIL PROTECTED] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. _______________________________________________ Perl-Win32-Admin mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs