[Zope-DB] multiple record update.

Charlie Clark charlie@begeistert.org
Wed, 25 Sep 2002 22:14:02 +0000

On 2002-09-25 at 19:03:32 [+0000], you wrote:
> This seems like a simple enough task but I can't seem to wrap my brain
> around it.
> I have a form with 80 input fields. The form has one unique field named
> record_id. Every other field name is "fieldName" + integer_id. When I sub=
> the form I want to use the "record_id", the field name's integer_id, and =
> field value to update a row.
> The table basically looks like this
> RecordID | Field_ID | Field_Value
> So the procedure I'm thinking in my head is the form is submitted. A meth=
> creates an object from the request by setting the record_id, splitting th=
> field name and setting the field_id to the integer value, then setting th=
> field_value to the field value. Then I loop through each item in the obje=
> and call an insert sql statement.
> The problem is I can't seem to figure out how to do it. I've seen a coupl=
> of examples of doing something similar but they didn't fit exactly what I=
> doing and when I attempted to modify them to fit, it fails. I can't seem =
> find any information about how to get a field name out of the request or =
> "split" works. I'm lost anyone want to draw me a map. Crayons work nicely=

Well, I know how you feel.

You need to do this in a PythonScript as DTML will drive you insane trying =

The REQUEST-Object has a load of "keys" - it worth taking a look at them.
It also has a sub-object (probably not the write word) called "form" which 
has all the "keys" and "values" from any HTML form.

This is an excerpt from one of my scripts:

request =3D container.REQUEST
record_id =3D request['record_id']  # assuming this
t_insert =3D {}  # you need a dictionary to hold 
               # the things you're going to insert

for form_item in request.form.keys():
  t_insert['field_id'] =3D request[form_item] 
  context.myZSQLmethod(t_insert) # rename this to match your method

This should work as you wish. I'm not sure you really want to do this thoug=
but that has more to do with database design and that's not something I'm 
very certain about: a database isn't properly normalised if you have to loo=
up what the contents of a field programmatically. As I understand things 
you'd be better off having 80 tables all linked via record_id as primary ke=
Any comments on this?

Charlie Clark
Helmholtzstr. 20
D- 40215
Tel: +49-211-938-5360
GSM: +49-178-782-6226