<a name="mysql_use_result"></a><div><span class="gmail_quote">On 1/22/08, <b class="gmail_sendername">Jesse Vincent</b> &lt;<a href="mailto:jesse@bestpractical.com">jesse@bestpractical.com</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
It _should_ be possible to sink that down into Jifty::DBI, possibly down<br>as far as ::Handle-&gt;simple_query. (Say, trap a failure and retry if you<br>get a not-connected error?) That way you don&#39;t get the overhead of a
<br>ping before each statement.<br><br>-j</blockquote><div><br>Added to Jifty::DBI. Hopefully this will resolve some issues I&#39;m having
with sessions failing to load properly (which happens before the before rules).<br>
<br>
And an FYI regarding some other things I&#39;ve learned through this: As I
was digging around, I found a better way to do this by implementing the
&quot;before_request&quot; trigger. This should not be necessary on the very
latest Jifty::DBI, but could be done from the main application package
as:<br>
<br><span style="font-family: courier new,monospace;">
package MyJiftyApp;</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
sub start {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp; Jifty-&gt;handler-&gt;add_trigger( before_request =&gt; sub { Jifty-&gt;handle-&gt;connect } );</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
}</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
1;</span><br>
<br>
That would be the best way to implement this since session loading
depends on the database and happens before the first before rule is
executed.<br>
<br>
Again, this shouldn&#39;t be necessary if you use the very latest
Jifty::DBI trunk, but in case you can&#39;t yet this is about as good as it gets. It will not help you if your database
connection craps out in the middle of a request, which should be almost
entirely solved by the Jifty::DBI patch, but, hopefully, that is very
rare.<br>
<br>
In addition to this, MySQL users may also want to setup auto-reconnection. In that case, you might re-implement the above as:<br>
<br><span style="font-family: courier new,monospace;">
sub start {</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
&nbsp; Jifty-&gt;handle-&gt;dbh-&gt;{mysq_auto_reconnect} = 1;</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
}</span><br>
<br>
Though, you should be aware of these caveats described in the driver docs: <br>
<br>
<blockquote style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;" class="gmail_quote">Setting
mysql_auto_reconnect to on is not advised if &#39;lock tables&#39; is used
because if DBD::mysql reconnect to mysql all table locks will be lost.
This attribute is ignored when AutoCommit is turned off, and when
AutoCommit is turned off, DBD::mysql will not automatically reconnect
to the server.<br>
</blockquote>
<br>
This does highlight a potential flaw in the reconnect implementation in
Jifty::DBI since it won&#39;t attempt to re-acquire any locks or fail
during reconnection if your application is in the middle of a
non-autocommit transaction. This requires further consideration.<br>
<br>
Cheers,<br>
Andrew <br></div></div>