The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

NAME

Teng::Plugin::SearchBySQLAbstractMore::Pager::Count - pager plugin using SQL::AbstractMore. count total entry by count(*)

SYNOPSIS

see Teng::Plugin::SearchBySQLAbstractMore

CAUTION

This solution is bad when you have many records. You re-consider the implementation where you want to use this module. If you are using MySQL, I recommend to use Pager::CountOrMySQLFoundRows or Pager::MySQLFoundRows.

METHODS

search_by_sql_abstract_more_with_pager

search_by_sql_abstract_more with paging feature. additional parameter can be taken, page, rows and hint_columns.

hint_columns

If you pass hint_columns, or -hint_columns as option and select using "GROUP BY", it uses these values as select columns for calculating total count.

For example:

my ($rows, $pager) = $teng->search_by_sql_abstrat_more_with_pager
('clicks',
{},
{-columns => [qw/user_id count(*) date(clicked_datetime)/],
-group_by => [qw/user_id date(clicked_datetime)/],
-rows => 20,
-page => 1,
}
);

It execute the following 2 SQLs.

SELECT COUNT(*) AS cnt FROM (SELECT user_id,DATE(clicked_datetime),COUNT(*) FROM clicks GROUP BY user_id, date(clicked_datetime)) AS total_count;
SELECT user_id, date(clicked_datetime), COUNT(*) FROM clicks GROUP BY user_id, date(clicked_datetime) LIMIT 20 OFFSET 0;

If you pass -hint_columns option.

my ($rows, $pager) = $teng->search_by_sql_abstrat_more_with_pager
('clicks',
{},
{-columns => [qw/user_id count(*) date(clicked_datetime)/],
-group_by => [qw/user_id date(clicked_datetime)/],
-hint_columns => [qw/user_id/],
-rows => 20,
-page => 1,
}
);

It execute the following 2 SQLs.

SELECT COUNT(*) AS cnt FROM (SELECT user_id FROM clicks GROUP BY user_id, date(clicked_datetime)) AS total_count;
SELECT user_id,date(clicked_datetime) FROM clicks GROUP BY user_id, date(clicked_datetime) LIMIT 20 OFFSET 0;

AUTHOR

Ktat, <ktat at cpan.org>

BUGS

Please report any bugs or feature requests to bug-teng-plugin-searchbysqlabstractmore at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Teng-Plugin-SearchBySQLAbstractMore. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Teng::Plugin::SearchBySQLAbstractMore

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2012 Ktat.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.