From 0129cd78f1516df6d2af2a2eb81b58a039bfb1b5 Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Fri, 17 Feb 2012 22:57:13 +0100 Subject: prefix --- videodb-check.pl | 11 ++++++----- videodb.rc | 4 ++-- videomv.pl | 9 +++++---- videorm.pl | 9 +++++---- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/videodb-check.pl b/videodb-check.pl index 11c5de2..14d58ed 100755 --- a/videodb-check.pl +++ b/videodb-check.pl @@ -24,7 +24,8 @@ my %config = do $confile; die "Error in `" .$confile. "'\n" if $@ || not %config; map { exists $config{$_} || die "Error: Missing `${_}'.\n" } - qw /videodir driver database hostname user port password videodata/; + qw /videodir driver database hostname user port password/; +$config{prefix} = "" unless exists $config{prefix}; my $symlinks = catdir($config{videodir},'MOVIES'); # Symlinks folder die "Error: No such directory: `" .$symlinks. "'.\n" unless -d $symlinks; @@ -105,7 +106,7 @@ e.g., user => 'username', port => 3306, password => '******', - videodata => "videodb_videodata", + prefix => "videodb_", =head1 EXIT STATUS @@ -149,7 +150,7 @@ $dbh->do( "set names utf8" ) or die; # valid target my $r = 0; # Exit status -my $res = $dbh->selectall_arrayref ( "SELECT filename,director FROM $config{videodata}" ) +my $res = $dbh->selectall_arrayref ( "SELECT filename,director FROM $config{prefix}videodata" ) or die "Can't select: " .$dbh->errstr. "\n"; @@ -214,7 +215,7 @@ closedir(DIR) or die "Can't close: $!\n"; undef @files; -my $sth = $dbh->prepare ( "SELECT id FROM $config{videodata} WHERE filename = ?" ) +my $sth = $dbh->prepare ( "SELECT id FROM $config{prefix}videodata WHERE filename = ?" ) or die "Error: " .$dbh->errstr; foreach (@filelist) { $sth->execute ($_) or die "Can't select: " .$dbh->errstr. "\n"; @@ -255,7 +256,7 @@ sub report { sub check { my $bad = $dbh->selectall_arrayref( "SELECT filename - FROM $config{videodata} + FROM $config{prefix}videodata WHERE " .$_[1] ) or die "Can't select: " .$dbh->errstr. "\n"; &report ("The following files have " .$_[0], [map {$_->[0]} @$bad]); diff --git a/videodb.rc b/videodb.rc index 19405b2..a506d6a 100644 --- a/videodb.rc +++ b/videodb.rc @@ -14,7 +14,7 @@ dbi_misc => { mysql_ssl => 1 , mysql_ssl_ca_file => "/etc/ssl/certs/cacert.org.pem" }, password => '******', -videodata => "videodb_videodata", +prefix => 'videodb_', +userid => 1, imdb => 'akas.imdb.com', url => 'https://videodb.example.org', -userid => 1 diff --git a/videomv.pl b/videomv.pl index ddc3357..063ecb3 100755 --- a/videomv.pl +++ b/videomv.pl @@ -29,7 +29,8 @@ my %config = do $confile; die "Error in `" .$confile. "'\n" if $@ || not %config; map { exists $config{$_} || die "Error: Missing `${_}'.\n" } - qw /videodir driver database hostname user port password videodata/; + qw /videodir driver database hostname user port password/; +$config{prefix} = "" unless exists $config{prefix}; my $symlinks = catdir($config{videodir},'MOVIES'); # Symlinks folder die "Error: No such directory: `" .$symlinks. "'.\n" unless -d $symlinks; @@ -310,7 +311,7 @@ e.g., user => 'username', port => 3306, password => '******', - videodata => "videodb_videodata", + prefix => "videodb_", =head1 EXIT STATUS @@ -391,7 +392,7 @@ unless (defined $ignoredb_flag) { # Lookup for the file in the videodb database $RES = - $dbh->selectall_hashref ( "SELECT id,director,title FROM $config{videodata} + $dbh->selectall_hashref ( "SELECT id,director,title FROM $config{prefix}videodata WHERE filename = ?", 'id', undef, $old_filename ) @@ -574,7 +575,7 @@ unless ($r || defined ($ignoredb_flag) || $old_filename eq $new_filename) { &revert(@actions); } else { - my $rv = $dbh->do ( "UPDATE $config{videodata} SET filename = ? WHERE id = ?", + my $rv = $dbh->do ( "UPDATE $config{prefix}videodata SET filename = ? WHERE id = ?", undef, $new_filename, $id ); &ack (\$r, $rv); diff --git a/videorm.pl b/videorm.pl index 04e1e03..b30744d 100755 --- a/videorm.pl +++ b/videorm.pl @@ -29,7 +29,8 @@ my %config = do $confile; die "Error in `" .$confile. "'\n" if $@ || not %config; map { exists $config{$_} || die "Error: Missing `${_}'.\n" } - qw /videodir driver database hostname user port password videodata/; + qw /videodir driver database hostname user port password/; +$config{prefix} = "" unless exists $config{prefix}; my $symlinks = catdir($config{videodir},'MOVIES'); # Symlinks folder die "Error: No such directory: `" .$symlinks. "'.\n" unless -d $symlinks; @@ -112,7 +113,7 @@ e.g., user => 'username', port => 3306, password => '******', - videodata => "videodb_videodata", + prefix => "videodb_", =head1 EXIT STATUS @@ -172,7 +173,7 @@ $dbh->do( "set names utf8" ) or die; # Lookup for the file in the videodb database -my $res = $dbh->selectall_arrayref ( "SELECT id FROM $config{videodata} WHERE filename = ?", +my $res = $dbh->selectall_arrayref ( "SELECT id FROM $config{prefix}videodata WHERE filename = ?", undef, $file ) or die "Can't select: " .$dbh->errstr. "\n"; @@ -184,7 +185,7 @@ die "Error: Your collection is not sane! (and `--force' is not set).\n" my $r = 0; &ack ( "Updating database... ", - $dbh->do ( "DELETE FROM $config{videodata} WHERE filename = ?", undef, $file ) > 0); + $dbh->do ( "DELETE FROM $config{prefix}videodata WHERE filename = ?", undef, $file ) > 0); &ack ( "Deleting symlink... ", -l $file_s && unlink $file_s ); -- cgit v1.2.3