15 my $class=ref($proto) || $proto;
19 my($dir, $init, $me)=@_;
20 $self->{dbpath}="$dir/$dbfile";
23 my $exists=-f $self->{dbpath};
24 die("$me: $self->{dbpath}: not found. use --init to create.\n") if(!$exists && !$init);
25 die("$me: --init used but $self->{dbpath} exists.\n") if($exists && $init);
27 $self->{dbh}=DBI->connect("dbi:SQLite:dbname=$self->{dbpath}","","",
29 unless(defined($self->{dbh}))
31 die("$me: DB Error: " . $DBI::errstr . "\n");
49 my @schema=split(/\n\n/,join("", <DATA>));
53 $self->{dbh}->do($cmd);
55 $self->cmd("INSERT INTO id3fs (schema_version) VALUES (?)", $SCHEMA_VERSION);
61 my ($version)=$self->cmd_onerow("SELECT schema_version from id3fs");
62 if(!defined($version) || $version != $SCHEMA_VERSION)
64 die("$self->{me}: id3fs database version " .
65 defined($version) ? $version : '""' .
66 "not known, current version is $SCHEMA_VERSION.\n");
72 my($self, $sql, @params)=@_;
73 my $sth=$self->{dbh}->prepare($sql);
75 for my $param (@params)
77 $param="" unless(defined($param));
78 $sth->bind_param($idx++, $param);
87 my $file=ID3FS::File->new($path);
88 return unless(defined($file));
89 my $artist=$file->artist();
90 my $album=$file->album();
91 my $v1genre=$file->v1genre();
92 my $year=$file->year();
93 my $audiotype=$file->album();
95 # my $haspic=$file->haspic();
96 my $tags=$file->tags();
98 for my $thing (qw(artist album v1genre year audiotype))
101 my $thingval=$file->$thing();
103 print("\t$thing: ", $thingval, "\n") if(defined($thingval));
109 my ($self, @args)=@_;
110 # don't care about retcode
111 $self->cmd_sth(@args);
116 my ($self, @args)=@_;
117 my $sth=$self->cmd_sth(@args);
118 return($sth->fetchrow_array());
128 id INTEGER PRIMARY KEY,
133 id INTEGER PRIMARY KEY,
137 CREATE TABLE tagvalues (
138 id INTEGER PRIMARY KEY,
142 CREATE TABLE files_x_tags (
147 CREATE TABLE tags_x_tagvalues (