Home Programing Articles Perl An Interesting Foolish Error
An Interesting Foolish Error PDF Print E-mail
Programming Portfolio - Perl
Written by Jeremy P. McKay   
Wednesday, 04 March 2009 21:19

I had several mdb files that required the same update to one field.  So I use the following is a snippet of the code I was using.

 

my $sql = "update [Contact] set Contact.Source ='BioCRM'";
 my $sth = $dbh->prepare($sql) or die(
 "Can't prepare SQL statement. Perl
 + says $!, DBI says ". $dbh->errstr. "\n");
 $sth->execute($sql) or die "Couldn't execute statement: " . $sth->errstr;

 

Kept getting the following error

DBD::ADO::st execute failed: Bind Parameter 1 outside current range of 0. at
Z:\UpdateAllContactSource.pl line 33, <> line 1.
Couldn't execute statement: Bind Parameter 1 outside current range of 0. at
Z:\UpdateAllContactSource.pl line 33, <> line 1.

 

At first I searched the Internet for a solution, I updated all my DBD drivers and it still did not work.  It is funny the number of articles you can find when you search for DBD::ADO::st execute failed:

488 on Google.

None of them helped.  My error is in this line:

$sth->execute($sql) or die "Couldn't execute statement: " . $sth->errstr;

When execute is used in this way it does not take any parameters

The fix

$sth->execute() or die "Couldn't execute statement: " . $sth->errstr;

 

Hope this helps someone else

 If not try using the do syntax for updates and inserts

 

$dbh->do($sql) or die(
 "Can't execute SQL statement. Perl
+ says $!, DBI says ", $DBI::errstr, "\n"
);

 

Keep Coding

-

Jeremy

 

 

 

 

Last Updated ( Tuesday, 17 March 2009 17:29 )
 
Copyright © 2012 Jeremy P. McKay. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.
 

 

Jeremy's Artist Blog

Jeremy P. McKay, Artist
"Creative work is not a selfish act or a bid for attention on the part of the actor. It is a gift to the world and every being in it. Don't cheat us of your contribution. Give us what you've got" -- The War of Art: Break Through the Blocks and Win Your Inner Creative Battles by Steven Pressfield.

Mark Joyner

Mark Joyner's Blog: Atomic Mind Bombs (Personal Development Brain Puzzle Cartoons)