1package OpenXPKI::Server::Database::Role::CountEmulation; 2use Moose::Role; 3use utf8; 4=head1 Name 5 6OpenXPKI::Server::Database::Role::CountEmulation - Moose role for database 7drivers to emulate row count with a subselect 8 9=cut 10 11sub count_rows { 12 my ($self, $dbi, $query) = @_; 13 14 $query->string(sprintf "SELECT COUNT(*) as amount FROM (%s) as tmp", $query->string); 15 16 my $sth = $dbi->run($query); 17 return $sth->fetchrow_hashref->{amount}; 18} 19 201; 21 22__END__; 23 24=head1 Description 25 26This is the default implementation to count the number of rows in a select 27by using SELECT COUNT(*) from (...) as tmp 28 29It might be overriden if the specifica RDBMS requires a different syntax 30(e.g. Oracle) or there is a builtin method. 31