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.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.