in reply to DBI using wrong connection

You are preparing two different queries within loops. This can be tricky because some databases don't release the cursor of the query, thus running out of cursors after a while (been there and seen it).
While the loop is inevitable for the first query, you can and should put the second (update) query outside the loop:
my $insert_query = $cdbh->prepare("insert into keyword (zkey, value) v +alues (?, ?)"; while ($csth->fetch) { $query = "select $primarykey, $fieldname from $tablename"; # this sth uses the ODBC $dbh for the first three columns, but # tries to use the SQLite $cdbh for the 4th column my $sth = $::dbh->prepare($query); $sth->execute; my ($key, $value); $sth->bind_columns(\$key, \$value); while ($sth->fetch) { next if !$key; next if !$value; $value = lc($value); my @words = split(/\W/, $value); for (my $i = 0; $i < scalar(@words); $i++) { my $word = $words[$i - 1]; next if !$word; # trim $word =~ s|^ *(.+) *$|$1|; next if !$word; $insert_query->execute("$tablename.$key", $word)";); } } }
Note that using $dbh->quote is not neccessary when you use placeholders. Also note that this is untested.


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: DBI using wrong connection
by Stephen Toney (Sexton) on Sep 05, 2006 at 14:36 UTC
    Holli: Many thanks for the clear reply. You were right about the problem and the solution! Best regards.