7 $main::lxdebug->enter_sub();
12 Common::check_params(\%params, qw(links));
14 if (!scalar @{ $params{links} }) {
15 $main::lxdebug->leave_sub();
19 my $myconfig = \%main::myconfig;
20 my $form = $main::form;
22 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
24 my $query = qq|INSERT INTO record_links (from_table, from_id, to_table, to_id) VALUES (?, ?, ?, ?)|;
25 my $sth = prepare_query($form, $dbh, $query);
27 foreach my $link (@{ $params{links} }) {
28 next if ('HASH' ne ref $link);
29 next if (!$link->{from_table} || !$link->{from_id} || !$link->{to_table} || !$link->{to_id});
31 do_statement($form, $sth, $query, $link->{from_table}, conv_i($link->{from_id}), $link->{to_table}, conv_i($link->{to_id}));
34 $dbh->commit() unless ($params{dbh});
36 $main::lxdebug->leave_sub();
40 $main::lxdebug->enter_sub();
45 Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]);
47 my $myconfig = \%main::myconfig;
48 my $form = $main::form;
50 my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig);
55 foreach my $col (qw(from_table from_id to_table to_id)) {
56 next unless ($params{$col});
58 if ('ARRAY' eq ref $params{$col}) {
59 push @conditions, "$col IN (" . join(', ', ('?') x scalar(@{ $params{$col} })) . ")";
60 push @values, $col =~ m/table/ ? @{ $params{$col} } : map { conv_i($_) } @{ $params{$col} };
63 push @conditions, "$col = ?";
64 push @values, $col =~ m/table/ ? $params{$col} : conv_i($params{$col});
68 my $query = qq|SELECT from_table, from_id, to_table, to_id
71 if (scalar @conditions) {
72 $query .= qq| WHERE | . join(' AND ', map { "($_)" } @conditions);
75 my $links = selectall_hashref_query($form, $dbh, $query, @values);
77 $main::lxdebug->leave_sub();
79 return wantarray ? @{ $links } : $links;