[Zope-DB] sqlvar tag for text

Charlie Clark charlie@begeistert.org
Mon, 24 Feb 2003 22:12:18 +0100

On 2003-02-24 at 21:48:10 [+0100], Alex Cowan wrote:
> Ah alright, I'll explain a little ;)
> Its for when you want to enter text into a database but not as a string. 
> Normally you'd have a problem if there are any ' or ", so you need to 
> either have a small python script to parse the text before you put it 
> into the db or something else to do it.

no problem with either """ this is "text" """ or """ this is 'text' """

The ZopeDA does the quoting for you. This is apparently no so nice to 
implement and another reason for a general overhaul of the ZopeDAs but it 
works in userland.

> PHP has addslashes, python doesn't seem to have anything (that I can 
> find) except using string.replace to do it, but its far easier to have a 
> dtml-tag to do it.

Python doesn't have this because it doesn't need it! You can have raw 
strings if you want (quite nice for regular expressions). 
eat_this = r"\"
print eat_this

Anybody got a link to the wonderful Dilbert comic about Python?

php is evil, very bad, nearly perl

and DTML should be getting less tags instead of more!!! Go ZPT, 
PythonScripts + ExternalMethods!!!

> sqlvar only has string or int (basically), which is great for strings but 
> converting the text to a string isn't always the best thing (since it 
> loses any formatting). So the tag does it without making it a string.

It's gonna be a string in the database. It just needs quoting properly and 
then you don't have to worry.