Stephen Toney has asked for the wisdom of the Perl Monks concerning the following question:
use DBI; # connection to ODBC database $::dbh = DBI->connect("dbi:ODBC:$::dsn"); # second connection for SQLite control database $datpath = "d:/mwa/uni/spt/mwebxml.dat"; $::cdbh = DBI->connect("dbi:SQLite:$datpath"); my $query = "select f.tablename, f.fieldname, " . " t.primarykey" . " from mwebfield f, mwebtable t" . " where f.tablename=t.tablename"; # control sth uses control dbh (SQLite) my $csth = $::cdbh->prepare($query); $csth->execute; my ($tablename, $fieldname, $primarykey); $csth->bind_columns(\$tablename, \$fieldname, \$primarykey); 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; $word = $::cdbh->quote($word); $query = "insert into keyword (zkey, value)" . " values ('$tablename.$key', $word)"; $::cdbh->do($query); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI using wrong connection
by holli (Abbot) on Sep 05, 2006 at 13:46 UTC | |
by Stephen Toney (Sexton) on Sep 05, 2006 at 14:36 UTC |