diff options
author | Yorhel <git@yorhel.nl> | 2010-01-01 19:01:38 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2010-01-01 19:01:38 +0100 |
commit | 81380525f2c4385577019ae964039dcf3c791625 (patch) | |
tree | bb39439553ecbf76d34b971c688225d5d2047238 /lib/VNDB/DB/Producers.pm | |
parent | 0a4395eb4b186ea91e7a69d1556cb50352ade7f7 (diff) |
SQL: Revision insertion abstraction for producer entries
Diffstat (limited to 'lib/VNDB/DB/Producers.pm')
-rw-r--r-- | lib/VNDB/DB/Producers.pm | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/lib/VNDB/DB/Producers.pm b/lib/VNDB/DB/Producers.pm index 4a666350..f32f70db 100644 --- a/lib/VNDB/DB/Producers.pm +++ b/lib/VNDB/DB/Producers.pm @@ -100,22 +100,21 @@ sub dbProducerGet { } -# inserts a producer revision, called from dbItemEdit() or dbItemAdd() -# Arguments: global revision, item id, { columns in producers_rev + relations }, +# Updates the edit_* tables, used from dbItemEdit() +# Arguments: { columns in producers_rev + relations }, sub dbProducerRevisionInsert { - my($self, $cid, $pid, $o) = @_; + my($self, $o) = @_; - $self->dbExec(q| - INSERT INTO producers_rev (id, pid, name, original, website, l_wp, type, lang, "desc", alias) - VALUES (!l)|, - [ $cid, $pid, @$o{qw| name original website l_wp type lang desc alias|} ] - ); + my %set = map exists($o->{$_}) ? (qq|"$_" = ?|, $o->{$_}) : (), + qw|name original website l_wp type lang desc alias|; + $self->dbExec('UPDATE edit_producer !H', \%set) if keys %set; - $self->dbExec(q| - INSERT INTO producers_relations (pid1, pid2, relation) - VALUES (?, ?, ?)|, - $cid, $_->[1], $_->[0] - ) for (@{$o->{relations}}); + if($o->{relations}) { + $self->dbExec('DELETE FROM edit_producer_relations'); + my $q = join ',', map '(?,?)', @{$o->{relations}}; + my @q = map +($_->[1], $_->[0]), @{$o->{relations}}; + $self->dbExec("INSERT INTO edit_producer_relations (pid, relation) VALUES $q", @q) if @q; + } } |