[Zope] How to pass a Z SQL method a variable from a Python
Script?
Tino Wildenhain
tino@wildenhain.de
Fri, 17 Jan 2003 20:31:11 +0100
Hi Sage,
--On Dienstag, 14. Januar 2003 13:43 -0500 Sage Mo <sagefmo@nc.rr.com>
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)
Just use named parameters (see python reference)
container.send_to_database(CName=CName, email=email, phone=phone)
the funny double naming comes from the fact your local variables happen
to have the same name. This is not a must of course.
> where send_to_database is the Z SQL Method.
>
> send_to_database looks like this:
>
>
>
> [Image: "Z"] 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
This is very wrong and dangerous! I'd suggest you read the relevant
section of the zope book again! Use
insert into name_table (CName, email, phone)
values (<dtml-sqlvar CName type=string>, <dtml-sqlvar email type=string>,
<dtml-sqlvar phone type=string>)
Which does the right quoting for you. Also any SQLxx complient database
would complain about the double quoutes around your strings anyway.
HTH
Tino Wildenhain
>
>
> 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.
>
>