Hi everyone, I am having trouble with a simple indexing routine which takes data from an ODBC table and creates an index in a SQLite database. The ODBC and SQLite databases use separate connections, dbh's and sth's.

The routine retrieves all data for a column of the ODBC table, indexes it, and then goes to the next column. It works perfectly on the first three columns of the ODBC table, but then fails on the 4th column with this error:

DBD::SQLite::db do failed: no such table: ISSUE(1) at dbdimp.c line 269

However, the table ISSUE is the ODBC table being indexed. So why was the $sth trying to access this table using the SQLite connection?

Here's the code, with error-handling stuff removed for clarity.
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); } }

In reply to DBI using wrong connection by Stephen Toney

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.