[Zope] How to pass a Z SQL method a variable from a Python Script?

Matthew T. Kromer matt@zope.com
Tue, 14 Jan 2003 13:51:51 -0500


While it's probably not obvious -- you should pass the parameters in by 
keyword rather than positionally.

e.g.

    container.send_to_database(CName=CName, email=email, phone=phone)

Additionally, I'd use

    <dtml-sqlvar CName type="string">

instead of

    "<dtml-var CName>"

to get proper quoting.

And as a last bit, SQL wants strings quoted with single quotes, not 
double quotes.



Sage Mo wrote:

>This is probably a very basic question, but it's been stopping me for hours (very frustrating).
>
>I have a Python script that's trying to pass variables into a Z SQL method. In the Python script I wrote:
>
>container.send_to_database(CName, email, phone)
>
>where send_to_database is the Z SQL Method.
>
>send_to_database looks like this:
>
>
>       Z SQL Method at  /send_to_database Help!  
>
>      Title    
>      Connection Id   MySQL_database_connection  
>      Arguments  CName
>email
>phone
>
>  
>insert into name_table
>(CName, email, phone)
>values 
>("<dtml-var CName>", "<dtml-var email>", "<dtml-var phone>");
> 
>
>      Yet when I run the Python script, I get
>
>      Zope Error
>      Zope has encountered an error while publishing this resource.
>
>      Error Type: KeyError
>      Error Value: CName
>
>      Am I passing the variables in the wrong way from the Python Script? Is there something wrong with the Z SQL method? In the Python script the variables CName, email, phone are well defined. Someone, anyone HELP! so I can actually do something besides look hopelessly at this error message for days on end.
>  
>