7 $main::lxdebug->enter_sub();
12 if ($params{mode} && ($params{mode} eq 'ids')) {
13 Common::check_params_x(\%params, [ qw(from_ids to_ids) ]);
16 Common::check_params(\%params, qw(links));
22 if ($params{mode} && ($params{mode} eq 'ids')) {
23 my ($from_to, $to_from) = $params{from_ids} ? qw(from to) : qw(to from);
26 if ('ARRAY' eq ref $params{"${from_to}_ids"}) {
27 $ids{$from_to} = $params{"${from_to}_ids"};
29 $ids{$from_to} = [ grep { $_ } map { $_ * 1 } split m/\s+/, $params{"${from_to}_ids"} ];
32 if (my $num = scalar @{ $ids{$from_to} }) {
33 $main::lxdebug->message(0, "3");
34 $ids{$to_from} = [ ($params{"${to_from}_id"}) x $num ];
35 @links = map { { 'from_table' => $params{from_table},
36 'from_id' => $ids{from}->[$_],
37 'to_table' => $params{to_table},
38 'to_id' => $ids{to}->[$_], } } (0 .. $num - 1);
42 @links = @{ $params{links} };
46 $main::lxdebug->leave_sub();
50 my $myconfig = \%main::myconfig;
51 my $form = $main::form;
53 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
55 my $query = qq|INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES (?, ?, ?, ?)|;
56 my $sth = prepare_query($form, $dbh, $query);
58 foreach my $link (@links) {
59 next if ('HASH' ne ref $link);
60 next if (!$link->{from_table} || !$link->{from_id} || !$link->{to_table} || !$link->{to_id});
62 do_statement($form, $sth, $query, $link->{from_table}, conv_i($link->{from_id}), $link->{to_table}, conv_i($link->{to_id}));
65 $dbh->commit() unless ($params{dbh});
67 $main::lxdebug->leave_sub();
71 $main::lxdebug->enter_sub();
76 Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]);
78 my $myconfig = \%main::myconfig;
79 my $form = $main::form;
81 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
86 foreach my $col (qw(from_table from_id to_table to_id)) {
87 next unless ($params{$col});
89 if ('ARRAY' eq ref $params{$col}) {
90 push @conditions, "$col IN (" . join(', ', ('?') x scalar(@{ $params{$col} })) . ")";
91 push @values, $col =~ m/table/ ? @{ $params{$col} } : map { conv_i($_) } @{ $params{$col} };
94 push @conditions, "$col = ?";
95 push @values, $col =~ m/table/ ? $params{$col} : conv_i($params{$col});
99 my $query = qq|SELECT from_table, from_id, to_table, to_id
102 if (scalar @conditions) {
103 $query .= qq| WHERE | . join(' AND ', map { "($_)" } @conditions);
106 my $links = selectall_hashref_query($form, $dbh, $query, @values);
108 $main::lxdebug->leave_sub();
110 return wantarray ? @{ $links } : $links;