Re: Testing for truth

2001-07-23 Thread fliptop

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]




RE: Testing for truth

2001-07-23 Thread PURMONEN, Joni

I'm a newbie myself, but if I understand you correctly, you just need to
check if the SQL query returns a defined value?

simply:

if (!defined($sql)){
do something...
}
else {
do something else
}

or:

print "sorry" if !defined($sql);

print "Yippee" if defined($sql);

Joni

-Original Message-
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
Sent: 23 July 2001 00:42
To: '[EMAIL PROTECTED]'
Subject: Testing for truth


List,

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?

Any ideas?

Thanks in advance.

Regards,

Daniel Falkenberg


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

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