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

index d34711af6f9b965e6b926628dd7c150bcb88f3a2..44e38b8be3445d88c2b5b4974c6f62185ae8fb59 100755

--- a/phosta.pl

+++ b/phosta.pl

@@ -15,25 +15,27 @@ use Cwd;

use DBI;

use Getopt::Std;

-my $driver = "SQLite";

-my $database = getcwd . "/photo_stats.db";

-my $dsn = "DBI:$driver:dbname=$database";

$Getopt::Std::STANDARD_HELP_VERSION = 'true';

-my $VERSION = '0.4';

+my $VERSION = '0.5';

my $PROGRAM = 'Photo Stats';

# read commandline switches

+our $opt_d=getcwd . "/photo_stats.db";

our $opt_p='';

our $opt_c=0;

our $opt_q=0;

our $opt_s='';

our $opt_g='';

-getopts('cqp:g:s:') or die "Invalid parameters provided! See 'phosta.pl --help' for more details.";

+getopts('cqp:g:s:d:') or die "Invalid parameters provided! See 'phosta.pl --help' for more details.";

+my $dsn = "DBI:SQLite:dbname=$opt_d";

+

+if ($opt_c) { unlink $opt_d; }

+if ( !-e $opt_d ) { create_db($opt_d) or die 'database could not be created'; }

if ( $opt_p ne '' ) {

- populate_db($opt_p, $opt_c);

+ populate_db($opt_p);

exit 0;

}

@@ -41,17 +43,25 @@ query_db($opt_s, $opt_g);

exit 0;

+sub create_db

+{

+ my ($dbfile) = @_;

+ my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr;

+

+ my $stmt = 'CREATE TABLE photos (file TEXT PRIMARY KEY, maker TEXT, model TEXT, lens TEXT, focallength INTEGER, focallength35mm INTEGER, aperture DECIMAL, exposuretime TEXT, iso INTEGER, flash TEXT, datetimeoriginal DATETIME);';

+ my $rv = $dbh->do($stmt);

+}

+

sub populate_db

{

- my ($destination_dir, $clean) = @_;

+ my ($destination_dir) = @_;

say "Scanning $destination_dir for images...";

-

+

my $cmd = "exiftool -fast2 -r -m -f -p '\$filepath##\$make##\$model##\$lens##\$lensmodel##\$focallength##\$focallengthin35mmformat##\$aperture##\$exposuretime##\$iso##\$flash##\$datetimeoriginal' -d \"%Y-%m-%d %H:%M:%S\" -ext jpg " . $destination_dir;

my @lines = qx($cmd);

my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr;

- if ( $clean ) { $dbh->do('DELETE FROM photos'); }

my $errorcount = 0;

my $emptycount = 0;

foreach (@lines)

@@ -131,7 +141,7 @@

sub query_db

{

my ($selected, $grouping) = @_;

-

+

my $dbh = DBI->connect($dsn, '', '', { RaiseError => 1 }) or die $DBI::errstr;

my $total_count = $dbh->selectrow_array("SELECT count(file) from photos");

@@ -170,6 +180,7 @@ say '';

say 'usage: phosta(.pl) [options]';

say '';

say 'options:';

+ say ' -d <file> : path and name of the db file to use';

say ' -p <folder> : populate database from the files in the specified folder';

say ' -c : clear the database before populating with data from the folder';

say ' -g : (query mode) group by time range, defaults to total (which means no grouping by time range)';