<?xml version="1.0" encoding="windows-1252"?>
<node id="907862" title="Re^4: DBI, place holders and CGI forms (quote++)" created="2011-06-02 14:25:46" updated="2011-06-02 14:25:46">
<type id="11">
note</type>
<author id="22609">
tye</author>
<data>
<field name="doctext">
&lt;blockquote&gt;&lt;i&gt;
I never use quote myself.
&lt;/i&gt;&lt;/blockquote&gt;&lt;p&gt;
Actually, quote() is the more general solution.  I've run into quite a few different problems trying to use placeholders.  And I've never noticed any performance problem with my failure to re-use prepared queries.  I've actually had more problems due to people being too aggressive about trying to re-use prepared queries such as using prepare_cached() way too much.
&lt;/p&gt;&lt;p&gt;
A significant fraction (perhaps a majority) of the environments where I've done significant DBI work were such that placeholders had no performance impact &lt;em&gt;at all&lt;/em&gt;.  For example, the default with [mod://DBD::mysql] seems to still be to not do server-side prepares.
&lt;/p&gt;&lt;p&gt;
At more than one recent employer I've experienced upgrading [mod://DBD::Pg] such that prepares started happening server-side and then having to disable server-side prepares due to more than one resulting problem (the query planner got significantly stupider in a few important cases, it was incompatible with PgBouncer or other middle-layer tools, and other problems).
&lt;/p&gt;&lt;p&gt;
We had some breakage at PerlMonks because "limit ?" worked fine on older versions of DBD::mysql but then stopped working after some ugprade.
&lt;/p&gt;&lt;p&gt;
And I've had significant problems with placeholders when using DBD::ODBC.  The first batch of problems were around certain data type checking such that "where somedate = '2011-01-01'" is no problem but "where somedate = ?" plus passing '2011-01-01' to execute() gave some "type mismatch" error.
&lt;/p&gt;&lt;p&gt;
The scariest problem was using DBD::ODBC and having "where somedate between cast(? as datetime) and cast(? as datetime)" work without emitting any errors or warnings but then returning &lt;em&gt;the wrong data&lt;/em&gt;.  But, of course:
&lt;/p&gt;&lt;c&gt;
join ' ',
    ...
    "where somedate between", $dbh-&gt;quote($start),
    "and", $dbh-&gt;quote($end),
&lt;/c&gt;&lt;p&gt;
worked exactly as expected (whether "cast( ... as datetime)" was included or not).
&lt;/p&gt;&lt;p&gt;
So, I like being able to use placeholders.  But way too often that actually requires being able to disable server-side prepares which then just boils down to $dbh-&gt;quote() except that the DBD module is doing that call for you (and thus removes your claimed advantage).
&lt;/p&gt;&lt;p&gt;
Actually, the majority of my experience using [mod://DBI] is via some wrapper (quite a few different ones, some extremely thin, some only moderately thin) that takes my column names and column values and assembles at least some of the SQL for me.
&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-22609"&gt;&lt;p align="right"&gt;
- [tye]&lt;tt&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/tt&gt;
&lt;/p&gt;&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
907815</field>
<field name="parent_node">
907835</field>
</data>
</node>
