[Zope-DB] Cleaning apostrophes

Lalo Castro laloc at ucsc.edu
Wed Sep 15 18:26:32 EDT 2004


	I apologize if this is a simple enough question.  I am something of a 
newbie...
	We are using Zope 2.6.0, python 2.1.3, and pSQl 7.3.4 on a freebsd4 
machine.
	There is a webform we have that has to be able to accept apostrophes. 
PostgreSQL sees the apostrophes as the end of string and errors out at 
the next character.  We've been trying to build a python script to 
escape the apostrophes before they get sent off to the database, but the 
writing has become problematic.  Here's the script:

import string
unapostrophated = string.replace(apostrophated, "'", "\'")
return (unapostrophated)

	This doesn't work, as python sees the escape character as escaping the 
apostrophe and replaces, say, "here's" with "here's" (as opposed to 
"here\'s", which is what we want.
	We've also tried escaping the escape character ("\\'" which makes 
"here\\'s"), and raw text (r"\'" which makes "here\\'s"), to no 
solution.  PostgreSQL sees the double backslash and errors out.  Other 
attempts were ASCII text ("\034'") and the html code ("?034:'") and 
unicode for apostrophes ("\\a").  None of which worked.
	Is there a way to do this within the python script?  If I am missing a 
solution using another method other than the python script, please let 
me know.
		Thanks in advance for any help.
			Lalo


More information about the Zope-DB mailing list