title: Perl/MySQL "Query was empty" error, probably multithreading-related
body: <p>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):</p>
  
  <pre><code>$query = "INSERT INTO relations (relation_type_id, confidence) VALUES ($reltypeid, $conf)";
  print "$query\n";
  $result = $conn-&gt;query($query);
  $relid = $result-&gt;insertid();
  ...
  </code></pre>
  
  <p>However, I have noticed random errors pop up during the execution, like this:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>If I run it with <code>perl -w</code>, I get this:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>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 <code>zcat</code>, and these are all the packages that are included:</p>
  
  <pre><code>use Switch;
  use File::Basename;
  </code></pre>
  
  <p>and in an included <code>pm</code>:</p>
  
  <pre><code>use Mysql;
  use Exporter qw(import);
  </code></pre>
  
  <p>Also, I've googled the error message, and I can't get the full hit (name &amp; location). Just the error name ("Query was empty") hit an article where the poster was accessing a connection from two subsequently forked processes.</p>
  
  <p>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 <code>print "---";</code> to separate my record blocks), the errors occur earlier (can't really say if it's on the same byte-count of output or not).</p>
  
  <p>Is there a way to disable multithreading in <code>perl</code>? How do I catch the bugger? What is that error message about?</p>
  
  <p><strong>UPDATE:</strong> The problem was the combination of stdout buffering, misleading Google hit, perl directory name and a major case of brain fart.</p>