首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

Class:DBI的应用有关问题

2012-12-25 
Class::DBI的应用问题## Class::DBI ##################################__PACKAGE__-set_sql(get_count

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";

”自摸”! 解決了,谁进来就给分~

热点排行