<div dir="ltr">SQL is  just text so generating it is pretty easy.  For insert statements I sometimes craft lines like this:<div><br></div><div>    use Modern::Perl;</div><div>    my @fields = qw(TIMESTAMP KEY VALUE);</div>
<div>    my $insert = "insert into table ("</div><div>                         .  join(", ", @fields)</div><div>                         . ") values ("</div><div>                         . join( ", ", ("?")x@fields)</div>
<div>                         . ")";</div><div>    say $insert</div><div><br></div><div><br></div><div>There are also LOADS of SQL modules on CPAN.   </div><div>One of my favorite for mucking about with plain old SQL is SQL::Abstract</div>
<div><br></div><div><div>    use Modern::Perl;</div><div>    use SQL::Abstract;</div><div><br></div><div>    my $sql = SQL::Abstract->new;</div><div><br></div><div>    my %fields = (</div><div>        TIMESTAMP => scalar gmtime,</div>
<div>        KEY => rand(),</div><div>        VALUE => "some value",</div><div>    );</div><div><br></div><div>    my ($insert, @bind) = $sql->insert('table', \%fields);</div><div><br></div><div>
    say $insert. "\n";</div><div>    say for (@bind);</div></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jul 1, 2014 at 4:49 PM, deandre <span dir="ltr"><<a href="mailto:deandre@deandrecarroll.com" target="_blank">deandre@deandrecarroll.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>If I understand your problem correctly, this is the type of work for which prepared statements are created.</div>
<div><br></div><div><br></div><div>$ sth = $ dbh-> prepare ("insert into table ( TIMESTAMP, KEY, VALUE ) values ( ?,?,? )";</div><div><br></div><div>$ sth-> execute($Timestamp, $Key, $Value);</div><div><br>
</div><div>Values passed to execute are escaped, thus preventing possible sales injection. Plus the statement handle goes through a sort of compilation making repeated use (by adding new values to the execute) much faster.</div>
<div><br></div><div><div style="font-size:9px;color:#575757">Sent on a Sprint Samsung Galaxy S® III</div></div><div class=""><br><br><div>-------- Original message --------</div><div>From: "Robert L. Harris" <u></u> </div>
<div>Date:07/01/2014  4:22 PM  (GMT-07:00) </div><div>To: <a href="mailto:Denver-pm@pm.org" target="_blank">Denver-pm@pm.org</a> </div><div>Subject: [Denver-pm] Better way to handle vars? </div><div><br></div><div dir="ltr">
<div><br></div>OK, so I'm parsing a ton of data based on patterns in the lines.  Given the line I pull out 3 things,<div>Timestamp</div><div>Key</div><div>Value</div><div><br></div><div>Right now for one of my patters I have </div>


<div><br></div><div>$Insert="insert into table ( TIMESTAMP, KEY, VALUE ) values ( $Timestamp, $Key, $Value )";</div><div><br></div><div>( effectively ).</div><div><br></div><div>I'm going to have about 20+ of these patterns.  The actual insert is about 5x longer.  Is there a way to "template" the Insert so I can basically reference the template in the pattern and re-use the template?  That way if the template has to change down the line ( a new field added ) I update the template and not 20+ variables?</div>


<div><br></div><div>Robert</div><div><br clear="all"><div><br></div>-- <br>:wq!<br>---------------------------------------------------------------------------<br>Robert L. Harris<br><br>DISCLAIMER:<br>      These are MY OPINIONS             With Dreams To Be A King,<br>


       ALONE.  I speak for                      First One Should Be A Man<br>       no-one else.                                     - Manowar
</div></div>
</div></div><br>_______________________________________________<br>
Denver-pm mailing list<br>
<a href="mailto:Denver-pm@pm.org">Denver-pm@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/denver-pm" target="_blank">http://mail.pm.org/mailman/listinfo/denver-pm</a><br>
<br></blockquote></div><br></div>