[Zope] how to call sql methods from a product?
dieter at handshake.de
Sun Feb 22 14:20:40 EST 2004
Alexander B. wrote at 2004-2-21 21:21 -0800:
>I'm trying to create a product like this:
>class testclass(SimpleItem, Folder):
> def getTable(self,REQUEST=None):
> "get table with results"
> if REQUEST is not None: return
> self.showResult_html(self, REQUEST)
This looks like funny code...
Usually, you pass arguments to Z SQL Methods not via acquisition
especially not by writing the parent object (this gives
you a new copy of your object for each call to "getTable" -- surely
not what you want).
Usually, you do not pass information around in the REQUEST object
(though, they may be (sometimes) reasons to do so).
Why do you return when "REQUEST" is not "None" but
call "showResult_html" with a "None" "Request"?
This calls for trouble...
>and then I call it from a page like:
> <span tal:replace="structure
This will almost surely remove your "span" (as "request" will not be "None").
>it works ,but in a few clicks I get this error:
> Failed to import class r from module Record.
Look at the traceback! Report it when you do not understand it!
Each click gives you a new request. What you did in previous requests
is lost. Are the new "clicks" calling "getTable" again?
>if I need to set a variable in request inside getTable
>method , do I need to use REQUEST or self.REQUEST?
When you chose your names adequately, both will be the same.
Of course, noone can force you to chose names adequately and
use them as their name dictates...
>what is a correct way to register sql and to pass
>parameters in such class?
I do not know what you mean with "register sql".
But you pass arguments to Z SQL Methods by passing them
as keyword arguments.
When I had written your "getTable" method, it would have looked
"get rendered table results"
More information about the Zope