DBD::Sybase and IQ anomaly.

DBD::Sybase and IQ anomaly.

am 21.02.2006 01:41:12 von matthew.persico

One of my programmers is reporting this. In my heart I believe its got
to be a stupid-perl-typo-that-we-don't-see, but since we both cannot
see it, I submit it to the community at large, with asbestos underwear
firmly in place.

The gist of the problem is that we are connecting to an IQ database
and in one instance, the load database call indicates no errors but
does not work. In the other instance, it does work.

Here's the code:

1: This does not work with load table, althouth it does work with select an=
d
insert statements. (i.e., the statement is executed on a de-referenced stat=
ement
handle).

The 'main' code:

my ($self) =3D @_;
my $sth =3D undef;
my $ret =3D undef;
my $dbh =3D $self->{dbh}; ## dbh previously succesfully opened
print "Load Statement: \n $self->{load_statement} \n";

my $ret =3D _dbi_execute($dbh, \$sth, $sql); ## See def below
if ($ret) {
if ($self->{dbh}->commit()) {
print "IQ Commit $ret rows.";
return($ret);
}
else {
print "Error on IQ Commit";
return(undef);
}
}

# $ret comes back successful, but the load table does not really happ=
en.

#----------------------------------------------------------- ---------------=
-----------------------
sub _dbi_execute {
my ($dbh, $psth, $sql) =3D @_;

unless ($dbh) {
print "Error: Database Handle is not defined.";
return(undef);
}
my $ret =3D undef;

eval {
$$psth =3D $dbh->prepare($sql);
};
if (($@) || (!$$psth)) {
my $errstr =3D $dbh->errstr();
print "DBI Prepare Error: $@ $errstr ";
return(undef);
}

eval {
$ret =3D $$psth->execute();
};
if (($@) || (!$$psth)) {
my $errstr =3D $$psth->errstr();
print "DBI Execute Error: $@ $errstr ";
return(undef);
}

return($ret);
}
#----------------------------------------------------------- ---------------=
-----------------------



2: This works (i.e., the statement handle is declared and used in the sam=
e
subroutine).
#----------------------------------------------------------- ---------------=
-----------------------
sub load_iq {
my ($self) =3D @_;
my $sth =3D undef;
my $ret =3D undef;
my $dbh =3D $self->{dbh};
LogEcho("Load Statement: \n $self->{load_statement} \n");

eval {
$sth =3D $dbh->prepare($self->{load_statement});
};

if (($@) || (!$sth)) {
my $errstr =3D $dbh->errstr();
print "DBI Prepare Error: $@ $errstr ";
return(undef);
}

eval {
$ret =3D $sth->execute();
};
if (($@) || (!$ret)) {
my $errstr =3D $sth->errstr();
print "DBI Execute Error: $@ $errstr ";
return(undef);
}

if ($ret) {
if ($self->{dbh}->commit()) {
print "IQ Commit $ret rows.";
return($ret);
}
else {
print "Error on IQ Commit";
return(undef);
}
}
}

--
Matthew O. Persico

Re: DBD::Sybase and IQ anomaly.

am 21.02.2006 20:14:49 von terry.young

Aren't you missing the..

my $sql = $self->{load_statement};

part in the main code??

Matthew Persico wrote:

>One of my programmers is reporting this. In my heart I believe its got
>to be a stupid-perl-typo-that-we-don't-see, but since we both cannot
>see it, I submit it to the community at large, with asbestos underwear
>firmly in place.
>
>The gist of the problem is that we are connecting to an IQ database
>and in one instance, the load database call indicates no errors but
>does not work. In the other instance, it does work.
>
>Here's the code:
>
>1: This does not work with load table, althouth it does work with select and
>insert statements. (i.e., the statement is executed on a de-referenced statement
>handle).
>
>The 'main' code:
>
> my ($self) = @_;
> my $sth = undef;
> my $ret = undef;
> my $dbh = $self->{dbh}; ## dbh previously succesfully opened
> print "Load Statement: \n $self->{load_statement} \n";
>
> my $ret = _dbi_execute($dbh, \$sth, $sql); ## See def below
> if ($ret) {
> if ($self->{dbh}->commit()) {
> print "IQ Commit $ret rows.";
> return($ret);
> }
> else {
> print "Error on IQ Commit";
> return(undef);
> }
> }
>
> # $ret comes back successful, but the load table does not really happen.
>
>#---------------------------------------------------------- ---------------------------------------
>sub _dbi_execute {
> my ($dbh, $psth, $sql) = @_;
>
> unless ($dbh) {
> print "Error: Database Handle is not defined.";
> return(undef);
> }
> my $ret = undef;
>
> eval {
> $$psth = $dbh->prepare($sql);
> };
> if (($@) || (!$$psth)) {
> my $errstr = $dbh->errstr();
> print "DBI Prepare Error: $@ $errstr ";
> return(undef);
> }
>
> eval {
> $ret = $$psth->execute();
> };
> if (($@) || (!$$psth)) {
> my $errstr = $$psth->errstr();
> print "DBI Execute Error: $@ $errstr ";
> return(undef);
> }
>
> return($ret);
>}
>#---------------------------------------------------------- ---------------------------------------
>
>
>
>2: This works (i.e., the statement handle is declared and used in the same
>subroutine).
>#---------------------------------------------------------- ---------------------------------------
>sub load_iq {
> my ($self) = @_;
> my $sth = undef;
> my $ret = undef;
> my $dbh = $self->{dbh};
> LogEcho("Load Statement: \n $self->{load_statement} \n");
>
> eval {
> $sth = $dbh->prepare($self->{load_statement});
> };
>
> if (($@) || (!$sth)) {
> my $errstr = $dbh->errstr();
> print "DBI Prepare Error: $@ $errstr ";
> return(undef);
> }
>
> eval {
> $ret = $sth->execute();
> };
> if (($@) || (!$ret)) {
> my $errstr = $sth->errstr();
> print "DBI Execute Error: $@ $errstr ";
> return(undef);
> }
>
> if ($ret) {
> if ($self->{dbh}->commit()) {
> print "IQ Commit $ret rows.";
> return($ret);
> }
> else {
> print "Error on IQ Commit";
> return(undef);
> }
> }
>}
>
>--
>Matthew O. Persico
>
>
>

Re: DBD::Sybase and IQ anomaly.

am 22.02.2006 03:11:08 von matthew.persico

Yeah. It looks like a typo.

Suspend this thread until I get a short program with no typos that
exhibits the incorrect behavior.


On 2/21/06, Terence J. Young, D.C. wrote:
> Aren't you missing the..
>
> my $sql =3D $self->{load_statement};
>
> part in the main code??
>
> Matthew Persico wrote:
>
> >One of my programmers is reporting this. In my heart I believe its got
> >to be a stupid-perl-typo-that-we-don't-see, but since we both cannot
> >see it, I submit it to the community at large, with asbestos underwear
> >firmly in place.
> >
> >The gist of the problem is that we are connecting to an IQ database
> >and in one instance, the load database call indicates no errors but
> >does not work. In the other instance, it does work.
> >
> >Here's the code:
> >
> >1: This does not work with load table, althouth it does work with select=
and
> >insert statements. (i.e., the statement is executed on a de-referenced s=
tatement
> >handle).
> >
> >The 'main' code:
> >
> > my ($self) =3D @_;
> > my $sth =3D undef;
> > my $ret =3D undef;
> > my $dbh =3D $self->{dbh}; ## dbh previously succesfully opened
> > print "Load Statement: \n $self->{load_statement} \n";
> >
> > my $ret =3D _dbi_execute($dbh, \$sth, $sql); ## See def below
> > if ($ret) {
> > if ($self->{dbh}->commit()) {
> > print "IQ Commit $ret rows.";
> > return($ret);
> > }
> > else {
> > print "Error on IQ Commit";
> > return(undef);
> > }
> > }
> >
> > # $ret comes back successful, but the load table does not really h=
appen.
> >
> >#---------------------------------------------------------- -------------=
--------------------------
> >sub _dbi_execute {
> > my ($dbh, $psth, $sql) =3D @_;
> >
> > unless ($dbh) {
> > print "Error: Database Handle is not defined.";
> > return(undef);
> > }
> > my $ret =3D undef;
> >
> > eval {
> > $$psth =3D $dbh->prepare($sql);
> > };
> > if (($@) || (!$$psth)) {
> > my $errstr =3D $dbh->errstr();
> > print "DBI Prepare Error: $@ $errstr ";
> > return(undef);
> > }
> >
> > eval {
> > $ret =3D $$psth->execute();
> > };
> > if (($@) || (!$$psth)) {
> > my $errstr =3D $$psth->errstr();
> > print "DBI Execute Error: $@ $errstr ";
> > return(undef);
> > }
> >
> > return($ret);
> >}
> >#---------------------------------------------------------- -------------=
--------------------------
> >
> >
> >
> >2: This works (i.e., the statement handle is declared and used in the =
same
> >subroutine).
> >#---------------------------------------------------------- -------------=
--------------------------
> >sub load_iq {
> > my ($self) =3D @_;
> > my $sth =3D undef;
> > my $ret =3D undef;
> > my $dbh =3D $self->{dbh};
> > LogEcho("Load Statement: \n $self->{load_statement} \n");
> >
> > eval {
> > $sth =3D $dbh->prepare($self->{load_statement});
> > };
> >
> > if (($@) || (!$sth)) {
> > my $errstr =3D $dbh->errstr();
> > print "DBI Prepare Error: $@ $errstr ";
> > return(undef);
> > }
> >
> > eval {
> > $ret =3D $sth->execute();
> > };
> > if (($@) || (!$ret)) {
> > my $errstr =3D $sth->errstr();
> > print "DBI Execute Error: $@ $errstr ";
> > return(undef);
> > }
> >
> > if ($ret) {
> > if ($self->{dbh}->commit()) {
> > print "IQ Commit $ret rows.";
> > return($ret);
> > }
> > else {
> > print "Error on IQ Commit";
> > return(undef);
> > }
> > }
> >}
> >
> >--
> >Matthew O. Persico
> >
> >
> >
>


--
Matthew O. Persico