diff --git a/phosta.pl b/phosta.pl

index db891a7da49dd22f25a1ff5a44ace6cb7727b87b..a74c38e2f791bc4936b19e4b5e7d821fc1e9fe85 100755

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

@@ -64,6 +65,8 @@ foreach (split (/,/, $opt_s))

{

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

@@ -217,7 +220,10 @@

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 @@ my $stmt = $dbh->prepare(get_sql($selected, $grouping));

$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});

+ $dbh->disconnect();

+ if (defined($opt_n)) { say "Showing top $currentlines results, skipping $skippedlines." }

say $tb->draw;

- $dbh->disconnect();

}

sub main::VERSION_MESSAGE()

@@ -277,4 +292,5 @@ say ' allowed values: maker, model, lensmake, lens, aperture, exposuretime, iso, focallength, focallength35mm';

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

}