1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#! /usr/bin/perl -w
# This program is free software. It comes without any warranty, to the
# extent permitted by applicable law. You can redistribute it and/or
# modify it under the terms of the Do What The Fuck You Want To Public
# License, Version 2, as published by Sam Hocevar.
# See http://sam.zoy.org/wtfpl/COPYING for more details.
use Getopt::Long qw(:config posix_default no_ignore_case gnu_compat
bundling auto_version auto_help);
use DBI;
use strict;
# Database
my $driver = "mysql";
my $database = "videodb";
my $hostname = "127.0.0.1";
my $user = "videodb";
my $port = 3306;
my $password = "videodb";
my $videodata = "videodb_videodata";
################################################################################
# Connect to database
my $dsn = "DBI:$driver:database=$database;host=$hostname;port=$port";
my $dbh = DBI->connect($dsn, $user, $password)
or die "Failed to connect; have you tried `mktunnel --sql' first?";
# Use utf8
$dbh->do( "set names utf8" ) or die;
my ($from, $to) = @ARGV;
my $RES =
$dbh->selectall_hashref ( "SELECT id,title,director FROM $videodata
WHERE filename = ?",
'id', undef, $from
)
or die "Can't select: " . $dbh->errstr;
my $nRES = scalar (keys %$RES);
if ($nRES == 0) {
print STDERR "No entry found in the database: nothing to update there.\n";
}
elsif ($nRES > 1) {
print STDERR "$nRES > 1 entries found in the database: dunno what to update there.\n";
}
else {
my ($id,$v) = each %$RES;
print STDERR "Update filename for " . $v->{director} .
" - " . $v->{title} . ":\n";
print STDERR "`" . $from . "' -> `" . $to, "'\n";
$dbh->do ( "UPDATE $videodata SET filename = ? WHERE id = ?",
undef, $to, $id
)
or die "Can't update: " . $dbh->errstr;
}
# Disconnect
$dbh->disconnect();
|