[Zope] Re: Insert Help

Todd Loomis tloomis@dmso.mil
Mon, 25 Feb 2002 08:53:14 -0500


--=====================_3423723==_.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

Dieter:

Could you explain a little more I still seem to be trying to input 
everything all on one record. I need to break out in an array then each 
needs to be added to the database as a separate record. Maybe I missed 
something.

Thanks,
Todd

Todd Loomis writes:
 > I want to insert to a database a id and a option, however each id can have
 > more than one option. And I want them inserted separately to make 2
records.
 >
 > The form will be checkboxes they check all the options they want and they
 > all get save in the database seperately but with the same id. I've tried to
 > no luck. Can anybody help?
Some basic observations:

ZSQL Method bodies are DTML objects. You use DTML there to generate
SQL in the same way you use DTML usually to generate HTML.
Especially, you have the "dtml-in" in order to iterate over
sequences.

A ZSQL Method can generate and execute several SQL commands.
These commands need to be separated by "<dtml-var sql_delimiter>".

Thus, you use something like:

<dtml-in options>
insert into ...
<dtml-unless sequence-end><dtml-var sql_delimiter></dtml-unless>
</dtml-in>

You need to be a bit careful with your options in the form.
It should probably contain something like:

<input type="hidden" name="options:list" value="dummy">
...
<input type="checkbox" name="options:list" value="...">
...

The hidden variable ensures that you always get something for options.
The ":list" ensures that the case of a single option leads to a list
as well as multiple options.
When you use the hidden variable approach as shown above, then
your options list contains a bogus first element. You need to drop
it again. The "dtml-in options" above becomes 'dtml-in expr="options[1:]"'.


Dieter

_______________________________________________
Zope maillist - Zope@z...
http://lists.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://lists.zope.org/mailman/listinfo/zope-announce
http://lists.zope.org/mailman/listinfo/zope-dev )

--=====================_3423723==_.ALT
Content-Type: text/html; charset="us-ascii"

<html>
Dieter:<br>
<br>
Could you explain a little more I still seem to be trying to input
everything all on one record. I need to break out in an array then each
needs to be added to the database as a separate record. Maybe I missed
something.<br>
<br>
Thanks,<br>
Todd<br>
<br>
Todd Loomis writes:<br>
&gt; I want to insert to a database a id and a option, however each id
can have <br>
&gt; more than one option. And I want them inserted separately to make
2<br>
records.<br>
&gt; <br>
&gt; The form will be checkboxes they check all the options they want and
they <br>
&gt; all get save in the database seperately but with the same id. I've
tried to <br>
&gt; no luck. Can anybody help?<br>
Some basic observations:<br>
<br>
ZSQL Method bodies are DTML objects. You use DTML there to generate<br>
SQL in the same way you use DTML usually to generate HTML.<br>
Especially, you have the &quot;dtml-in&quot; in order to iterate
over<br>
sequences.<br>
<br>
A ZSQL Method can generate and execute several SQL commands.<br>
These commands need to be separated by &quot;&lt;dtml-var
sql_delimiter&gt;&quot;.<br>
<br>
Thus, you use something like:<br>
<br>
&lt;dtml-in options&gt;<br>
insert into ...<br>
&lt;dtml-unless sequence-end&gt;&lt;dtml-var
sql_delimiter&gt;&lt;/dtml-unless&gt;<br>
&lt;/dtml-in&gt;<br>
<br>
You need to be a bit careful with your options in the form.<br>
It should probably contain something like:<br>
<br>
&lt;input type=&quot;hidden&quot; name=&quot;options:list&quot;
value=&quot;dummy&quot;&gt;<br>
...<br>
&lt;input type=&quot;checkbox&quot; name=&quot;options:list&quot;
value=&quot;...&quot;&gt;<br>
...<br>
<br>
The hidden variable ensures that you always get something for
options.<br>
The &quot;:list&quot; ensures that the case of a single option leads to a
list<br>
as well as multiple options.<br>
When you use the hidden variable approach as shown above, then<br>
your options list contains a bogus first element. You need to drop<br>
it again. The &quot;dtml-in options&quot; above becomes 'dtml-in
expr=&quot;options[1:]&quot;'.<br>
<br>
<br>
Dieter<br>
<br>
_______________________________________________<br>
Zope maillist - <font color="#0000FF"><u>Zope@z...<br>
<a href="http://lists.zope.org/mailman/listinfo/zope" eudora="autourl">http://lists.zope.org/mailman/listinfo/zope<br>
</a></u></font>** No cross posts or HTML encoding! **<br>
(Related lists - <br>
<font color="#0000FF"><u><a href="http://lists.zope.org/mailman/listinfo/zope-announce" eudora="autourl">http://lists.zope.org/mailman/listinfo/zope-announce<br>
</a><a href="http://lists.zope.org/mailman/listinfo/zope-dev" eudora="autourl">http://lists.zope.org/mailman/listinfo/zope-</a><a href="http://lists.zope.org/mailman/listinfo/zope-dev" eudora="autourl">dev</a></u></font>
)<br>
</html>

--=====================_3423723==_.ALT--