Re: [htmltmpl] [Question] H::T and DBI => stuffing query info into <TMPL_LOOP>'s
Brought to you by:
samtregar
From: Puneet K. <pk...@ei...> - 2004-04-14 00:18:10
|
On Apr 13, 2004, at 6:21 PM, Mathew Robertson wrote: >>> I can get the results to print directly with this code: >>> >>> $sth = $dbh->prepare ("SELECT * FROM $working_tbl WHERE first='one' >>> ORDER BY Location"); >>> $sth->execute (); >>> while ( my $hash_ref = $sth->fetchrow_hashref ) { >>> print "ID: $hash_ref->{'ID'} -- Name: $hash_ref->{'Name'} >>> (etc....) <br>\n"; >>> } > >> this is cool, but do note that the DBI docs generally advise against >> the >> use of a variable table name (well... I understand them to be advising >> against) as it doesn't allow for creating a plan and optimizing the >> query. Anyway... > > What has Perl's string interpolation got to do with DBI? > > "SELECT * FROM $working_tbl WHERE first='one' ORDER BY Location" > > The variable $working_tbl will be interpolated by Perl, long before > DBI ever gets to see the SQL statement, due to the double-quote. > > you are correct, and my advise was half-baked. The assertion I made holds true when doing multiple queries using bind variables, and hence, I try to stay away from variable-izing table names... that is where my advise came from and it really doesn't apply to Carl's case. But, as they say... you gotta do what you gotta do. |