<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7650.28">
<TITLE>RE: SPUG: BD::mysql::st execute failed:</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Generally speaking,<BR>
If you use placeholders, the driver will use db bind variables and the db will be able to cache the statement and avoid reparsing on each execution.<BR>
If you don't use placeholders, particularly in a loop, you'll pollute the db's statement cache.<BR>
<BR>
On the other hand, the statement analyzer will determine the execution plan BEFORE the vars are bound, so<BR>
it won't have the benefit of knowing the value and will assume the worst.<BR>
This becomes an issue with statements like:<BR>
<BR>
&nbsp; where foo_col LIKE ?<BR>
<BR>
(if the bind-var is 'foo%', for example, an index on foo_col will likely be very useful, but if the bind-var is '%foo', for example, the index will be useless)<BR>
<BR>
YMMV depending on the db, db version and driver.<BR>
<BR>
<BR>
-----Original Message-----<BR>
From: spug-list-bounces+aeh=akc.org@pm.org on behalf of Peter Darley<BR>
Sent: Wed 9/27/2006 11:20 AM<BR>
To: Jacinta Richardson; spug-list@pm.org<BR>
Cc: luis medrano<BR>
Subject: Re: SPUG: BD::mysql::st execute failed:<BR>
<BR>
Jacinta,<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I don't agree.&nbsp; Anything that hides the actual SQL statement is bad bad<BR>
bad.&nbsp; If there wasn't an alternative it would be worth putting up with the<BR>
place holders, but since you can get the same protection without hiding the<BR>
exact query, I don't think it's a very good practice.&nbsp; Things like<BR>
SQL::Abstract make me cringe. :)<BR>
<BR>
Thanks,<BR>
Peter<BR>
<BR>
-----Original Message-----<BR>
From: spug-list-bounces+pdarley=kinesis-cem.com@pm.org<BR>
[<A HREF="mailto:spug-list-bounces+pdarley=kinesis-cem.com@pm.org">mailto:spug-list-bounces+pdarley=kinesis-cem.com@pm.org</A>]On Behalf Of<BR>
Jacinta Richardson<BR>
Sent: Saturday, September 23, 2006 6:45 PM<BR>
To: spug-list@pm.org<BR>
Cc: luis medrano<BR>
Subject: Re: SPUG: BD::mysql::st execute failed:<BR>
<BR>
<BR>
Peter Darley wrote:<BR>
<BR>
&gt; $Query = &quot;INSERT INTO HTML_Pages (Page_ID, Type, Entity, Name, Title,<BR>
&gt; Content) VALUES (&quot; . Quote($Args{PageID}) . &quot;, &quot; . Quote($Args{Type}) . &quot;,<BR>
&quot;<BR>
&gt; . Quote($Args{Entity}) . &quot;, &quot; . Quote($Args{Name}) . &quot;, &quot; .<BR>
&gt; Quote($Args{Title}) . &quot;, &quot; . Quote($Args{Content}) . &quot;)&quot;;<BR>
&gt;<BR>
&gt; $Neo::DB::Shopper-&gt;do($Query) || die &quot;Bad Query!\n\t$Query&quot;;<BR>
<BR>
It's still a better solution to use placeholders:<BR>
<BR>
my @values = ($post_author, $post_date, $post_date_gmt, &quot;@post_content&quot;,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $post_title, $post_status, $comment_status, $ping_status, $post_name,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $post_modified, $post_modified_gmt, $guid);<BR>
<BR>
my $sth1 = $dbh-&gt;prepare(&quot;INSERT INTO wp_posts (post_author, post_date,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post_date_gmt, post_content, post_title, post_status,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; comment_status, ping_status, post_name, post_modified,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post_modified_gmt, guid)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)&quot;)<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or die $dbh-&gt;errstr;<BR>
<BR>
my $rv1 = $sth-&gt;execute(@values);<BR>
<BR>
<BR>
As it says in the documentation, using place holders allows the database<BR>
engine<BR>
to be more efficient as well as ensuring that your values are properly<BR>
quoted<BR>
for whichever database engine you are using (and if your underlying database<BR>
engine changes, then that's handled too!<BR>
<BR>
You may also find it useful to look into SQL::Abstract as it makes these<BR>
large<BR>
inserts and updates much easier.&nbsp; Of course there's always<BR>
Class::DBI/DBIx::Class if you want to take it a step further than that too.<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my %fieldvars = (<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post_author =&gt; $post_author,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; post_date&nbsp;&nbsp; =&gt; $post_date,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; guid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; $guid,<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; );<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use SQL::Abstract;<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $sql = SQL::Abstract-&gt;new;<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my($stmt, @bind) = $sql-&gt;insert(&quot;wp_posts&quot;, \%fieldvals);<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; my $sth = $dbh-&gt;prepare($stmt);<BR>
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; $sth-&gt;execute(@bind);<BR>
<BR>
All the best,<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Jacinta<BR>
<BR>
--<BR>
&nbsp;&nbsp; (&quot;`-''-/&quot;).___..--''&quot;`-._&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp; Jacinta Richardson&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>
&nbsp;&nbsp;&nbsp; `6_ 6&nbsp; )&nbsp;&nbsp; `-.&nbsp; (&nbsp;&nbsp;&nbsp;&nbsp; ).`-.__.`)&nbsp; |&nbsp; Perl Training Australia&nbsp;&nbsp;&nbsp; |<BR>
&nbsp;&nbsp;&nbsp; (_Y_.)'&nbsp; ._&nbsp;&nbsp; )&nbsp; `._ `. ``-..-'&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +61 3 9354 6001&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |<BR>
&nbsp; _..`--'_..-_/&nbsp; /--'_.' ,'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | contact@perltraining.com.au |<BR>
&nbsp;(il),-''&nbsp; (li),'&nbsp; ((!.-'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp; www.perltraining.com.au&nbsp;&nbsp; |<BR>
_____________________________________________________________<BR>
Seattle Perl Users Group Mailing List<BR>
&nbsp;&nbsp;&nbsp;&nbsp; POST TO: spug-list@pm.org<BR>
SUBSCRIPTION: <A HREF="http://mail.pm.org/mailman/listinfo/spug-list">http://mail.pm.org/mailman/listinfo/spug-list</A><BR>
&nbsp;&nbsp;&nbsp; MEETINGS: 3rd Tuesdays<BR>
&nbsp;&nbsp;&nbsp; WEB PAGE: <A HREF="http://seattleperl.org/">http://seattleperl.org/</A><BR>
<BR>
_____________________________________________________________<BR>
Seattle Perl Users Group Mailing List&nbsp;<BR>
&nbsp;&nbsp;&nbsp;&nbsp; POST TO: spug-list@pm.org<BR>
SUBSCRIPTION: <A HREF="http://mail.pm.org/mailman/listinfo/spug-list">http://mail.pm.org/mailman/listinfo/spug-list</A><BR>
&nbsp;&nbsp;&nbsp; MEETINGS: 3rd Tuesdays<BR>
&nbsp;&nbsp;&nbsp; WEB PAGE: <A HREF="http://seattleperl.org/">http://seattleperl.org/</A><BR>
<BR>
<BR>
<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>