photo-stats

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/photo-stats.git
Log | Files | Refs | README | LICENSE

commit c5e8f551120eba6cbb43de47421c7c6c272d31d8
parent bc2aa306c82d6a2d24524a6746783072bc50a3e6
Author: René Wagner <rwagner@rw-net.de>
Date:   Fri, 14 Aug 2020 12:04:51 +0200

implement sorting of output

* none -> no sort
* grouping -> time stamp desc (newest first)
* selected fields -> by usage desc (most used first)
* selected fields & grouping -> by time stamp desc, usage desc

Diffstat:
Mphosta.pl | 22++++++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/phosta.pl b/phosta.pl @@ -25,7 +25,7 @@ my $password = ""; $Getopt::Std::STANDARD_HELP_VERSION = 'true'; -my $VERSION = '0.3'; +my $VERSION = '0.4'; my $PROGRAM = 'Photo Stats'; # read commandline switches @@ -85,6 +85,7 @@ sub get_sql my $fieldlist = ''; my $grouplist = ''; + my $orderlist = ''; given ($grouping) { when ('month') @@ -110,9 +111,26 @@ sub get_sql $grouplist = $grouplist . ($grouplist ne '' ? ',' : '') . $selected; } + if ($selected ne '') + { + my $lastcolumn = $selected =~ tr/,//; + $lastcolumn += 2; + $orderlist = 'ORDER BY '; + if ($grouping ne '') + { + $orderlist = $orderlist . ' 1 DESC,'; + $lastcolumn++; + } + $orderlist = $orderlist . " $lastcolumn DESC"; + } + elsif ($grouping ne '') + { + $orderlist = 'ORDER BY 1 DESC'; + } + if ( $grouplist ne '' ) { $grouplist = 'GROUP BY '. $grouplist; } - return qq/SELECT $fieldlist count(file) as photo_count FROM photos $grouplist ORDER BY 1 DESC/; + return "SELECT $fieldlist count(file) as count FROM photos $grouplist $orderlist"; } sub query_db