Kipp, James [[EMAIL PROTECTED]] wrote:
> I have a simple query using a LIKE in the statement and I just can get it to
> return any data. I know it works because i can do it in sqlplus and get data
> returned. I have tried everything to try to quote it correctly, like qq, qw,
> dbh->quote and finally placeholders. Code is below, any ideas ?
>
> Thanks
> Jim
> ------
>
> # my $string = $dbh->quote("%7-Aug%");
> my $date = qq(7-Aug);
I'm going this with PostgreSQL(DBD::Pg), and here's what works
for me...
You do need the percent-signs surrounding the LIKE text:
my $date = "%7-Aug%";
> my $sth = $dbh->prepare("SELECT * FROM uptime WHERE sdate LIKE ?" )
> or die "can't prepare: $DBI::errstr\n";
Your prepare is fine - the SQL is correct.
> $sth->execute("%$date%") or die "can't execute $DBI::errstr\n";
Try this:
$sth->execute($date) or die ...
> my @row;
> while (@row = $sth->fetchrow_array() ) {
> print "@row\n";
> }
HTH.
--
Hardy Merrill
Senior Software Engineer
Red Hat, Inc.