Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision aad72b4a

Von Sven Schöling vor etwa 8 Jahren hinzugefügt

  • ID aad72b4a0c9e9eafc96dba41c317d3d66baad4fb
  • Vorgänger 16c60c08
  • Nachfolger 64a301e5

SL:: single-dbh und disconnects

Unterschiede anzeigen:

SL/BP.pm
35 35
package BP;
36 36

  
37 37
use SL::DBUtils;
38
use SL::DB;
38 39

  
39 40
use strict;
40 41

  
......
83 84
    $sth->finish;
84 85
  }
85 86

  
86
  $dbh->disconnect;
87

  
88 87
  $main::lxdebug->leave_sub();
89 88
}
90 89

  
......
94 93
  my ($self, $myconfig, $form) = @_;
95 94

  
96 95
  # connect to database
97
  my $dbh = $form->dbconnect($myconfig);
96
  my $dbh = SL::DB->client->dbh;
98 97

  
99 98
  my $query =
100 99
    qq|SELECT DISTINCT ON (s.chart_id) c.accno, c.description | .
......
109 108
  }
110 109

  
111 110
  $sth->finish;
112
  $dbh->disconnect;
113 111

  
114 112
  $main::lxdebug->leave_sub();
115 113
}
......
119 117

  
120 118
  my ($self, $myconfig, $form) = @_;
121 119

  
122
  # connect to database
123
  my $dbh = $form->dbconnect($myconfig);
120
  my $dbh = SL::DB->client->dbh;
124 121

  
125 122
  my ($query, $arap, @values);
126 123
  my $invnumber = "invnumber";
......
227 224
  }
228 225

  
229 226
  $sth->finish;
230
  $dbh->disconnect;
231 227

  
232 228
  $main::lxdebug->leave_sub();
233 229
}
......
239 235

  
240 236
  my $spool = $::lx_office_conf{paths}->{spool};
241 237

  
242
  # connect to database, turn AutoCommit off
243
  my $dbh = $form->dbconnect_noauto($myconfig);
238
  SL::DB->client->with_transaction(sub {
239
    my $dbh = SL::DB->client->dbh;
244 240

  
245
  my $query;
241
    my $query;
246 242

  
247
  if ($form->{type} =~ /(check|receipt)/) {
248
    $query = qq|DELETE FROM status WHERE spoolfile = ?|;
249
  } else {
250
    $query =
251
      qq|UPDATE status SET spoolfile = NULL, printed = '1' | .
252
      qq|WHERE spoolfile = ?|;
253
  }
254
  my $sth = $dbh->prepare($query) || $form->dberror($query);
255

  
256
  foreach my $i (1 .. $form->{rowcount}) {
257
    if ($form->{"checked_$i"}) {
258
      $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query);
259
      $sth->finish;
243
    if ($form->{type} =~ /(check|receipt)/) {
244
      $query = qq|DELETE FROM status WHERE spoolfile = ?|;
245
    } else {
246
      $query =
247
        qq|UPDATE status SET spoolfile = NULL, printed = '1' | .
248
        qq|WHERE spoolfile = ?|;
260 249
    }
261
  }
250
    my $sth = $dbh->prepare($query) || $form->dberror($query);
262 251

  
263
  # commit
264
  my $rc = $dbh->commit;
265
  $dbh->disconnect;
252
    foreach my $i (1 .. $form->{rowcount}) {
253
      if ($form->{"checked_$i"}) {
254
        $sth->execute($form->{"spoolfile_$i"}) || $form->dberror($query);
255
        $sth->finish;
256
      }
257
    }
266 258

  
267
  if ($rc) {
268 259
    foreach my $i (1 .. $form->{rowcount}) {
269 260
      if ($form->{"checked_$i"}) {
270 261
        unlink(qq|$spool/$form->{"spoolfile_$i"}|);
271 262
      }
272 263
    }
273
  }
264
  });
274 265

  
275 266
  $main::lxdebug->leave_sub();
276

  
277
  return $rc;
267
  return 1;
278 268
}
279 269

  
280 270
sub print_spool {
......
285 275
  my $spool = $::lx_office_conf{paths}->{spool};
286 276

  
287 277
  # connect to database
288
  my $dbh = $form->dbconnect($myconfig);
278
  my $dbh = SL::DB->client->dbh;
289 279

  
290 280
  my $query =
291 281
    qq|UPDATE status SET printed = '1' | .
......
316 306
    }
317 307
  }
318 308

  
319
  $dbh->disconnect;
320

  
321 309
  $main::lxdebug->leave_sub();
322 310
}
323 311

  

Auch abrufbar als: Unified diff