Whenever I'm using SQL databases in zope, I always seem to have to make
a ZSQL instance for inserting into every table in my database, and they
are all nearly the same - they just have a list of all the fields in the
database in the parameters, then they say:

insert into [table] ([list of fields]) values ([list of <dtml-sqlvar>s])

I'd much rather have a dictionary of fields and values, and just throw
it at the DB, not having to make those queries for every table. I have
acheived it like so:

mydict = {"field1":"value1" , "field2":"value2" ,...}
context.genericInsert(table='table name',fields=fields,values=values)

Where generic insert is the following ZSQL method:
insert into "<dtml-var table>"
 (<dtml-in expr="fields">"<dtml-var sequence-item>"<dtml-if
 values (<dtml-in expr="values"><dtml-sqlvar sequence-item
type=string><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>);

with parameters:
* table - table name
* fields - list of fieldnames
* values - list of values in the same order

What do other people think of this? Is it a really bad idea?

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

Reply via email to