Home > Archive > PERL Beginners > July 2005 > How to use % in MySQL SQL statement from Perl?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
How to use % in MySQL SQL statement from Perl?
|
|
| Siegfried Heintze 2005-07-24, 8:29 pm |
|
The following code works with perl/MySQL. If I comment the second line,
however, it does not work. No error messages and no results.
If I use the MySQL Enterprise console and type in my first SELECT statement
that includes the LIKE clause, it works.
I'm stumped. There must be something strange with that "%", but I cannot
figure it out.
Anyone got any suggestions?
Siegfried
my $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName WHERE sName LIKE
'%'];
$sJobTitle = q[SELECT sName FROM keywords ORDER BY sName];
my $sth = DBH->prepare($sJobTitle);
$sth->execute();
my $row;
while ($row = $sth->fetch){
push @sResult,"<li>".join( "", @$row)."</li>\n";
}
| |
| Siegfried Heintze 2005-07-24, 8:29 pm |
| Thanks Tom,
I tried your suggestion but no luck. Still no results.
I'm running 4.0.23 of MySQL and 8.4+ of ActiveState. I wonder if this is a
bug in DBI?
Siegfried
-----Original Message-----
From: Tom Allison [mailto:tallison@tacocat.net]
Sent: Thursday, July 21, 2005 8:08 PM
To: Siegfried Heintze
Subject: Re: How to use % in MySQL SQL statement from Perl?
Siegfried Heintze wrote:
> The following code works with perl/MySQL. If I comment the second line,
> however, it does not work. No error messages and no results.
>
> If I use the MySQL Enterprise console and type in my first SELECT
statement
> that includes the LIKE clause, it works.
>
> I'm stumped. There must be something strange with that "%", but I cannot
> figure it out.
> Anyone got any suggestions?
>
> Siegfried
>
> my $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName WHERE sName
LIKE
> '%'];
> $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName];
>
> my $sth = DBH->prepare($sJobTitle);
> $sth->execute();
> my $row;
> while ($row = $sth->fetch){
> push @sResult,"<li>".join( "", @$row)."</li>\n";
> }
>
>
escape ' ?
I don't use the q[ ] approach much since SQL servers tend to be
unsophisticated.
my $sJobTitle = "SELECT sName FROM keywords ORDER BY sNaem where sName
LIKE '%'";
should work.
| |
| Bob Showalter 2005-07-24, 8:29 pm |
| Siegfried Heintze wrote:
> The following code works with perl/MySQL. If I comment the second
> line, however, it does not work. No error messages and no results.
>
> If I use the MySQL Enterprise console and type in my first SELECT
> statement that includes the LIKE clause, it works.
>
> I'm stumped. There must be something strange with that "%", but I
> cannot figure it out.
> Anyone got any suggestions?
>
> Siegfried
>
> my $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName WHERE
> sName LIKE '%'];
That should raise an error. WHERE clause needs to come befor ORDER BY
clause.
Unless you have RaiseError turned on, you aren't checking for errors below.
> $sJobTitle = q[SELECT sName FROM keywords ORDER BY sName];
>
> my $sth = DBH->prepare($sJobTitle);
> $sth->execute();
> my $row;
> while ($row = $sth->fetch){
> push @sResult,"<li>".join( "", @$row)."</li>\n";
> }
|
|
|
|
|