ColtsFoot has asked for the wisdom of the Perl Monks concerning the following question:
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); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI (Prepare once execute many fails)
by gmax (Abbot) on Jun 06, 2003 at 07:46 UTC | |
by dws (Chancellor) on Jun 06, 2003 at 09:06 UTC | |
|
Re: DBI (Prepare once execute many fails)
by Grygonos (Chaplain) on Jun 06, 2003 at 13:36 UTC | |
|
Re: DBI (Prepare once execute many fails)
by Itatsumaki (Friar) on Jun 06, 2003 at 15:00 UTC | |
by Itatsumaki (Friar) on Jun 06, 2003 at 16:12 UTC | |
by Grygonos (Chaplain) on Jun 06, 2003 at 17:00 UTC | |
by runrig (Abbot) on Jun 06, 2003 at 21:25 UTC | |
by Itatsumaki (Friar) on Jun 06, 2003 at 18:41 UTC |