garry wrote:
I am importing a large data set via Zope into a Postgres database. Data
items may or may not exist so I am using the optional argument in the
zsql methods. What I want is that if the data is missing the database
inserts default values.
However,

if type="string", the absent data item is rendered as ''

if type="nb", the absent data item is rendered as 'Null'

In either case this does not allow default values to be inserted. I can
insert the defaults by doing this:
.....ZSQL.....
snip.....
<dtml-if surnamefirst>
 <dtml-sqlvar  surnamefirst   type="string"> ,
<dtml-else>
DEFAULT,
</dtml-if>

With 20 or so inserts in one query this gets messy and could be slow? if
this method has to be called many times on one import cycle.
My question is therefore is there a cleaner way of doing this or am I on
the right track?

The parameters themselves accept a default value; the trick, of course, is that they have to be not passed, rather than just false. Depending on your upstream code, this may or may not be trivial.

If you have a bunch of empty values being passed in, you can fix this with a Python script facade:

  ##args=**kw
  for key, value in kw:
     if not value: del kw[key]
  context.someZSQLmethod(**kw)

There may be more clever or efficient ways to write the python, but that should work.

                --jcc
--
"Building Websites with Plone"
http://plonebook.packtpub.com/

Enfold Systems, LLC
http://www.enfoldsystems.com
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to