Class::DBI的应用问题
## Class::DBI ##################################
__PACKAGE__->set_sql(get_count => qq{
SELECT
count(*)
FROM
__TABLE__
%s
});
利用上述格式、把下述的SQL条件动态替换进去、求写段函数
## SQL文 ########################################
SELECT *
FROM users
WHERE (last_name='姓' AND first_name='名')
OR phone='1122223'
OR mail_address='me@aaa.cn'
[解决办法]
$where->{'-or'} = [ {'-and' => [ {last_name => "姓"},
{first_name => "名"} ]},
{phone => "1122223"}
];
若要把 mail_address='me@aaa.cn'
追加到上述数据结构里,该如何写?
也就是说,实现上述数据结构,如何分开添加?
[解决办法]
my $where=[];
push( @$where, {'-and' => [ {last_name => "姓"},
{first_name => "名"}
]} );
push( @$where, { phone => "1122223" } );
push( @$where, { mail_address => 'me@aaa.cn' } );
my ( $users_count ) = Data::users->count( $where, { logic => 'OR' } );
print "users_count: ". $users_count, "\n";
”自摸”! 解了,谁进来就给分~