I need to run a select across two different databases so I've created two zsql methods, one for each database. The problem is that if I use statements to call the zsql methods, I get duplicate results due to dtml-in iterating.
<dtml-in blog_author_select>
<dtml-in "intranet_user_select(intranet_username)">
<option value="&dtml-id;">&dtml-fullname;</option>
</dtml-in>
</dtml-in>
That code is what I initially tried but of course due to dtml-in iterating over results, it's looping through over and over and creating a ton of duplicate data.
To resolve this, I am wanting to use a python script to call the first zsql method and then use the results of that against the second zsql method. Then I can use dtml-in to call the python script and populate my select list with the correct data.
While I can get a python script to run the zsql method and return the results, I cannot seem to figure out how to pass those results to the second zsql method in the same python script and return the correct data set.
Here's what I have thus far (and yes, I am aware it's wrong).
recordset = context.blog_author_select().dictionaries()
rownum = 1
for record in recordset:
rownum = rownum + 1
username = [record["intranet_username"] for record in recordset]
mainselect = context.intranet_user_select(intranet_username=username).dictionaries()
print mainselect
return printed
There are two things happening here that aren't working (and possibly more):
-
The results being returned are not correct. The intranet_user_select zsql method says (select * from table where !=username and yet those results are not being filtered out.
-
As part of #1 the reason for this, at least I believe, is that the results are in a list and therefore not being interpreted correctly.
I think what needs to happen is that the first query (blog_author_select) is run, and those results are held row by row instead of a list. Then, a loop needs to be run on the second query, and run however many times as there are results from the first query (i.e. if there are 5 results from the first query, the loop would run 5 times on the second query).
My plan, once the correct data is returned, is to call this script via and use the variables (column names) just as I do with any other zsql method.
I hope that explained everything in detail, and I am appreciative of anyone who can help me solve this.