14 my $class=ref($proto) || $proto;
18 my($dir, $init, $me)=@_;
19 $self->{dbpath}="$dir/$dbfile";
22 my $exists=-f $self->{dbpath};
23 die("$me: $self->{dbpath}: not found. use --init to create.\n") if(!$exists && !$init);
24 die("$me: --init used but $self->{dbpath} exists.\n") if($exists && $init);
26 $self->{dbh}=DBI->connect("dbi:SQLite:dbname=$self->{dbpath}","","",
28 unless(defined($self->{dbh}))
30 die("$me: DB Error: " . $DBI::errstr . "\n");
48 my @schema=split(/\n\n/,join("", <DATA>));
52 $self->{dbh}->do($cmd);
54 $self->cmd("INSERT INTO id3fs (schema_version) VALUES (?)", $SCHEMA_VERSION);
60 my ($version)=$self->cmd_onerow("SELECT schema_version from id3fs");
61 if(!defined($version) || $version != $SCHEMA_VERSION)
63 die("$self->{me}: id3fs database version " .
64 defined($version) ? $version : '""' .
65 "not known, current version is $SCHEMA_VERSION.\n");
71 my($self, $sql, @params)=@_;
72 my $sth=$self->{dbh}->prepare($sql);
74 for my $param (@params)
76 $param="" unless(defined($param));
77 $sth->bind_param($idx++, $param);
91 # don't care about retcode
92 $self->cmd_sth(@args);
98 my $sth=$self->cmd_sth(@args);
99 return($sth->fetchrow_array());
109 id INTEGER PRIMARY KEY,
114 id INTEGER PRIMARY KEY,
118 CREATE TABLE tags_x_files (
123 CREATE TABLE v1genres (