开发者

Perl/MySQL "Query was empty" error, probably multithreading-related

I am writing a program to extract data from a bunch of text files and stuff it into DB. All of my commands currently have the form similar to this (with different queries):

$query = "INSERT INTO relations (relation_type_id, confidence) VALUES ($reltypeid, $conf)";
print "$query\n";
$result = $conn->query($query);
$relid = $result->insertid();
...

However, I have noticed random errors pop up during the execution, like this:

INSERT INTO relations (relatiDBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
DBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
on_type_id, confidence) VALUES (12, 0.709310711263845)

If I run it with perl -w, I get this:

INSERT INTO relations (relatiUse of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/DBD/mysql.pm line 211.
Use of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
DBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
Use of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/DBD/mysql.pm line 211.
Use of uninitialized value in subroutine entry at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
DBD::mysql::st execute failed: Query was empty at /usr/lib64/perl5/vendor_perl/5.8.5/x86_64-linux-thread-multi/Mysql.pm line 175.
on_type_id, confidence) VALUES (12, 0.709310711263845)

Now what worries me is that clearly some multithreading crap is going on - the program does not die, and the error is inserted in the middle of a print - and I have no clue how to debug it. For the record, I myself am not forking or threading anywhere except backticking zcat, and these are all the packages that are included:

use Switch;
use File::Basename;

and in an included pm:

use Mysql;
use Exporter qw(import);

Also, I've googled the error message, and I can't get the full hit (name & location). Just the error name ("Query was empty") hit an article where the poster was accessing a connection from two subsequently forked processes.

One more thing of note: the phenomenon is deterministic. The errors always appear in the same place, as long as the code is intact. If I change the output (for instance, insert some marker lines like print "---"; to separate my record blocks), the errors occur earlier (can't really say if it's on the s开发者_运维知识库ame byte-count of output or not).

Is there a way to disable multithreading in perl? How do I catch the bugger? What is that error message about?

UPDATE: The problem was the combination of stdout buffering, misleading Google hit, perl directory name and a major case of brain fart.


Please post the whole Perl program.

Nothing I see here makes me think that this is a multithreading issue. Unless you're asking for threads somewhere, you aren't getting multiple threads in Perl5.

As a wild guess, due to the extra print statements changing the results it feels like a buffering issue. Try hotting your STDOUT with $|=1;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜