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 6a7052b62533d69b7156e285de54aee3b58d0911
parent c760785dbb24b624f6c68ce42789f3ec3a45af5f
Author: René Wagner <rwagner@rw-net.de>
Date:   Sat, 15 Aug 2020 19:17:26 +0200

optional limit for resultset

Diffstat:
Mphosta.pl | 26+++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)

diff --git a/phosta.pl b/phosta.pl @@ -33,10 +33,11 @@ our $opt_c=0; our $opt_s=''; our $opt_g=''; our $opt_v=0; +our $opt_n=undef; getconfig($configfile); -getopts('vcp:g:s:t:D:E:') or die "Invalid parameters provided! See 'phosta --help' for more details."; +getopts('vcp:n:g:s:t:D:E:') or die "Invalid parameters provided! See 'phosta --help' for more details."; validate() or die "Invalid parameters provided! See 'phosta --help' for more details."; my $dsn = "DBI:SQLite:dbname=$opt_D"; @@ -65,6 +66,8 @@ sub validate if ( ! ($_ ~~ @select_params) ) { return 0; } } + if (defined($opt_n) && (!looks_like_number($opt_n) || $opt_n < 1)) { return 0; } + if ($opt_t ne '' && $opt_t !~ /^([0-9]{8}){0,1}\-([0-9]{8}){0,1}$/) { return 0; } if ($opt_E !~ /^([a-z]{2,4}){1,}(\,[a-z]{2,4}){0,}$/) { return 0; } @@ -217,7 +220,10 @@ sub get_sql sub query_db { my ($selected, $grouping) = @_; - + + my $currentlines=0; + my $skippedlines=0; + my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr; my $total_count = $dbh->selectrow_array("SELECT count(file) from photos"); @@ -231,12 +237,21 @@ sub query_db $stmt->execute(); while (my @row = $stmt->fetchrow_array) { - $tb->row(@row); + if (!defined($opt_n) || ($currentlines < $opt_n)) + { + $tb->row(@row); + $currentlines++; + } + else + { + $skippedlines++; + } } - + $tb->captions($stmt->{NAME}); - say $tb->draw; $dbh->disconnect(); + if (defined($opt_n)) { say "Showing top $currentlines results, skipping $skippedlines." } + say $tb->draw; } sub main::VERSION_MESSAGE() @@ -277,4 +292,5 @@ sub main::HELP_MESSAGE say ' multiple fields should be listed comma-separated'; say ' -t <range> : only take images into account which have been taken in the given timerange'; say ' <range> must be specified as \'YYYYMMDD-YYYYMMDD\', you can omit one value'; + say ' -n <number> : limit the resultset to <number> of lines'; }