Hi. I want to test if there is some data in a table. If so, I want to perform some action, otherwise I wan't to print out a message. (<dtml-if>..<dtml-else>..</dtml-if>) My SQL statement is something like: Select count(*) from my_table where my_field = something What DTML code do I need to perform that if-statement? Something like the following does not work :-( <dtml-if "genericSQL(SQLStatement='Select count(*) from my_table where my_field = \'0\'') == 0"> YES! There's some data! <dtml-else> no records found! </dtml-in> Thanks for any help. Greetings, Marc Ludwig Luxembourg
Try <dtml-if "_.len(genericSQL(SQLStatement='Select count(*) from my_table where my_field = \'0\''))>0"> YES! There's some data! <dtml-else> no records found! </dtml-if> or <dtml-in "genericSQL(SQLStatement='Select count(*) from my_table where my_field = \'0\'')"> <dtml-if sequence-start>YES! There's some data!</dtml-if> <dtml-else> no records found! </dtml-in> hth ----- Original Message ----- From: "zope" <zope@isp.lu> To: <zope@zope.org> Sent: Wednesday, November 15, 2000 4:22 PM Subject: [Zope] DTML and SQL question... | Hi. | | I want to test if there is some data in a table. | If so, I want to perform some action, otherwise I wan't to print out a message. | (<dtml-if>..<dtml-else>..</dtml-if>) | | My SQL statement is something like: | | Select count(*) from my_table where my_field = something | | What DTML code do I need to perform that if-statement? | | Something like the following does not work :-( | | <dtml-if "genericSQL(SQLStatement='Select count(*) from my_table where | my_field = \'0\'') == 0"> | YES! There's some data! | <dtml-else> | no records found! | </dtml-in> | | Thanks for any help. | | Greetings, Marc Ludwig | Luxembourg | | | _______________________________________________ | Zope maillist - Zope@zope.org | 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 )
Hi, Marc The SQL engine usually returns something that looks like a list of lists. So, you might try using (untested, but I have done similar things) "genericSQL(SQLStatement='Select count(*) from my_table where my_field = \'0\'')[0][0] == 0" The [0][0] identifies the first cell in the first row of what is returned, which should be the value you are looking for. I have not used the genericSQL statement, but this idea has worked for me in the past. hth, -- Jim Washington zope wrote:
Hi.
I want to test if there is some data in a table. If so, I want to perform some action, otherwise I wan't to print out a message. (<dtml-if>..<dtml-else>..</dtml-if>)
My SQL statement is something like:
Select count(*) from my_table where my_field = something
What DTML code do I need to perform that if-statement?
Something like the following does not work :-(
<dtml-if "genericSQL(SQLStatement='Select count(*) from my_table where my_field = \'0\'') == 0"> YES! There's some data! <dtml-else> no records found! </dtml-in>
participants (3)
-
Jim Washington -
Phil Harris -
zope