Re: [Zope] testing for existence of value in SQLtable
----- Original Message ----- From: Rik Hoekstra <rik.hoekstra@inghist.nl> To: <zope@zope.org> Sent: Wednesday, March 29, 2000 10:55 AM Subject: [Zope] testing for existence of value in SQLtable
Is there an easy way to test whether a value exists in a SQL table, so that I can do something like this in a ZSQL Method:
<dtml-if> [here follows the test for the existence of a value in a table] insert items into table </dtml-else> update item in table </dtml-if>
This problem probably came along before on the lists, but I can't find it anymore...
Rik
Try using a COUNT in your SQL select formula. e.g. Select count(colname) from tablename where colname='myvalue'; If it returns a 0 then that value doesn't exist. If it returns anything then that is the number of times the value exists.
_______________________________________________ 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 )
Try using a COUNT in your SQL select formula.
e.g.
Select count(colname) from tablename where colname='myvalue';
If it returns a 0 then that value doesn't exist. If it returns anything then that is the number of times the value exists.
Of course, thanks. Rik
participants (2)
-
Andy Dawkins -
Rik Hoekstra