Revision 822cdc96
Von Sven Schöling vor etwa 8 Jahren hinzugefügt
SL/RecordLinks.pm | ||
---|---|---|
7 | 7 |
use SL::DBUtils; |
8 | 8 |
use Data::Dumper; |
9 | 9 |
use List::Util qw(reduce); |
10 |
use SL::DB; |
|
10 | 11 |
|
11 | 12 |
sub create_links { |
12 | 13 |
$main::lxdebug->enter_sub(); |
... | ... | |
54 | 55 |
my $myconfig = \%main::myconfig; |
55 | 56 |
my $form = $main::form; |
56 | 57 |
|
57 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
58 |
SL::DB->client->with_transaction(sub { |
|
59 |
my $dbh = $params{dbh} || SL::DB->client->dbh; |
|
58 | 60 |
|
59 |
my $query = qq|INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES (?, ?, ?, ?)|; |
|
60 |
my $sth = prepare_query($form, $dbh, $query); |
|
61 |
my $query = qq|INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES (?, ?, ?, ?)|;
|
|
62 |
my $sth = prepare_query($form, $dbh, $query);
|
|
61 | 63 |
|
62 |
foreach my $link (@links) { |
|
63 |
next if ('HASH' ne ref $link); |
|
64 |
next if (!$link->{from_table} || !$link->{from_id} || !$link->{to_table} || !$link->{to_id}); |
|
64 |
foreach my $link (@links) {
|
|
65 |
next if ('HASH' ne ref $link);
|
|
66 |
next if (!$link->{from_table} || !$link->{from_id} || !$link->{to_table} || !$link->{to_id});
|
|
65 | 67 |
|
66 |
do_statement($form, $sth, $query, $link->{from_table}, conv_i($link->{from_id}), $link->{to_table}, conv_i($link->{to_id})); |
|
67 |
} |
|
68 |
do_statement($form, $sth, $query, $link->{from_table}, conv_i($link->{from_id}), $link->{to_table}, conv_i($link->{to_id}));
|
|
69 |
}
|
|
68 | 70 |
|
69 |
$dbh->commit() unless ($params{dbh}); |
|
71 |
1; |
|
72 |
}) or do { die SL::DB->client->error }; |
|
70 | 73 |
|
71 | 74 |
$main::lxdebug->leave_sub(); |
72 | 75 |
} |
... | ... | |
184 | 187 |
my $myconfig = \%main::myconfig; |
185 | 188 |
my $form = $main::form; |
186 | 189 |
|
187 |
my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); |
|
190 |
SL::DB->client->with_transaction(sub { |
|
191 |
my $dbh = $params{dbh} || SL::DB->client->dbh; |
|
188 | 192 |
|
189 |
# content |
|
190 |
my (@where_tokens, @where_values); |
|
193 |
# content
|
|
194 |
my (@where_tokens, @where_values);
|
|
191 | 195 |
|
192 |
for my $col (qw(from_table from_id to_table to_id)) { |
|
193 |
add_token(\@where_tokens, \@where_values, col => $col, val => $params{$col}) if $params{$col}; |
|
194 |
} |
|
196 |
for my $col (qw(from_table from_id to_table to_id)) {
|
|
197 |
add_token(\@where_tokens, \@where_values, col => $col, val => $params{$col}) if $params{$col};
|
|
198 |
}
|
|
195 | 199 |
|
196 |
my $where = @where_tokens ? "WHERE ". join ' AND ', map { "($_)" } @where_tokens : ''; |
|
197 |
my $query = "DELETE FROM record_links $where"; |
|
200 |
my $where = @where_tokens ? "WHERE ". join ' AND ', map { "($_)" } @where_tokens : '';
|
|
201 |
my $query = "DELETE FROM record_links $where";
|
|
198 | 202 |
|
199 |
do_query($form, $dbh, $query, @where_values); |
|
203 |
do_query($form, $dbh, $query, @where_values);
|
|
200 | 204 |
|
201 |
$dbh->commit() unless ($params{dbh}); |
|
205 |
1; |
|
206 |
}) or die { SL::DD->client->error }; |
|
202 | 207 |
|
203 | 208 |
$main::lxdebug->leave_sub(); |
204 | 209 |
} |
Auch abrufbar als: Unified diff
RecordLinks: single-dbh