Created
November 24, 2011 08:42
-
-
Save kiyotakagoto/1390914 to your computer and use it in GitHub Desktop.
perl : SQL文を動的に作成するときのちょっとキレイなWHERE句の作り方
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $sql = 'select * from hoge where'; | |
my (@where, @bind); | |
push @where, 'name = ?'; | |
push @bind, 'aiueo'; | |
push @where, 'name = ?'; | |
push @bind, 'kakikukeko'; | |
push @where, 'name = ?'; | |
push @bind, 'sasisuseso'; | |
$sql .= join(' and ', @where); | |
my $dbh = DBI->connect(...); | |
my $sth = $dbh->prepare( $sql ); | |
$sth->execute( @bind ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment