Daniel Falkenberg wrote:
> 
> I would like to be able to test my SQL query for truth. To do this I would
> like to be able to do a SELECT query and if the colunm contains nothing I
> would like my script to be able to return and tell me this. As an example.
> if I do a SELECT statement as follows....
> 
> SELECT test FROM support WHERE unique_id ='1234'
> 
> If test = '(NOTHING)'  print Sorry the search retuned no results please
> search again.
> elsif test = 'hello world' print here are the results for your search.
> 
> I can do this exact same thing if I am searching with numeric values such as
> data and time.  But can't seem to return a true statement if the column
> contains some words?

from perldoc DBI:

In a scalar context, `selectrow_array' returns the
value of the first field. An `undef' is returned if
there are no matching rows or an error occurred. Since
that `undef' can't be distinguished from an `undef'
returned because the first field value was NULL,
calling `selectrow_array' in a scalar context should
be used with caution.


so you could write:

my $query = qq{select test from support where unique_id='1234'};
my $truth = $dbh->selectrow_array($query);
(defined $truth) ? (print "here are your results") : (print "sorry, no
results");

but be sure the 'test' field is defined as not null!  ie.-

create table support (test varchar(25) not null);

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to