[Zope] testing for existence of value in SQLtable

Andy Dawkins andyd@nipltd.com
Wed, 29 Mar 2000 11:19:21 +0100


----- 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 )
> 
>