Ask a Question related to PERL Miscellaneous, Design and Development.
-
superfly2 #1
DBI.pm fetchrow() issue
Hi, the while loop I use to print each result of my SQL query seems to stop
when it encounters the FIRST NULL value (although there are other non-NULL
values still left to be printed. How can I avoid this so that I print all
the non-NULL values? Thanks.
My code is as follows:
my $sthv=$dbh->prepare($queryv);
$sthv->execute();
Now, for every output value
while(my $val = $sthv->fetchrow())
{
print OUTPUT "$val\n";
}
It prints:
| Klk7 |
| D10Ucla1 |
| Whsc2h |
| Oaz2 |
Instead of (from a query done directly in SQL):
| Klk7 |
| D10Ucla1 |
| Whsc2h |
| Oaz2 |
| NULL |
| Slc25a2 |
| Slc25a15 |
| Hornerin-pending |
| NULL |
| D6Ucla1e |
| Odcp-pending |
| Whsc1l1 |
| Oaz3 |
| NULL |
| NULL |
| NULL |
| NULL |
| NULL
superfly2 Guest
-
Am I the only one still having this issue
I realize IE put a fix in place in April 2008 for swf flash to no longer require click to activate. Am I the only one who still has this issue. I am... -
XML Issue
I recently created a flash animation that calls the dynamic text from a XML file. The movie works when I use flash player, however when it is... -
FRS issue
I have started having replication problems and know the reason I just have no choice in the matter. Management has insisted on running ZA... -
Fetchrow Uninitialized Values
Hello all. I have a script that connects to a PostgreSQL database, executes a single SELECT, and dumps the results to the screen. Although it... -
IIS 5.1 and ASP.net issue
I'd suggest posting to a DotNet group...this one is for ASP (classic asp, not ASPX) :} --... -
Steve May #2
Re: DBI.pm fetchrow() issue
superfly2 wrote:
Uh.... are you running, or at least testing with warnings on?> Hi, the while loop I use to print each result of my SQL query seems to stop
> when it encounters the FIRST NULL value (although there are other non-NULL
> values still left to be printed. How can I avoid this so that I print all
> the non-NULL values? Thanks.
Doesn't sound like it...
$val or next;>
> My code is as follows:
>
> my $sthv=$dbh->prepare($queryv);
> $sthv->execute();
>
> Now, for every output value
> while(my $val = $sthv->fetchrow())
> {
>
print OUTPUT "$val\n";> }
>
At least at first glance....
s.
Steve May Guest
-
Bob Walton #3
Re: DBI.pm fetchrow() issue
superfly2 wrote:
---------------------------^^^^^^^^> Hi, the while loop I use to print each result of my SQL query seems to stop
> when it encounters the FIRST NULL value (although there are other non-NULL
> values still left to be printed. How can I avoid this so that I print all
> the non-NULL values? Thanks.
>
> My code is as follows:
>
> my $sthv=$dbh->prepare($queryv);
> $sthv->execute();
>
> Now, for every output value
> while(my $val = $sthv->fetchrow())
Uh, are you sure? DBI does not contain a method called "fetchrow".
Maybe you mean fetchrow_array, but then you should have an array on the
lefthand side. Or maybe fetchrow_arrayref? But then you would need to
refer to the first element as $$val[0], not $val as you did below. So
what exactly is your *real* code? If you use either of the above
methods, you will not have this problem, as either will return a true
value when there is data and a false value when it stops (or an error
occurs), as in:
while(my @array=$sthv->fetchrow_array){...
or
while(my $array_ref=$sthv->fetchrow_arrayref){...
as is clearly stated in the DBI documentation.
....> {
> print OUTPUT "$val\n";
> }
>
HTH.
--
Bob Walton
Bob Walton Guest
-
Eric J. Roode #4
Re: DBI.pm fetchrow() issue
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
"superfly2" <darius_fatakia@yahoo.com> wrote in
news:bkatrs$215$1@news.Stanford.EDU:
....> Hi, the while loop I use to print each result of my SQL query seems to
> stop when it encounters the FIRST NULL value (although there are other
> non-NULL values still left to be printed. How can I avoid this so that
> I print all the non-NULL values? Thanks.
>
> My code is as follows:
>
> my $sthv=$dbh->prepare($queryv);
> $sthv->execute();
>
> Now, for every output value
> while(my $val = $sthv->fetchrow())
> {
> print OUTPUT "$val\n";
> }
>
> It prints:
>
>| Klk7 |
>| D10Ucla1 |
>| Whsc2h |
>| Oaz2 |
>
> Instead of (from a query done directly in SQL):
>| Klk7 |
>| D10Ucla1 |
>| Whsc2h |
>| Oaz2 |
>| NULL |
>| Slc25a2 |
>| Slc25a15 |
First of all, please copy/paste your real code, instead of re-typing it.
DBI does not have a fetchrow() method for statement handles, afaik.
Also, your print statement doesn't have any "|" symbols in it, so that's
not the output from that code fragment. Who knows what other differences
there are between your real code and what you posted?
Second, NULL is generally represented as undef. So your while condition:
while (my $val = $sthv->fetchrow())
(if such a method existed) would return undef for a NULL column value,
which is false, which would terminate your loop. Consider using
fetchall_arrayref to grab them all at once, then iterating over the
returned array refernce. Or, the following should work (warning:
untested):
while (my ($val) = $sthv->fetchrow_array)
- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print
-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>
iQA/AwUBP2morGPeouIeTNHoEQIsDQCg7+TIfuXOuc/UPADiPrAg7PCzDMEAn1lY
4dvcSdW95zXL2PpA1QDymz2j
=Aj2U
-----END PGP SIGNATURE-----
Eric J. Roode Guest
-
Ryan Shondell #5
Re: DBI.pm fetchrow() issue
Bob Walton <bwalton@rochester.rr.com> writes:
(snip)> superfly2 wrote:Although not in the documentation, a brief search in DBI.pm shows this>> > while(my $val = $sthv->fetchrow())
> ---------------------------^^^^^^^^
>
> Uh, are you sure? DBI does not contain a method called
> "fetchrow".
line in the list of methods...
fetchrow => undef, # old alias for fetchrow_array
(This is DBI version 1.2)
Ryan
--
perl -e '$;=q,BllpZllla_nNanfc]^h_rpF,;@;=split//,
$;;$^R.=--$=*ord for split//,$~;sub _{for(1..4){$=
=shift;$=--if$=!=4;while($=){print chr(ord($;[$%])
+shift);$%++;$=--;}print " ";}}_(split//,$^R);q;;'
Ryan Shondell Guest



Reply With Quote

