If I prepare the statement inside the loop all is fineDBD::ODBC::st execute failed: [iODBC][Driver Manager]Invalid cursor st +ate (SQL-24000)(DBD: st_execute/SQLExecute err=-1) at ./addstuname.pl + line 21, <INPUT> chunk 2014. [iODBC][Driver Manager]Invalid cursor state (SQL-24000)(DBD: st_execut +e/SQLExecute err=-1) at ./addstuname.pl line 21, <INPUT> chunk 2014.
Any ideas would be most welcome.#!/usr/bin/perl #use strict; use DBI; my $dbh = DBI->connect('dbi:ODBC:MY_DB') or die (DBI->errstr()); open INPUT, '/tmp/records.asc'; my $query = qq(select b from c where a = ?); # # Preparing here causes an error! # #my $sth = $dbh->prepare($query) # or die ($dbh->errstr()); while (my $rec = <INPUT>) { chomp($rec); my @items = split(',', $rec); my $a = $items[6]; $a =~ s/#//; if ($items[7] eq '') { # If I prepare each time it works! # my $sth = $dbh->prepare($query) or die ($dbh->errstr()); $sth->execute($a) or die ($dbh->errstr()); my $b = $sth->fetchrow_array(); print qq(Name:$b missing\n); } }
In reply to DBI (Prepare once execute many fails) by ColtsFoot
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |