Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Not using them means that you have to recreate the query execution plan each time. You get better performance by using them.

    You might want to have a look at Tim Bunce's Advanced DBI talk [gtsm.com]

    -Dom

    • Not using them means that you have to recreate the query execution plan each time.

      Actually, my code generates SQL with positional parameters. It takes a pseudo-SQL template like this:
      SELECT foo
        FROM bar
        WHERE baz = $baz
         AND qux = $qux
      And turns it into this:
      SELECT foo
        FROM bar
        WHERE baz = ?
         AND qux = ?
      Simultaneously taking the name-based parameters that you provide (in a hash, i.e., unordered) and lining their values up in the correct order in a params array:
      $tmpl = SQL::Template->new($template_string);
      ($sql, @params) = $tmpl->process(
          'qux' => 'quaint',
          'baz' => 'baboon'
      );
      The result is:
      $sql = ...as above...
      @params = ('baboon', 'quaint')
      Which you can then use normally:
      $sth = $dbh->prepare[_cached]($sql);
      $sth->execute(@params);
      Oh, and thanks for the tip on Tim Bunce's slides!