[Zope-dev] SOLVED: Using recursion with a SQL method
Jim Cain
jec@mgmt-inc.com
Tue, 30 Nov 1999 11:43:35 -0500 (EST)
I finally figured this out for myself. Apparently something like:
<dtml-var "some_object(parameter_name=value)">
results in a namespace stack in some_object that has *only*
parameter_name defined, and no other namespaces may be accessed. As a
result, using this for recursion fails.
The solution was to call some_object this way instead:
<dtml-with "_.namespace(parameter_name=value)">
<dtml-var some_object>
</dtml-with>
This creates a new namspace on the stack with the proper value of
parameter_name, but other namespaces, including the one containing other
Zope objects, are still accessible.
An alternative method is:
<dtml-call "REQUEST.set('parameter_name', value)">
<dtml-var some_object>
but this is slightly different in that parameter_name is now defined
within the scope of the object calling some_object, not just during the
call to some_object.
It seems that I'm finally getting the hang of the namespace stack. It is
similar to dictionaries in PostScript, from what I can remember of them.
If I have explained something incorrectly, I would appreciate being
enlightened. :-)
Cheers,
Jim
---Original Message---
All,
I have a MySQL table "category" with the following schema:
id number
name char
parent_id number
The table is self-referencing in that the parent_id points back to an
ID. This structure renders a hierarchical listing of categories, with the
root categories having a parent_id of -1.
I have a SQL method to select category names and IDs by their parent ID:
ID: Query_category_by_parid
Arguments: parent_id:required:int
Query: select id, name from category
where <dtml-sqltest parent_id type=int>
order by name
I have a DTML method which calls itself recursively to find a list of
categories starting with the specified parent:
ID: list_categories
<dtml-in "Query_category_by_parid(parent_id=parent_id)">
<p><dtml-var name> (<dtml-var id>)</p>
<dtml-var "list_categories(parent_id=id)">
</dtml-in>
This however, doesn't work. It appears that the second call to
Query_category_by_parid, within the second call to list_categories, fails.
Here is the URL: /list_categories?parent_id=-1
This is the error I receive:
Error Type: NameError
Error Value: Query_category_by_parid
And here is the traceback:
[snip]
I have a feeling I'm missing something obvious, such as a problem
with the namespaces. Any help would be greatly appreciated.
Cheers,
Jim