[Denver-pm] Better way to handle vars?

deandre deandre at deandrecarroll.com
Tue Jul 1 15:49:53 PDT 2014


If I understand your problem correctly, this is the type of work for which prepared statements are created.


$ sth = $ dbh-> prepare ("insert into table ( TIMESTAMP, KEY, VALUE ) values ( ?,?,? )";

$ sth-> execute($Timestamp, $Key, $Value);

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.

Sent on a Sprint Samsung Galaxy S® III

<div>-------- Original message --------</div><div>From: "Robert L. Harris" <robert.l.harris at gmail.com> </div><div>Date:07/01/2014  4:22 PM  (GMT-07:00) </div><div>To: Denver-pm at pm.org </div><div>Subject: [Denver-pm] Better way to handle vars? </div><div>
</div>
OK, so I'm parsing a ton of data based on patterns in the lines.  Given the line I pull out 3 things,
Timestamp
Key
Value

Right now for one of my patters I have 

$Insert="insert into table ( TIMESTAMP, KEY, VALUE ) values ( $Timestamp, $Key, $Value )";

( effectively ).

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?

Robert


-- 
:wq!
---------------------------------------------------------------------------
Robert L. Harris

DISCLAIMER:
      These are MY OPINIONS             With Dreams To Be A King,
       ALONE.  I speak for                      First One Should Be A Man
       no-one else.                                     - Manowar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/pipermail/denver-pm/attachments/20140701/02bdc03a/attachment.html>


More information about the Denver-pm mailing list