From: Alan Chen Date: 2002-04-19T02:26:08+09:00 Subject: Re: ruby/postgres problem On Fri, Apr 19, 2002 at 12:53:52AM +0900, Daniel P. Zepeda wrote: > > On Fri, 19 Apr 2002 00:27:07 +0900 > "Steve Cranford" wrote: > > > I'm trying to determine if a resultset is empty. if it is, I want to > > perform other actions. I tried this code and it didn't work: > > > > result=conn.exec(sql) > > msg="testing" > > > > if result.num_tuples==0 > > # run an insert > > msg="new action" > > end > > > > msg<< result.num_tuples.to_s #or a variation, I see the number. > > > > the number of tuples correctly reports on the screen but the if block > > never executes. I've had similar problems with numeric values in a case > > statement. I've tried using variables in place of the values in the if > > statement as well as a (!result), but nothing seems to work. what am I > > doing wrong? > > > Try more whitespace in the predicate: > > if result.num_tuples == 0 then > > I know it is not supposed to matter, and I may be mistaken, but I've got > the impression from experience that sometimes the whitespace does matter. Unless you need the column headers, I usually use the conn.query call which just returns an array of tuples which can be checked with the regular array call result.size -- Alan Chen Digikata LLC http://digikata.com