I don't know if the word "variadic" is the right word, but I'm talking about things that can take a list of values, like IN() . If you have been working with DBI for a long time, you probably tried to do this:
(Note: all examples are extremely simplified for brevity)
my $vals = join ', ', @numbers; my $sth = $dbh->prepare( "SELECT * FROM mytbl WHERE foo IN( ? )" ); $sth->execute( $vals );
DBI deputies simply do not support these types of frauds, is this the only value for everyone ? or nothing as far as I know.
This leads me to doing something like:
my $sth = $dbh->prepare( "SELECT * FROM mytbl WHERE foo IN ( $vals )" );
which is not so terrible, but consider a function, as I wrote today, which should accept some arbitrary SQL with an IN clause and a list of values
sub example { my $self = shift; my ( $sql, @args ) = @_; my $vals = join ', ', @args; $sql =~ s/XXX/$vals/; <----
The result is a callable material that looks like
my $sql = "SELECT * FROM mytbl WHERE foo IN( XXX ) AND bar = 42 ORDER BY baz"; my $result = $self->example( $sql, @quux );
It really offends my sense of aesthetics. Building custom SQL programmatically is a big pain, as it is; I do not want to go the way of regular expression of SQL strings if I do not need it.
Is there a better way?