LPM: Many Monkeys: Question about quotes

David Hempy hempy at ket.org
Thu Jan 13 14:29:53 CST 2000

At 03:10 PM 1/13/2000 -0500, you wrote:
>If I have understood the issue correctly, you should be able to use the:
>    $dbh->quote($string)
>to "correctly" backslash the string.  Correctly here is defined as correct
>with respect to your database - different databases need different characters
>protected and this function is supposed to handle that.

If I were using DBI, that is!  ;-)  Early in this project, I switched to
Win32::ODBC as I couldn't get DBD::ODBC to work with my Visual Fox Pro
database.  I hope I don't regret it later on... :-(

Anyway, about 7 seconds after I resolved the headline issue with " , I
ran into the same problem with my html_body field.  Here, I need real
quotes to be real qoutes.  That is, <a href="index.html"> can't become <a

For anyone else who runs into this, here is my solution.  I think it is a
clean one.  Of course, if I were using DBI it would be a non-issue and even
cleaner thanks to the quote function, but that's another story.  (I suppose
I *could* use DBI to build the quoted string before schlepping it over to
Win32:ODBC, but that would be a little kinky)

>From _Microsoft SQL Server Database Developer's Companion_ p. 64,

>Character strings...must be enclosed in single quotation marks (')... 
>Although double quotations marks are allowed, single quotation marks are 
>preferred for compliance with ANSI standards.

Okay... switch to single quotes.  That's half the battle.  Same page continues:

>To specify other single quotation marks (or apostrophes) within a character 
>entity, use two consecutive single quotation marks, as shown:
>	'I don''t understand'

So, my code that was:

	$headline =~ s/\"/&quot;/g; ## Escape quotes within the title.
	$cmd = qq {update release set headline="$headline" where id="$id" };

...has become:

	$headline =~ s/'/''/g;		## Escape quotes within the title.
	$cmd = qq {update release set headline='$headline' where id='$id'};

I suppose I don't need qq{} at this point, but what the heck...can't hurt.
BTW, I had a real hard time finding documentation on qq.  Both the camel
book and Learning Perl do not mention it, and online docs are spartan.  In
fact, I don't even recall what code I swiped originally that used qq...I
sure didn't come up with it!

>PS - Erik Ackerman says Hi!

What is Erik up to?  Ask him to drop me a line, okay?


David Hempy
Internet Database Administrator
Kentucky Educational Television

More information about the Lexington-pm mailing list