[Zope] dynamically generating sql queries?

Paul Winkler pw_lists at slinkp.com
Wed Mar 28 11:42:04 EDT 2007


On Wed, Mar 28, 2007 at 02:52:26PM +0000, siva k wrote:
> Hi,
> I have five fields in the database author1,author2..author5.
> Trying to generate a parameter for the select_sql method called result,
> I run into an error -cannot add type "int" to string. Could you please
> say how to concatenate a string and a number?

this is a simple python mistake, nothing to do with zope really...
in your example:
	result="'%s%d' % (field, index)"

> 	result="field+index">

... the stuff in quotes is a python expression, so the normal python
rules apply. One solution:

	result="'%s%d' % (field, index)"

> or is there a better way to generate 5 different sql quesries and display 
> the result?

I guess that select_sql is a separate zsql method that is called by
this one?

One option would be to replace the dtml you showed us with a Script
(Python) which calls select_sql and passes it appropriate parameters.

Something like this (may need adjustment, I'm not sure I understand
your example code):

for i in range(1, 6):
     print context.select_sql(field=result, language=language)
return printed

-- 

Paul Winkler
http://www.slinkp.com


More information about the Zope mailing list