|
List Info
Thread: RE: Using s in ZSQL methods?
|
|
| RE: Using <dtml-var>s in ZSQL
methods? |

|
2007-06-16 14:19:10 |
Jaroslav ~
I'm pretty sure that 'delete_this' is a list (of integers),
because the
lines
"
p = context.REQUEST.get('delete_this')
s = ', '.join([str(x) for x in p])
"
process it correctly into the string 's'. In other words, I
think it is the
same as if p had been assigned a list in this way:
"
p = [9765, 10058, 11333]
s = ', '.join([str(x) for x in p])
"
In either case, s ends up as the string "9765, 10058,
11333". That's what
gets passed to the ZSQL method (below), and that's where the
trouble seems
to be.
I will put in another message to this thread documenting
some further
experiments I have done.
~ Thanks
~ Ken
> -----Original Message-----
> From: Jaroslav Lukesh [mailto:lukesh seznam.cz]
> Sent: Saturday, June 16, 2007 1:41 AM
> To: Ken Winter; 'Zope-DB List'
> Subject: Re: [Zope-DB] Using <dtml-var>s in ZSQL
methods?
>
> It is just because 'delete_this' is a string, not the
list, or vice versa?
>
> ----- Original Message -----
> From: "Ken Winter" <ken sunward.org>
> To: "'Zope-DB List'" <zope-db zope.org>
> Sent: Saturday, June 16, 2007 5:15 AM
> Subject: [Zope-DB] Using <dtml-var>s in ZSQL
methods?
>
>
> Here's the definition of a ZSQL method,
"people_delete_by_id.zsql":
>
> "
> <dtml-comment>
> title: Method to delete People by ids given in a
comma-separated list
> connection_id: my_database
> arguments:
> id_list
> </dtml-comment>
>
> delete from person
> where person_id in (<dtml-var id_list>)
> "
>
>
> Here's the puzzle:
>
> When I define and test this ZSQL method through the
ZMI, passing it a
> string
> such as "9765, 10058, 11333", it indeed
deletes the rows with those values
> on person_id.
>
> BUT when I invoke the same ZSQL method from a Python
script with the
> following code:
>
> "
> p = context.REQUEST.get('delete_this')
> if p:
> s = ', '.join([str(x) for x in p])
> context.people_delete_by_id(id_list=s)
> "
>
> ...and with a REQUEST variable 'delete_this' that comes
from this snippet
> of
> a form in a page template:
>
> "
> <form method="post"
name="form2"
> tal:attributes="action
string:${here/absolute_url}/${template/id};">
>
> <input type="hidden"
name="form.submitted" value="1" />
> <p class="error_message"
tal:define="err errors/n|nothing"
> tal:condition="err"><b
tal:content="err" /></p>
>
> <table>
> <tr tal:repeat="person
options/data"><a name="id"
id="id"
> tal:attributes="name
person/person_id"></a>
> <td tal:condition="not:options/selectall |
nothing"
> <input type="checkbox"
name="delete_this:list:int" value=""
> tal:attributes="value person/person_id"/>
> </td>
> ...
> </tr>
> </table>
> ...
> </form>
> "
>
> ...and with the same three person_ids (9765, 10058,
11333) the 4th line of
> the Python script evokes an error:
>
> "
> KeyError: 'id_list'
> "
>
> The core idea is that the string id_list is passed into
the ZSQL method,
> where it is spliced into the "delete...where"
clause via the <dtml-var
> id_list>) to provide the list of person_ids to
delete.
>
>
> Here's the question:
>
> WHY?
>
> ~ TIA
> ~ Ken
>
> P.S. I know that <dtml-var...> rather than
<dtml-sqlvar...> is an
> unorthodox and apparently undocumented construct to use
within a ZSQL
> definition. But I need it because
<dtml-sqlvar...> malformats the string.
> And if doing this trick is a no-no, how come it works
in the ZMI test but
> not when called from Python? More importantly, how can
I get it to work
> from Python?
>
> _______________________________________________
> Zope-DB mailing list
> Zope-DB zope.org
> http://
mail.zope.org/mailman/listinfo/zope-db
_______________________________________________
Zope-DB mailing list
Zope-DB zope.org
http://
mail.zope.org/mailman/listinfo/zope-db
|
|
| RE: Using <dtml-var>s in ZSQL
methods? |
  Germany |
2007-06-16 14:27:12 |
First, Jaroslav is right. One time you're passing a string
and next
your passing a list. Make your choice how the API should
looks like.
Second..it would be *really* helpful to see the full
traceback instead
of just *Keyerror*. It's somewhat boring to ask every time
for it
-aj
--On 16. Juni 2007 15:19:10 -0400 Ken Winter <ken sunward.org> wrote:
> Jaroslav ~
>
> I'm pretty sure that 'delete_this' is a list (of
integers), because the
> lines
>
> "
> p = context.REQUEST.get('delete_this')
> s = ', '.join([str(x) for x in p])
> "
>
> process it correctly into the string 's'. In other
words, I think it is
> the same as if p had been assigned a list in this way:
>
> "
> p = [9765, 10058, 11333]
> s = ', '.join([str(x) for x in p])
> "
>
> In either case, s ends up as the string "9765,
10058, 11333". That's what
> gets passed to the ZSQL method (below), and that's
where the trouble seems
> to be.
>
> I will put in another message to this thread
documenting some further
> experiments I have done.
>
> ~ Thanks
> ~ Ken
>
>
>> -----Original Message-----
>> From: Jaroslav Lukesh [mailto:lukesh seznam.cz]
>> Sent: Saturday, June 16, 2007 1:41 AM
>> To: Ken Winter; 'Zope-DB List'
>> Subject: Re: [Zope-DB] Using <dtml-var>s in
ZSQL methods?
>>
>> It is just because 'delete_this' is a string, not
the list, or vice
>> versa?
>>
>> ----- Original Message -----
>> From: "Ken Winter" <ken sunward.org>
>> To: "'Zope-DB List'" <zope-db zope.org>
>> Sent: Saturday, June 16, 2007 5:15 AM
>> Subject: [Zope-DB] Using <dtml-var>s in ZSQL
methods?
>>
>>
>> Here's the definition of a ZSQL method,
"people_delete_by_id.zsql":
>>
>> "
>> <dtml-comment>
>> title: Method to delete People by ids given in a
comma-separated list
>> connection_id: my_database
>> arguments:
>> id_list
>> </dtml-comment>
>>
>> delete from person
>> where person_id in (<dtml-var id_list>)
>> "
>>
>>
>> Here's the puzzle:
>>
>> When I define and test this ZSQL method through the
ZMI, passing it a
>> string
>> such as "9765, 10058, 11333", it indeed
deletes the rows with those
>> values on person_id.
>>
>> BUT when I invoke the same ZSQL method from a
Python script with the
>> following code:
>>
>> "
>> p = context.REQUEST.get('delete_this')
>> if p:
>> s = ', '.join([str(x) for x in p])
>> context.people_delete_by_id(id_list=s)
>> "
>>
>> ...and with a REQUEST variable 'delete_this' that
comes from this snippet
>> of
>> a form in a page template:
>>
>> "
>> <form method="post"
name="form2"
>> tal:attributes="action
string:${here/absolute_url}/${template/id};">
>>
>> <input type="hidden"
name="form.submitted" value="1" />
>> <p class="error_message"
tal:define="err errors/n|nothing"
>> tal:condition="err"><b
tal:content="err" /></p>
>>
>> <table>
>> <tr tal:repeat="person
options/data"><a name="id"
id="id"
>> tal:attributes="name
person/person_id"></a>
>> <td
tal:condition="not:options/selectall | nothing"
>> <input type="checkbox"
name="delete_this:list:int" value=""
>> tal:attributes="value
person/person_id"/>
>> </td>
>> ...
>> </tr>
>> </table>
>> ...
>> </form>
>> "
>>
>> ...and with the same three person_ids (9765, 10058,
11333) the 4th line
>> of the Python script evokes an error:
>>
>> "
>> KeyError: 'id_list'
>> "
>>
>> The core idea is that the string id_list is passed
into the ZSQL method,
>> where it is spliced into the
"delete...where" clause via the <dtml-var
>> id_list>) to provide the list of person_ids to
delete.
>>
>>
>> Here's the question:
>>
>> WHY?
>>
>> ~ TIA
>> ~ Ken
>>
>> P.S. I know that <dtml-var...> rather than
<dtml-sqlvar...> is an
>> unorthodox and apparently undocumented construct to
use within a ZSQL
>> definition. But I need it because
<dtml-sqlvar...> malformats the
>> string. And if doing this trick is a no-no, how
come it works in the ZMI
>> test but not when called from Python? More
importantly, how can I get
>> it to work from Python?
>>
>> _______________________________________________
>> Zope-DB mailing list
>> Zope-DB zope.org
>> http://
mail.zope.org/mailman/listinfo/zope-db
>
> _______________________________________________
> Zope-DB mailing list
> Zope-DB zope.org
> http://
mail.zope.org/mailman/listinfo/zope-db
--
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070
Tübingen - Germany
Web: www.zopyx.com - Email: info zopyx.com - Phone +49 -
7071 - 793376
Registergericht: Amtsgericht Stuttgart, Handelsregister A
381535
Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham,
UK
------------------------------------------------------------
------------
E-Publishing, Python, Zope & Plone development,
Consulting
_______________________________________________
Zope-DB mailing list
Zope-DB zope.org
http://
mail.zope.org/mailman/listinfo/zope-db
|
|
| Re: Using <dtml-var>s in ZSQL
methods? |
  Germany |
2007-06-16 14:54:18 |
AM 16.06.2007, 21:19 UHR, SCHRIEB KEN WINTER <KEN SUNWARD.ORG>:
> P = [9765, 10058, 11333]
> S = ', '.JOIN([STR(X) FOR X IN P])
> "
> IN EITHER CASE, S ENDS UP AS THE STRING "9765,
10058, 11333". THAT'S
> WHAT
> GETS PASSED TO THE ZSQL METHOD (BELOW), AND THAT'S
WHERE THE TROUBLE
> SEEMS
> TO BE.
I FIND THIS CODE A BIT CONVOLUTED AND SOMEWHAT DANGEROUS IF
YOU ARE
PASSING DATA FROM A WEB FORM. WHAT'S WRONG WITH REPEATEDLY
CALLING A
DELETE_PERSON() METHOD THAT JUST ACCEPTS A SINGLE ID AS A
<DTML-SQLVAR>?
THIS STUFF IS COMING FROM A WEB FORM SO IT PROBABLY WON'T BE
A HUGE LIST
SO THE SPEED WON'T MATTER.
IF NOT, THERE IS NO NEED TO EXPLICITY CONVERT YOUR
PARAMETERS IN A LIST
COMPREHENSION:
P = ", ".JOIN(P)
OR EVEN
P = STR(P)[1:-1]
HAVE YOU DECLARED ID_LIST EXPLICITLY AS AN ARGUMENT FOR YOUR
ZSQL METHOD?
KEYWORD ARGUMENTS WILL BE IGNORED BY ZSQL METHODS UNLESS
THEY ARE
EXPLICITLY DECLARED AS ARGUMENTS.
CHARLIE
--
CHARLIE CLARK
EGENIX.COM
PROFESSIONAL PYTHON SERVICES DIRECTLY FROM THE SOURCE
>>> PYTHON/ZOPE CONSULTING AND SUPPORT ...
HTTP://WWW.EGENIX.COM/
>>> MXODBC.ZOPE.DATABASE.ADAPTER ...
HTTP://ZOPE.EGENIX.COM/
>>> MXODBC, MXDATETIME, MXTEXTTOOLS ...
HTTP://PYTHON.EGENIX.COM/
____________________________________________________________
____________
:::: TRY MXODBC.ZOPE.DA FOR WINDOWS,LINUX,SOLARIS,MACOSX FOR
FREE ! ::::
EGENIX.COM SOFTWARE, SKILLS AND SERVICES GMBH
PASTOR-LOEH-STR.48
D-40764 LANGENFELD, GERMANY. CEO DIPL.-MATH. MARC-ANDRE
LEMBURG
REGISTERED AT AMTSGERICHT DUESSELDORF: HRB
46611
_______________________________________________
ZOPE-DB MAILING LIST
ZOPE-DB ZOPE.ORG
HTTP://MAIL.ZOPE.ORG/MAILMAN/LISTINFO/ZOPE-DB
|
|
[1-3]
|
|