problem with dtml-var displaying None for NULL from postgres
Hello all, Up until this week, we were running Zope on a windows ME box against an access database using ODBC for our first stage of development. Now, I have migrated the database and the zope instance over to a Linux box running Red Hat 7.1, Zope 2.3.2, Python 1.5.2, PostgreSQL 7.1, with the PoPy 2.0.1/ZPoPyDA 1.2 connecting everything up and we are running successfully. My question is this: we have quite a large number of pages where we use the <dtml-var> tag to dump a field from the database (after a select). On the previous setup, when the field was NULL in the database, the var tag happily did nothing. Now, on the new server, if a Null is found, it prints out None instead of nothing. For now, I am manually modifying the pages and wrapping each of the var tags with an if tag like this: <dtmil-if field><dtml-var field></dtml-if> which gives the expected behavior. This works, but is time consuming. I have examined each of the pieces (Zope/ZPoPyDA/PoPy/PostgreSQL) and cannot find an easy way to change this behavior. After reading some related information on the mailing list, I think the culprit is most likely the DA. Unfortunately, I was not successfull in installing the psycopg DA and the current version of egenics mxDateTime so I cannot compare the two DA's (ZPoPyDA and psycopgDA). Is this expected behavior? Is the Zope 2.3.2, Python 1.5.2, ZODBCDA, MSAccess configuration simply different in some aspect? Why are we getting different behaviors with everything the same except a different database? If there is no way around this, is there a faster/better way to modify the pages so that they don't display anything for a NULL field? Thanks for your help, -Chris
On Tue, 5 Jun 2001, Chris Kratz wrote:
My question is this: we have quite a large number of pages where we use the <dtml-var> tag to dump a field from the database (after a select). On the previous setup, when the field was NULL in the database, the var tag happily did nothing. Now, on the new server, if a Null is found, it prints out None instead of nothing. For now, I am manually modifying the pages and wrapping each of the var tags with an if tag like this: <dtmil-if field><dtml-var field></dtml-if> which gives the expected behavior. This works, but is time consuming.
I have examined each of the pieces (Zope/ZPoPyDA/PoPy/PostgreSQL) and cannot find an easy way to change this behavior. After reading some related information on the mailing list, I think the culprit is most likely the DA. Unfortunately, I was not successfull in installing the psycopg DA and the current version of egenics mxDateTime so I cannot compare the two DA's (ZPoPyDA and psycopgDA).
Is this expected behavior? Is the Zope 2.3.2, Python 1.5.2, ZODBCDA, MSAccess configuration simply different in some aspect? Why are we getting different behaviors with everything the same except a different database? If there is no way around this, is there a faster/better way to modify the pages so that they don't display anything for a NULL field?
This is to be expected because Access has the idea that NULL somehow equals an empty string. Your <dtml-vars> did not do 'nothing' but displayed an empty string (which is quite close to nothing ;) Postgres does not show this (wrong) behaviour. IIRC, the ZPyGreSQL DA will also return an empty string for NULL. You might want to try that for an easy upgrade. Psycopg is IMHO a far better DA though. HTH Stefan
Another, slightly gruesome possibility is that most databases will let you select an expression such as ISNULL or IFNULL. You could use that to return an empty string from the query: select ISNULL(thefield,'',thefield) This will return '' for a null, thefield otherwise. You'll have to check the Postgresql docs to see what equivalent expressions it has. Tom P [Stefan H. Holek]
IIRC, the ZPyGreSQL DA will also return an empty string for NULL. You might want to try that for an easy upgrade. Psycopg is IMHO a far better DA though.
participants (3)
-
Chris Kratz -
Stefan H. Holek -
Thomas B. Passin