[Zope] DTML sql construction and IN keyword

Shane Landrum srl@mail.boston.com
Fri, 12 Jul 2002 16:37:32 -0400


I'm writing some DTML to create a SQL query which uses the IN
keyword. I need to select a set of records with a particular
set of record IDs, like so:

SELECT * FROM tablename WHERE id IN (42,27,83);

I'm constructing the list of ids externally, so that I pass in
an idlist as a string: '42,27,83'.  My DTML looks something like this:

'select * from tablename where id in \
(<dtml-sqlvar idlist type="string">)'

Now, clearly this isn't working because it's generating SQL with
quotes in wrong places, like:

SELECT * FROM tablename WHERE id IN ('42,27,83')

I'm assuming that I can't simply pass in a list of integers
to my SQL method; what's the right way to do this?

srl
-- 
Shane Landrum  (srl AT boston DOT com)  Software Engineer, boston.com