15 my $class=ref($proto) || $proto;
20 $self->{verbose}=shift;
24 my $fallbackdir=shift;
26 $dbpath=$self->find_db($init, $dbpath, $fallbackdir);
27 return undef unless($dbpath);
28 $self->{absbase}=Cwd::abs_path($self->{base});
30 my $connectstr="dbi:SQLite:dbname=$dbpath";
31 my ($user, $pass)=("", "");
34 $connectstr="dbi:Pg:dbname=id3fs";
38 my $exists=-f $dbpath;
39 $self->{dbh}=DBI->connect($connectstr, $user, $pass,
41 unless(defined($self->{dbh}))
43 die("$self->{me}: DB Error: " . $DBI::errstr . "\n");
54 $self->enable_foreign_keys();
60 my($self, $init, $dbpath, $fallbackdir)=@_;
67 if(defined ($self->{base}))
69 $file="$self->{base}/$dbfile" unless defined($file);
72 elsif(defined($fallbackdir) && -d $fallbackdir)
74 my $path=Cwd::abs_path($fallbackdir);
77 $file="$path/$dbfile";
79 $path=~s/(.*)\/.*/$1/;
81 while(! -f $file && length($path) && -d $path);
84 $file="$fallbackdir/$dbfile";
88 if(!-f $file && !$init)
90 print "$self->{me}: db not found at $file\n";
97 sub base_dir { return shift->{base}; }
102 my @schema=split(/\n\n/,join("", <DATA>));
104 for my $cmd (@schema)
106 $self->{dbh}->do($cmd);
108 if($self->{postgres})
110 $self->cmd("CREATE SEQUENCE seq");
114 my %indexes=( "idx_files_id" => "files (id)",
115 "idx_fxt_both" => "files_x_tags (files_id, tags_id)",
116 "idx_fxt_files" => "files_x_tags (files_id)",
117 "idx_fxt_tags" => "files_x_tags (tags_id)",
118 "idx_tags_id" => "tags (id)",
119 "idx_tags_name" => "tags (name)");
120 for my $index (keys %indexes)
122 $self->{dbh}->do("CREATE INDEX $index ON " . $indexes{$index});
125 $self->cmd("INSERT INTO id3fs (schema_version, last_update) VALUES (?, ?)",
126 $SCHEMA_VERSION, time());
132 my ($version)=$self->cmd_onerow("SELECT schema_version from id3fs");
133 if(!defined($version) || $version != $SCHEMA_VERSION)
135 die("$self->{me}: id3fs database version " .
136 defined($version) ? $version : '""' .
137 "not known, current version is $SCHEMA_VERSION.\n");
144 $self->cmd("ANALYZE");
147 sub enable_foreign_keys
150 $self->cmd("PRAGMA foreign_keys = ON");
155 my($self, $newval)=@_;
158 $self->cmd("UPDATE id3fs SET last_update=?", $newval);
162 ($newval)=$self->cmd_onerow("SELECT last_update from id3fs");
169 my($self, $sql, @params)=@_;
170 my $sth=$self->{dbh}->prepare($sql);
172 for my $param (@params)
174 $param="" unless(defined($param));
175 $sth->bind_param($idx++, $param);
184 my @constraints=@{$path->{elements}};
185 if(!@constraints) # /
187 my $sql="SELECT DISTINCT name FROM tags WHERE parents_id='';";
188 my $tags=$self->cmd_rows($sql);
189 return(map { $_->[0]; } @$tags);
191 my $hasvals=$path->tag_has_values();
192 my $parent=$path->trailing_tag_parent();
193 print "THASVALS: $hasvals\n";
194 print "TPARENT: ", (defined($parent)? $parent : "NO"), "\n";
196 my $sql=("SELECT tags.name FROM (\n" .
197 $self->tags_subselect($path) .
199 "INNER JOIN files_x_tags ON subselect.files_id=files_x_tags.files_id\n" .
200 "INNER JOIN tags ON files_x_tags.tags_id=tags.id\n");
201 my (@allused)=$path->used_tags();
202 my @used=grep { ref($_) ne "ARRAY"; } @allused;
203 my @used_with_vals=grep { ref($_) eq "ARRAY"; } @allused;
204 print "tags(): USED: ", join(", ", @used), "\n";
205 print "tags(): USED_WITH_VALS: ", join(", ", map { "[".$_->[0]. ", ".$_->[1]."]";} @used_with_vals), "\n";
208 my $id=$path->trailing_tag_id();
211 print "HAS_VALUES\n";
212 my @values=map { "'".$_->[1]."'"; } grep { $_->[0] == $id; } @used_with_vals;
213 my $clause="(tags.parents_id='$id'";
216 $clause .= " AND tags.id NOT IN (" . join(', ', @values) . ")";
219 push(@orclauses, $clause);
223 print "HASNT VALUES\n";;
226 push(@orclauses, "(NOT (tags.parents_id='' AND tags.id IN (" . join(', ', @used) . ")))");
228 for my $pair (@used_with_vals)
230 push(@orclauses, "(NOT (tags.parents_id='" . $pair->[0] . "' AND tags.id='" . $pair->[1] . "'))");
234 my $parentclause= "(tags.parents_id='";
237 $parentclause .= $id;
241 $parentclause .= $parent;
243 $parentclause .= "')";
244 push(@andclauses, $parentclause);
248 push(@andclauses, join(' OR ', @orclauses));
252 $sql .= "WHERE " . join(' AND ', @andclauses) . "\n";
254 $sql .= "GROUP BY tags.name;";
256 my $result=$self->cmd_rows($sql);
257 my @tagnames=map { $_->[0]; } @$result;
258 print "SUBNAMES: ", join(', ', @tagnames), "\n";
264 my($self, $tagid)=@_;
265 my $sql=("SELECT DISTINCT name FROM tags\n" .
266 "WHERE parents_id=?");
267 my $tags=$self->cmd_rows($sql, $tagid);
268 my @tags=map { $_->[0]; } @$tags;
269 @tags=map { length($_) ? $_ : "NOVALUE"; } @tags;
276 my @constraints=@{$path->{elements}};
277 if(!@constraints) # /ALL
279 my $sql="SELECT DISTINCT name FROM artists;";
280 my $tags=$self->cmd_rows($sql);
281 return(map { $_->[0]; } @$tags);
284 my $sql=("SELECT artists.name FROM (\n" .
285 $self->tags_subselect($path) .
287 "INNER JOIN files ON subselect.files_id=files.id\n" .
288 "INNER JOIN artists ON files.artists_id=artists.id\n" .
289 "GROUP BY artists.name;");
291 my $result=$self->cmd_rows($sql);
292 my @tagnames=map { $_->[0]; } @$result;
293 print "ARTISTS: ", join(', ', @tagnames), "\n";
300 my @constraints=@{$path->{elements}};
302 # FIXME: rework PathElements
303 if(ref($constraints[$#constraints]) eq "ID3FS::PathElement::Artist")
305 return $self->artist_albums($constraints[$#constraints]->{id}, $path);
307 my $sql=("SELECT albums.name\n" .
309 $self->tags_subselect($path) .
310 "\t) AS subselect\n" .
311 "INNER JOIN files ON subselect.files_id=files.id\n" .
312 "INNER JOIN albums ON files.albums_id=albums.id\n" .
313 "GROUP BY albums.name;");
314 print "SQL(ALBUMS): \n$sql\n";
315 my $result=$self->cmd_rows($sql);
316 my @names=map { $_->[0]; } @$result;
317 print "ALBUMS: ", join(', ', @names), "\n";
323 my($self, $artist_id, $path)=@_;
324 my @constraints=@{$path->{elements}};
325 my $sql=("SELECT albums.name FROM (\n" .
326 $self->tags_subselect($path) .
327 "\t) AS subselect\n" .
328 "INNER JOIN files ON subselect.files_id=files.id\n" .
329 "INNER JOIN albums ON albums.id=files.albums_id\n\t" .
330 "INNER JOIN artists ON artists.id=files.artists_id\n\t" .
331 "WHERE artists.id=? and albums.name <> ''\n\t" .
332 "GROUP BY albums.name\n");
333 print "ARTIST_ALBUMS SQL: $sql\n";
334 my $result=$self->cmd_rows($sql, $artist_id);
335 my @albums=map { $_->[0]; } @$result;
336 print "ALBUMS: ", join(', ', @albums), "\n";
342 my($self, $artist_id, $path)=@_;
343 my $sql=("SELECT files.name FROM (\n" .
344 $self->tags_subselect($path) .
345 "\t) AS subselect\n" .
346 "INNER JOIN files ON subselect.files_id=files.id\n" .
347 "INNER JOIN artists ON artists.id=files.artists_id\n\t" .
348 "INNER JOIN albums ON albums.id=files.albums_id\n\t" .
349 "WHERE artists.id=? AND albums.name=''\n\t" .
350 "GROUP BY files.name\n");
351 print "ARTIST_TRACKS SQL: $sql\n";
352 my $result=$self->cmd_rows($sql, $artist_id);
353 my @names=map { $_->[0]; } @$result;
354 print "ARTISTTRACKS: ", join(', ', @names), "\n";
360 my($self, $artist_id, $album_id)=@_;
361 my $sql=("SELECT files.name FROM files\n\t" .
362 "INNER JOIN albums ON albums.id=files.albums_id\n\t" .
363 "INNER JOIN artists ON artists.id=files.artists_id\n\t" .
364 "WHERE artists.id=? AND albums.id=?\n\t" .
365 "GROUP BY files.name\n");
366 print "ALBUM_TRACKS SQL($artist_id, $album_id): $sql\n";
367 my $result=$self->cmd_rows($sql, $artist_id, $album_id);
368 my @names=map { $_->[0]; } @$result;
369 print "TRACKS: ", join(', ', @names), "\n";
376 my @constraints=@{$path->{elements}};
377 # FIXME: rework PathElements
378 if(ref($constraints[$#constraints]) eq "ID3FS::PathElement::Artist")
381 my $artist=$constraints[$#constraints];
382 if(defined($artist) && (ref($artist) eq "ID3FS::PathElement::Artist"))
384 # should always happen
385 $artist_id=$artist->{id};
387 return $self->artist_tracks($artist_id, $path);
389 elsif(ref($constraints[$#constraints]) eq "ID3FS::PathElement::Album")
392 my $artist=$constraints[($#constraints)-1];
393 if(defined($artist) && (ref($artist) eq "ID3FS::PathElement::Artist"))
395 # should always happen
396 $artist_id=$artist->{id};
398 return $self->album_tracks($artist_id, $constraints[$#constraints]->{id});
401 my $sql=("SELECT files.name\n" .
403 $self->tags_subselect($path) .
404 "\t) AS subselect\n" .
405 "INNER JOIN files ON files.id=subselect.files_id\n" .
406 "GROUP BY files.name;");
408 my $result=$self->cmd_rows($sql);
409 my @names=map { $_->[0]; } @$result;
410 print "TRACKS: ", join(', ', @names), "\n";
416 my($self, $mountpoint, $path)=@_;
417 my @constraints=@{$path->{elements}};
418 if(ref($constraints[$#constraints]) eq "ID3FS::PathElement::File")
420 my $id=$constraints[$#constraints]->{id};
421 my $sql=("SELECT paths.name, files.name FROM files\n" .
422 "INNER JOIN paths ON files.paths_id=paths.id\n" .
423 "WHERE files.id=?\n" .
424 "GROUP BY paths.name, files.name");
425 print "FILENAME SQL: $sql\n";
426 my ($path, $name)=$self->cmd_onerow($sql, $id);
427 my $id3fs_path=join('/', map { $_->{name}; } @constraints);
428 return($self->relativise($path, $name, $mountpoint, $id3fs_path));
430 die("DB::filename: unhandled case\n"); #FIXME
436 my $tree=$path->{tagtree};
437 my $hasvals=$path->tag_has_values();
438 my $parent=$path->trailing_tag_parent();
443 $tag=$path->trailing_tag_id();
444 print "Trailing id: $tag\n";
446 my ($sqlclause, $joinsneeded)=(undef, 1);
447 ($sqlclause, $joinsneeded) = $tree->to_sql($tag) if($tree);
448 print "SQL($joinsneeded): $sqlclause\n";
449 my $sql="\tSELECT fxt1.files_id FROM tags t1";
452 # $joinsneeded++ if($tag);
453 for(my $i=1; $i <= $joinsneeded; $i++)
457 push(@crosses, "CROSS JOIN tags t$i");
459 my $inner=("\tINNER JOIN files_x_tags fxt$i ON " .
460 "t${i}.id=fxt${i}.tags_id");
463 $inner .= " AND fxt1.files_id=fxt${i}.files_id";
465 push(@inners, $inner);
467 $sql .= ("\n\t" . join(" ", @crosses)) if(@crosses);
468 $sql .= ("\n" . join("\n", @inners)) if(@inners);
469 $sql .= "\n\tWHERE $sqlclause" if($sqlclause);
472 # $sql .= " AND t${joinsneeded}.parents_id='$tag'";
474 $sql .= "\n\tGROUP BY fxt1.files_id\n";
478 sub tags_subselect_and_not
480 my($self,@constraints)=@_;
481 my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
483 my @tags_vals=@$tags_vals;;
491 $sql="\tSELECT fxt" . scalar(@tags) . ".files_id FROM files_x_tags fxt1\n";
492 push(@andclauses, "\t\tfxt${cnt}.tags_id=$tag");
496 $sql .= ("\tLEFT JOIN files_x_tags fxt$cnt ON fxt" .
497 ($cnt-1) . ".files_id=fxt${cnt}.files_id\n");
498 push(@andclauses, "\t\tfxt${cnt}.tags_id IS NULL");
500 print "AND: @andclauses\n";
505 $sql .= "\tWHERE\n\t\t";
506 $sql .= join(" AND\n\t\t", @andclauses) . "\n";
508 $sql .= "\tGROUP BY fxt". scalar(@tags).".files_id\n";
513 sub tags_subselect_and
515 my($self,@constraints)=@_;
516 my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
518 my @tags_vals=@$tags_vals;;
526 $sql="\tSELECT fxt" . scalar(@tags) . ".files_id FROM files_x_tags fxt1\n";
530 $sql .= ("\tINNER JOIN files_x_tags fxt$cnt ON fxt" .
531 ($cnt-1) . ".files_id=fxt${cnt}.files_id\n");
533 push(@andclauses, "\t\tfxt${cnt}.tags_id = $tag");
534 print "AND: @andclauses\n";
539 $sql .= "\tWHERE\n\t\t";
540 $sql .= join(" AND\n\t\t", @andclauses) . "\n";
542 $sql .= "\tGROUP BY fxt". scalar(@tags).".files_id\n";
546 sub tags_subselect_or
548 my($self,@constraints)=@_;
549 my ($tags, $tags_vals, $parent)=$self->constraints_tag_list(@constraints);
551 my @tags_vals=@$tags_vals;;
553 my $sql=("\tSELECT files_x_tags.files_id FROM tags t1\n" .
554 "\tINNER JOIN files_x_tags ON t1.id=files_x_tags.tags_id\n");
560 push(@andclauses, "( t1.parents_id=" . (defined($parent) ? $parent : "''") . " )");
561 push(@andclauses, "( t1.id IN ( " . join(', ', @tags) ." ) )");
563 for my $pair (@tags_vals)
565 my($tag, $val)=@$pair;
566 push(@orclauses, "( t1.parents_id=$tag AND t1.id=$val )");
568 # push(@andclauses, "( t1.parents_id=" . (defined($parent) ? $parent : "''") . " )");
571 push(@andclauses, join("\n\t\tOR ", @orclauses));
575 $sql .= "\tWHERE\n\t\t";
576 $sql .= join("\n\t\tAND ", @andclauses) . "\n";
578 $sql .= "\tGROUP BY files_x_tags.files_id\n";
582 sub constraints_tag_list
584 my($self, @constraints)=@_;
588 for my $constraint (@constraints)
590 # print ref($constraint), ": ", $constraint->{name}, "\n";
591 if(ref($constraint) eq "ID3FS::PathElement::Tag")
593 if(defined($lasttag))
596 push(@tags_vals, [$lasttag, $constraint->{id}]) if defined($constraint->{id});
599 elsif($self->tag_has_values($constraint->{id}))
601 # print "HASVALUES\n";
602 $lasttag=$constraint->{id} if defined($constraint->{id});
606 # print "NOVALUES\n";
607 push(@tags, $constraint->{id}) if(defined($constraint->{id}));
611 unless($self->{postgres})
613 @tags=map{ "\"$_\""; } @tags;
614 @tags_vals=map( { [ map({ "\"$_\""; } @$_ ) ] } @tags_vals);
615 $lasttag="\"$lasttag\"" if defined($lasttag);
617 return(\@tags, \@tags_vals, $lasttag);
623 my($self, $path, $name, $mountpoint, $id3fs_path)=@_;
624 $id3fs_path=~s/(.*)\/.*/$1/;
625 my $rpath="$self->{absbase}/$path";
626 my $vpath="$mountpoint/$id3fs_path";
627 my @path=split(/\//,$rpath);
628 my @rel=split(/\//,$vpath);
629 #absolute paths have empty first element due to leading /
630 shift(@path) if($path[0] eq "");
631 shift(@rel) if($rel[0] eq "");
632 if($path[0] ne $rel[0])
634 #no path in common, return absolute
635 print "FAIL: NO PATHS IN COMMON\n";
638 # f: /home/foo/bar/baz.mp3
639 # r: /home/ianb/music/albums
640 while(@path && @rel && ($path[0] eq $rel[0]))
647 my $upcount=scalar(@rel);
648 my $result="../" x $upcount;
649 $result .= join("/",@path);
657 my $sql=("SELECT tags.name FROM tags\n" .
658 "WHERE tags.parents_id=''\n" .
659 "GROUP BY tags.name\n");
660 my $result=$self->cmd_rows($sql);
661 my @names=map { $_->[0]; } @$result;
667 # FIXME: only shows one level of tag depth
669 my $sql=("SELECT p.name, t.name FROM tags t\n" .
670 "INNER JOIN tags p ON t.parents_id=p.id\n" .
671 "GROUP BY p.name, t.name\n");
673 my $result=$self->cmd_rows($sql);
675 for my $pair (@$result)
677 push(@{$tags->{$pair->[0]}}, $pair->[1]);
684 my($self, $type, $val)=@_;
685 my $sql="SELECT id FROM $type WHERE name=?";
686 my ($id)=$self->cmd_onerow($sql, $val);
694 $relpath =~ s/^\Q$self->{base}\E\/?//;
695 my($filepart,$pathpart);
703 ($pathpart, $filepart) = ($relpath =~ /(.*)\/(.*)/);
705 my $file=ID3FS::AudioFile->new($path, $self->{me});
706 return unless(defined($file));
707 my $artist=$file->artist();
708 my $album=$file->album();
709 my $v1genre=$file->v1genre();
710 my $year=$file->year();
711 my $audiotype=$file->audiotype();
712 my @tags=$file->tags();
713 my $haspic=$file->haspic();
715 $artist=undef unless($self->ok($artist));
716 print "$self->{me}: $path: no artist tag defined\n" unless(defined($artist));
717 my $artist_id=$self->add_to_table("artists", $artist);
718 my $path_id=$self->add_to_table("paths", $pathpart);
719 $album=undef unless($self->ok($album));
720 if($self->{verbose} && !defined($album))
722 print "$self->{me}: $path: no album tag defined\n";
725 my $albums_id=$self->add_to_table("albums", $album);
726 my $file_id=$self->add_to_table("files", $filepart,
727 { "artists_id" => $artist_id,
728 "albums_id" => $albums_id,
729 "paths_id" => $path_id });
732 $self->add_tag($file_id, @$tag);
737 $self->add_tag($file_id, "year", $year);
738 if($year=~/^(\d\d\d)\d$/)
740 $self->add_tag($file_id, "decade", "${1}0s");
744 if($self->ok($v1genre))
746 $self->add_tag($file_id, "v1genre", $v1genre);
751 $self->add_tag($file_id, "haspic", undef);
757 my($self, $file_id, $tag, $value)=@_;
758 my $tag_id=$self->add_to_table("tags", $tag,
759 { "parents_id" => undef });
760 $self->add_relation("files_x_tags",
761 { "files_id" => $file_id,
762 "tags_id" => $tag_id });
763 if(defined($value) && length($value))
765 my $val_id=$self->add_to_table("tags", $value,
766 { "parents_id" => $tag_id });
767 $self->add_relation("files_x_tags",
768 { "files_id" => $file_id,
769 "tags_id" => $val_id });
775 my($self, $table, $name, $extradata)=@_;
776 my $id=$self->lookup_id($table, $name);
779 my $sql="INSERT INTO $table (";
780 $sql .= "id, " if($self->{postgres});
782 if(defined($extradata))
784 push(@fields, sort keys(%$extradata));
786 $sql .= join(", ", @fields);
788 $sql .=") nextval('seq'), " if($self->{postgres});
789 $sql .= join(", ", map { "?"; } @fields);
791 $id=$self->cmd_id($sql, $name, map { $extradata->{$_} || ""; } sort keys %$extradata);
798 my ($self, $relname, $fields)=@_;
799 return if($self->relation_exists($relname, $fields));
800 my $sql="INSERT INTO $relname (";
801 $sql .= join(", ", sort keys(%$fields));
802 $sql .= ") VALUES (";
803 $sql .= join(", ", map { "?"; } sort keys(%$fields));
805 $self->cmd($sql, map { $fields->{$_}; } sort keys(%$fields));
810 my($self, $table, $name)=@_;
811 my($id)=$self->cmd_onerow("SELECT id FROM $table where name=?", $name);
818 my $sql=("SELECT COUNT(*) FROM tags\n\t" .
819 "WHERE tags.parents_id=?\n");
820 my ($rows)=$self->cmd_onerow($sql, $id);
827 $dir=~s/^$self->{base}\/?//;
828 my $sql=("SELECT files.name FROM files\n" .
829 "INNER JOIN paths ON files.paths_id=paths.id\n" .
830 "WHERE paths.name=?\n");
831 my $files=$self->cmd_rows($sql, $dir);
832 return(map { $_->[0]; } @$files);
835 sub prune_directories
838 my $sql=("SELECT name, id FROM paths ORDER BY name\n");
839 my $pathsref=$self->cmd_rows($sql);
841 for my $pathpair (@$pathsref)
843 my($path, $id)=@$pathpair;
844 my $fullpath="$self->{absbase}/$path";
850 $self->prune_paths(@ids);
858 my $sql=("DELETE FROM files WHERE paths_id IN (\n\t" .
859 join(', ', map { "\"$_\""; } @ids). "\n\t)");
860 print "SQL: \n", $sql, "\n";
868 DELETE FROM artists WHERE id IN (
869 SELECT artists.id FROM artists
870 LEFT JOIN files ON files.artists_id=artists.id
871 WHERE files.id IS NULL);
873 DELETE FROM albums WHERE id IN (
874 SELECT albums.id FROM albums
875 LEFT JOIN files ON files.albums_id=albums.id
876 WHERE files.id IS NULL);
878 DELETE FROM paths WHERE id IN (
879 SELECT paths.id FROM paths
880 LEFT JOIN files ON files.paths_id=paths.id
881 WHERE files.id IS NULL);
883 DELETE FROM files_x_tags WHERE files_id IN (
884 SELECT files_x_tags.files_id FROM files_x_tags
885 LEFT JOIN files ON files.id=files_x_tags.files_id
886 WHERE files.id IS NULL);
888 DELETE FROM tags WHERE id IN (
889 SELECT tags.id FROM tags
890 LEFT JOIN files_x_tags ON files_x_tags.tags_id=tags.id
891 WHERE files_x_tags.files_id IS NULL);
896 my @sql=split(/\n\n/, $sql);
897 $self->cmd($_) for (@sql);
902 my ($self, $relname, $fields)=@_;
903 my $sql="SELECT count(1) FROM $relname WHERE ";
906 for my $field (keys %$fields)
909 push(@vals,$fields->{$field});
911 $sql .= join(' AND ', map { "$_=?"; } @exprs);
912 my ($ret)=$self->cmd_onerow($sql, @vals);
918 my($self, $thing)=@_;
919 return(defined($thing) && length($thing) && $thing =~ /\S+/);
924 my ($self, @args)=@_;
925 # don't care about retcode
926 $self->cmd_sth(@args);
931 my ($self, @args)=@_;
932 my $sth=$self->cmd_sth(@args);
933 return($sth->fetchrow_array());
938 my ($self, @args)=@_;
939 my $sth=$self->cmd_sth(@args);
940 return $sth->fetchall_arrayref();
945 my ($self, @args)=@_;
946 $self->cmd_sth(@args);
947 return($self->last_insert_id());
953 if($self->{postgres})
955 return $self->{dbh}->last_insert_id(undef, undef, undef, undef,
956 { sequence => "seq" });
960 return $self->{dbh}->last_insert_id("","","","");
967 schema_version INTEGER,
972 id INTEGER PRIMARY KEY,
976 CREATE TABLE artists (
977 id INTEGER PRIMARY KEY,
981 CREATE TABLE albums (
982 id INTEGER PRIMARY KEY,
987 id INTEGER PRIMARY KEY,
992 FOREIGN KEY(artists_id) REFERENCES artists(id) ON DELETE CASCADE ON UPDATE CASCADE,
993 FOREIGN KEY(albums_id) REFERENCES albums(id) ON DELETE CASCADE ON UPDATE CASCADE,
994 FOREIGN KEY(paths_id) REFERENCES paths(id) ON DELETE CASCADE ON UPDATE CASCADE
998 id INTEGER PRIMARY KEY,
1003 CREATE TABLE files_x_tags (
1006 FOREIGN KEY(files_id) REFERENCES files(id) ON DELETE CASCADE ON UPDATE CASCADE,
1007 FOREIGN KEY(tags_id) REFERENCES tags(id) ON DELETE CASCADE ON UPDATE CASCADE