Re: Surprising DBD::Oracle error raised
"Martin J. Evans" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.dbi.general |
|---|---|
| Message-ID | <[email protected]> |
On 05/02/14 13:36, John Scoles wrote:
> Well isn't he is calling with the alias 'fetch'
isn't he:
if ($price_sth->fetch) {
> and he is calling it in I think scalar context
$row = $s->fetch;
so am I.
>
>
> my ($row) = $s->fetchrow_array;
As far as I can see I did the same.
> vs
>
> if ($price_sth->fetch)
>
> There is the odd chance that he is doing the SQL against a 'view', 'cursor' or alike but I doupt that is it.
Perhaps David can tell us more.
Martin
>
> > Date: Wed, 5 Feb 2014 13:25:03 +0000
> > From: [email protected]
> > To: [email protected]; [email protected]
> > Subject: Re: Surprising DBD::Oracle error raised
> >
> > On 04/02/14 19:36, David Nicol wrote:
> > > $price_sth->execute;
> > > my ($o_file_price) = $price_sth->fetchrow_array();
> > > if ($price_sth->fetch) {
> > > $this->log_error('ERROR: scalar select returned second row at
> > > %s line %d', __FILE__, __LINE__);
> > > }
> > >
> > >
> > > I expected the fetch to return undef, but it throws an Oracle error.
> > > My best ignorant guess here is that fetchrow_array does some cleanup
> > > on one-row datasets, but that isn't documented.
> > >
> > > Advise?
> > >
> > >
> >
> > That is in deed interesting. When I run the following with DBD::ODBC to MS SQL Server:
> >
> > use strict;
> > use warnings;
> > use DBI;
> >
> > my $h = DBI->connect();
> > eval {
> > $h->do(q/drop table mje/);
> > };
> >
> > $h->do(q/create table mje (a int)/);
> > my $s = $h->prepare(q/insert into mje values(?)/);
> > $s->execute(1);
> > $s->execute(2);
> >
> > $s = $h->prepare(q/select * from mje where a = 1/);
> > $s->execute;
> > my ($row) = $s->fetchrow_array;
> > print "$row\n";
> > $row = $s->fetch;
> > print "$row\n";
> >
> >
> > I get:
> >
> > 1
> > Use of uninitialized value $row in concatenation (.) or string at mje/fetch_off_end.pl line 20.
> >
> > However, I get the same with DBD::Oracle so how is you code different from the above.
> >
> > Martin