<?xml version="1.0" encoding="windows-1252"?>
<node id="914782" title="Mysql handle not in asynchronous mode" created="2011-07-15 22:58:30" updated="2011-07-15 22:58:30">
<type id="115">
perlquestion</type>
<author id="231169">
punkish</author>
<data>
<field name="doctext">
I asked this question on the dbi list (no response yet), so am posting it here for collective wisdom of the monks.
&lt;p&gt;
I have three MySQL/Perl Dancer [http://perldancer.org] powered web apps.
&lt;p&gt;
The user goes to app A which serves up a Google maps base layer. On document ready, app A makes three jQuery ajax calls -- two to app B like so
&lt;p&gt;
&lt;code&gt;
        http://app_B/points.json
        http://app_B/polys.json
&lt;/code&gt;
&lt;p&gt;
and one to app C
&lt;p&gt;
&lt;code&gt;
        http://app_C/polys.json
&lt;/code&gt;
&lt;p&gt;
Apps B and C query the MySQL database via DBI, and serve up json packets of points and polys that are rendered in the user's browser.
&lt;p&gt;
All three apps are proxies through Apache to Perl Starman running via plackup started like so
&lt;p&gt;
&lt;code&gt;
     $ plackup -E production -s Starman -w 10 -p &lt;port&gt; path/to/respective/app.pl
&lt;/code&gt;
&lt;p&gt;
From time to time, I start getting errors back from the apps called via Ajax. The initial 
symptoms were
&lt;p&gt;
&lt;code&gt;
        {"error":"Warning caught during route execution: DBD::mysql::st 
        fetchall_arrayref failed: fetch() without execute() at &lt;path/to/app.pm&gt; line 
        79.\n"}
&lt;/code&gt;
&lt;p&gt;
The offending lines are
&lt;p&gt;
&lt;code&gt;
        71&gt; my $sql = qq{
        72&gt;     ..
        73&gt;
        74&gt;
        75&gt; };
        76&gt; 
        77&gt; my $sth = $dbh-&gt;prepare($sql);
        78&gt; $sth-&gt;execute();
        79&gt; my $res = $sth-&gt;fetchall_arrayref({});
&lt;/code&gt;
&lt;p&gt;
This is bizarre... how can execute() not take place above? Perl doesn't have a 
habit of jumping over lines, does it? So, I turned on DBI_TRACE
&lt;p&gt;
&lt;code&gt;
        $DBI_TRACE=2=logs/dbi.log plackup -E production -p 5001 -s Starman -w 
10 -a bin/app.pl
&lt;/code&gt;
&lt;p&gt;
And, following is what stood out to me as the potential culprit in the log file
&lt;p&gt;
&lt;code&gt;
        &gt; Handle is not in asynchronous mode error 2000 recorded: Handle is 
        &gt; not in asynchronous mode
        &gt;    !! ERROR: 2000 CLEARED by call to fetch method
&lt;/code&gt;
&lt;p&gt;
What is going on? Basically, as is, app A is non-functional because the other apps don't return data "reliably" -- I put that in quotes because they do work correctly occasionally, so I know I don't have any logic or syntax errors in my code. I have some kind of intrinsic plumbing errors.
&lt;p&gt;
quick update: I did find the following [http://search.cpan.org/~capttofu/DBD-mysql-4.019/lib/DBD/mysql.pm#ASYNCHRONOUS_QUERIES] and am wondering if this is the cause and the solution of my problem. Would a DBI/mysql savvy monk kindly elucidate?

 

&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-231169"&gt;
&lt;br&gt;&lt;br&gt;&lt;i&gt;
when small people start casting long shadows, it is time to go to bed&lt;/i&gt;
&lt;/div&gt;&lt;/div&gt;</field>
</data>
</node>
