projects
/
id3fs.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
8d3d327
)
ensure tags with different parents have different entries; tweak schema
author
Ian Beckwith
<ianb@erislabs.net>
Sun, 17 Oct 2010 04:07:51 +0000
(
05:07
+0100)
committer
Ian Beckwith
<ianb@erislabs.net>
Sun, 17 Oct 2010 04:08:47 +0000
(
05:08
+0100)
lib/ID3FS/DB.pm
patch
|
blob
|
history
diff --git
a/lib/ID3FS/DB.pm
b/lib/ID3FS/DB.pm
index
a3a771f
..
1638c54
100644
(file)
--- a/
lib/ID3FS/DB.pm
+++ b/
lib/ID3FS/DB.pm
@@
-307,7
+307,12
@@
sub add_tag
sub add_to_table
{
my($self, $table, $name, $extradata)=@_;
sub add_to_table
{
my($self, $table, $name, $extradata)=@_;
- my $id=$self->lookup_id($table, $name);
+ my $parent=undef;
+ if($extradata && $extradata->{parents_id})
+ {
+ $parent=$extradata->{parents_id};
+ }
+ my $id=$self->lookup_id($table, $name, $parent);
unless(defined($id))
{
my $sql="INSERT INTO $table (";
unless(defined($id))
{
my $sql="INSERT INTO $table (";
@@
-511,8
+516,15
@@
sub last_insert_id
sub lookup_id
{
sub lookup_id
{
- my($self, $table, $name)=@_;
- my($id)=$self->cmd_onerow("SELECT id FROM $table where name=?", $name);
+ my($self, $table, $name, $parent)=@_;
+ my $sql="SELECT id FROM $table where name=?";
+ my @args=($name);
+ if($parent)
+ {
+ $sql .= " AND parents_id=?";
+ push(@args, $parent);
+ }
+ my($id)=$self->cmd_onerow($sql, @args);
return $id;
}
return $id;
}
@@
-524,35
+536,40
@@
CREATE TABLE id3fs (
);
CREATE TABLE paths (
);
CREATE TABLE paths (
- id INTEGER PRIMARY KEY,
- name text
+ id INTEGER,
+ name text,
+ PRIMARY KEY(id DESC)
);
CREATE TABLE artists (
);
CREATE TABLE artists (
- id INTEGER PRIMARY KEY,
- name text
+ id INTEGER,
+ name text,
+ PRIMARY KEY(id DESC)
);
CREATE TABLE albums (
);
CREATE TABLE albums (
- id INTEGER PRIMARY KEY,
- name text
+ id INTEGER,
+ name text,
+ PRIMARY KEY(id DESC)
);
CREATE TABLE files (
);
CREATE TABLE files (
- id INTEGER
PRIMARY KEY
,
+ id INTEGER,
name text,
artists_id,
albums_id,
paths_id,
name text,
artists_id,
albums_id,
paths_id,
+ PRIMARY KEY(id DESC),
FOREIGN KEY(artists_id) REFERENCES artists(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(albums_id) REFERENCES albums(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(paths_id) REFERENCES paths(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE tags (
FOREIGN KEY(artists_id) REFERENCES artists(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(albums_id) REFERENCES albums(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(paths_id) REFERENCES paths(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE tags (
- id INTEGER
PRIMARY KEY
,
+ id INTEGER,
parents_id INTEGER,
parents_id INTEGER,
- name text
+ name text,
+ PRIMARY KEY(id DESC)
);
CREATE TABLE files_x_tags (
);
CREATE TABLE files_x_tags (