in reply to Re: Fast Building of SQL Statements
in thread Fast Building of SQL Statements

++. This is the best one, for my money.

Very readable, and probably could be pulled out to a general sub which generates the run_insert sub for you. Nice use of a closure as well. I like this a lot as its a piece of code I have written badly over and over.

(Rushing back to work after lunch, so not doing it myself (yet).)

  • Comment on Re: Re: Fast Building of SQL Statements

Replies are listed 'Best First'.
Re^3: Fast Building of SQL Statements
by Aristotle (Chancellor) on Aug 28, 2003 at 12:59 UTC
    Yep, that's easy.
    sub make_insert_func { my @PLACEHOLDERS = ('?') x @_; local $" = ','; my $SQL = "INSERT (@_) INTO foo VALUES (@PLACEHOLDERS)"; return sub { my $dbh = shift || return; my $sth = $dbh->prepare($SQL); $sth->execute(@_); $sth->finish; } }

    Makeshifts last the longest.