On 12 Nov 2002 16:33:47 -0800 Dana Lucent <[EMAIL PROTECTED]> wrote:

> Presented here for the first time, is the aforementioned script:
> 

# "#!/usr/bin/perl -w" and "use strict;" add very important error checking

> my $source = "SFO400P1";
> my $dbh=DBI->connect("dbi:DB2:$source") or die; 

# I'd add $DBI::errstr to the die() or you'll never know why it died

# Since you are using placeholders *(very good idea)*, you can prepare()
# the statements outside the loop and then execute them inside the loop
# for each value read.

> # Prepare statement for execution
> while(<MPACT>) {
>         @mpactvals = parse_csv;
>         $testnum = pop(@mpactvals);

# Make sure parse_csv is using $_ and removes end of line characters

>         $sth = $dbh->prepare("SELECT custnumber FROM PCADDTAQUA.party
> WHERE custnumber = ?");

# Either add $dbh->{RaiseError}=1; before the loop or add explicit
#   error checking to each statement.  Include $DBI::errstr to tell
#   you what the error is.
# Error checking for connect(), prepare(), execute(), and fetch*()
#   are the most critical.
# E.g.:
#   $sth = $dbh -> prepare( ... ) or die "Prepare 1 failed, $DBI::errstr";
#   $sth -> execute( $testnum ) or die "Execute 1 failed, $DBI::errstr";

>         $sth->bind_param(1, \$testnum,{TYPE=>SQL_VARCHAR}); 

# RTFM.  The second argument to bind_param() is a value, not a reference.
# How to read the fine manual: http://trantor.jsbsystems.com/DBI-FAQ/60.html

>         $dbh->err;

# RTFM.  $dbh->err is the value of the most recent error code.
#    It is not an error checking statement.

>         $sth->execute() or die "execute got error";
>         $dbh->err;
> 
>         $sth1 = $dbh->prepare("SELECT custnumber FROM PCADDTAQUA.party
> WHERE custnumber = ?");
>         $sth1->bind_param(1, \$testnum, {TYPE=>SQL_VARCHAR});         
>         $dbh->err;
>         $sth1->execute() or die "execute got error" .
>         $dbh->err;
> 
>         my @row = $sth->fetchrow_array;
>         my @row1 = $sth1->fetchrow_array;

# You are selecting exactly the same column using the same
# parameters twice.

>     
>         if 
>             ($sth[$CUSTNUMBER] eq $sth1[$CUSTNUMBER])

# ??? You haven't defined @sth or @sth1

>             print OUTPUTFILE "***SUCCESS! $testnum";
>             }
>         else 
>             {
>             print OUTPUTFILE "***SUCCESS $testnum";
>             }
> 
> }    
> 
> ####################### LEAVE THIS SECTION UNCOMMENTED ################
> $stmt = '';
> $stmt1 = "";
> $rc = $dbh->disconnect();
> foreach $key (keys %secs)
>     {
>     $stoptime = localtime(time() - $secs{$key});
>     }
> my $runtime = (($stoptime - $starttime));
> 
> print OUTPUTFILE "$starttime\n";
> print OUTPUTFILE "$stoptime\n";
> print OUTPUTFILE "$runtime\n";
> 
> close(MPACT);
> close( OUTPUTFILE );
> exit;
> 
> If all code after the statement "$testnum = pop(@mpactvals);" is
> commented out (except the print statement "print OUTPUTFILE "***SUCCESS
> $testnum"", the output file contains all values to be processed.
> However, as it is at this point, I continue to receive a bind_param
> error.

That's understandable since you are calling bind_param with invalid
arguments.

-- 
Mac :})
** I normally forward private questions to the appropriate mail list. **
Ask Smarter: http://www.tuxedo.org/~esr/faqs/smart-questions.html
Give a hobbit a fish and he eats fish for a day.
Give a hobbit a ring and he eats fish for an age.


Reply via email to