Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9d17d16c

Von Sven Schöling vor mehr als 8 Jahren hinzugefügt

  • ID 9d17d16c39e6514243ee1ee71e9be8502331e0f2
  • Vorgänger 65b054be
  • Nachfolger 31155ae5

FU: single-dbh

Unterschiede anzeigen:

SL/FU.pm
6 6

  
7 7
use SL::Common;
8 8
use SL::DBUtils;
9
use SL::DB;
9 10
use SL::Notes;
10 11

  
11 12
use strict;
12 13

  
13 14
sub save {
15
  my ($self, %params) = @_;
14 16
  $main::lxdebug->enter_sub();
15 17

  
18
  my $rc = SL::DB->client->with_transaction(\&_save, $self, %params);
19

  
20
  $::lxdebug->leave_sub;
21
  return $rc;
22
}
23

  
24
sub _save {
16 25
  my $self     = shift;
17 26
  my %params   = @_;
18 27

  
19 28
  my $myconfig = \%main::myconfig;
20 29
  my $form     = $main::form;
21 30

  
22
  my $dbh      = $params{dbh} || $form->get_standard_dbh($myconfig);
31
  my $dbh      = $params{dbh} || SL::DB->client->dbh;
23 32
  my ($query, @values);
24 33

  
25 34
  if (!$params{id}) {
......
56 65

  
57 66
  $sth->finish();
58 67

  
59
  $dbh->commit() unless ($params{dbh});
60

  
61
  $main::lxdebug->leave_sub();
68
  return 1;
62 69
}
63 70

  
64 71
sub finish {
......
72 79
  my $myconfig = \%main::myconfig;
73 80
  my $form     = $main::form;
74 81

  
75
  my $dbh      = $form->get_standard_dbh($myconfig);
76

  
77
  do_query($form, $dbh, qq|UPDATE follow_ups SET done = TRUE WHERE id = ?|, conv_i($params{id}));
78

  
79
  $dbh->commit();
82
  SL::DB->client->with_transaction(sub {
83
    do_query($form, SL::DB->client->dbh, qq|UPDATE follow_ups SET done = TRUE WHERE id = ?|, conv_i($params{id}));
84
  });
80 85

  
81 86
  $main::lxdebug->leave_sub();
82 87
}
......
92 97
  my $myconfig = \%main::myconfig;
93 98
  my $form     = $main::form;
94 99

  
95
  my $dbh      = $form->get_standard_dbh($myconfig);
96

  
97
  my $id       = conv_i($params{id});
100
  SL::DB->client->with_transaction(sub {
101
    my $dbh      = SL::DB->client->dbh;
98 102

  
99
  do_query($form, $dbh, qq|DELETE FROM follow_up_links WHERE follow_up_id = ?|,                         $id);
100
  do_query($form, $dbh, qq|DELETE FROM follow_ups      WHERE id = ?|,                                   $id);
101
  do_query($form, $dbh, qq|DELETE FROM notes           WHERE (trans_id = ?) AND (trans_module = 'fu')|, $id);
103
    my $id       = conv_i($params{id});
102 104

  
103
  $dbh->commit();
105
    do_query($form, $dbh, qq|DELETE FROM follow_up_links WHERE follow_up_id = ?|,                         $id);
106
    do_query($form, $dbh, qq|DELETE FROM follow_ups      WHERE id = ?|,                                   $id);
107
    do_query($form, $dbh, qq|DELETE FROM notes           WHERE (trans_id = ?) AND (trans_module = 'fu')|, $id);
108
  });
104 109

  
105 110
  $main::lxdebug->leave_sub();
106 111
}
......
422 427
  my $myconfig = \%main::myconfig;
423 428
  my $form     = $main::form;
424 429

  
425
  my $dbh      = $form->get_standard_dbh($myconfig);
430
  SL::DB->client->with_transaction(sub {
431
    my $dbh      = SL::DB->client->dbh;
426 432

  
427
  my ($id)     = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $::myconfig{login});
433
    my ($id)     = selectrow_query($form, $dbh, qq|SELECT id FROM employee WHERE login = ?|, $::myconfig{login});
428 434

  
429
  do_query($form, $dbh, qq|DELETE FROM follow_up_access WHERE what = ?|, $id);
435
    do_query($form, $dbh, qq|DELETE FROM follow_up_access WHERE what = ?|, $id);
430 436

  
431
  my $query    = qq|INSERT INTO follow_up_access (who, what) VALUES (?, ?)|;
432
  my $sth      = prepare_query($form, $dbh, $query);
437
    my $query    = qq|INSERT INTO follow_up_access (who, what) VALUES (?, ?)|;
438
    my $sth      = prepare_query($form, $dbh, $query);
433 439

  
434
  while (my ($who, $access_allowed) = each %{ $params{access} }) {
435
    next unless ($access_allowed);
440
    while (my ($who, $access_allowed) = each %{ $params{access} }) {
441
      next unless ($access_allowed);
436 442

  
437
    do_statement($form, $sth, $query, conv_i($who), $id);
438
  }
439

  
440
  $sth->finish();
443
      do_statement($form, $sth, $query, conv_i($who), $id);
444
    }
441 445

  
442
  $dbh->commit();
446
    $sth->finish();
447
  });
443 448

  
444 449
  $main::lxdebug->leave_sub();
445 450
}

Auch abrufbar als: Unified diff