use Data::Dumper;
use SL::DBUtils;
+use SL::DB;
use strict;
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
my ($where, @values);
$form->{item_list} = selectall_hashref_query($form, $dbh, $query, @values);
- $dbh->disconnect;
-
$main::lxdebug->leave_sub();
return scalar(@{ $form->{item_list} });
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
$form->{discount} /= 100;
}
do_query($form, $dbh, $query, @values);
- $dbh->disconnect;
-
$main::lxdebug->leave_sub();
}
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
my $query =
qq|SELECT pg.*, | .
map({ $form->{$_} = $ref->{$_} } keys(%{$ref}));
$sth->finish;
- $dbh->disconnect;
-
# also not orphaned if partsgroup is selected for a cvar filter
if ($form->{orphaned}) {
my $cvar_count = scalar( @{ SL::DB::PartsGroup->new(id => $form->{id})->custom_variable_configs } );
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
-
- my $table = $form->{type} eq "pricegroup" ? "pricegroup" : "partsgroup";
+ SL::DB->client->with_transaction(sub {
+ my $dbh = SL::DB->client->dbh;
- my $query = qq|DELETE FROM $table WHERE id = ?|;
- do_query($form, $dbh, $query, $form->{id});
+ my $table = $form->{type} eq "pricegroup" ? "pricegroup" : "partsgroup";
- $dbh->disconnect;
+ my $query = qq|DELETE FROM $table WHERE id = ?|;
+ do_query($form, $dbh, $query, $form->{id});
+ 1;
+ }) or do { die SL::DB->client->error };
$main::lxdebug->leave_sub();
}
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
my ($where, @values);
$form->{item_list} = selectall_hashref_query($form, $dbh, $query, @values);
- $dbh->disconnect;
-
$main::lxdebug->leave_sub();
return scalar(@{ $form->{item_list} });
my ($self, $myconfig, $form) = @_;
- # connect to database
- my $dbh = $form->dbconnect($myconfig);
- my $query;
-
- $form->{discount} /= 100;
+ SL::DB->client->with_transaction(sub {
+ my $dbh = SL::DB->client->dbh;
+ my $query;
- my @values = ($form->{pricegroup});
+ $form->{discount} /= 100;
- if ($form->{id}) {
- $query = qq|UPDATE pricegroup SET pricegroup = ? WHERE id = ? |;
- push(@values, $form->{id});
- } else {
- $query = qq|INSERT INTO pricegroup (pricegroup) VALUES (?)|;
- }
- do_query($form, $dbh, $query, @values);
+ my @values = ($form->{pricegroup});
- $dbh->disconnect;
+ if ($form->{id}) {
+ $query = qq|UPDATE pricegroup SET pricegroup = ? WHERE id = ? |;
+ push(@values, $form->{id});
+ } else {
+ $query = qq|INSERT INTO pricegroup (pricegroup) VALUES (?)|;
+ }
+ do_query($form, $dbh, $query, @values);
+ 1;
+ }) or do { die SL::DB->client->error };
$main::lxdebug->leave_sub();
}
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = SL::DB->client->dbh;
my $query = qq|SELECT id, pricegroup FROM pricegroup WHERE id = ?|;
my $sth = prepare_execute_query($form, $dbh, $query, $form->{id});
($form->{orphaned}) = selectrow_query($form, $dbh, $query, @values);
$form->{orphaned} = !$form->{orphaned};
- $dbh->disconnect;
-
$main::lxdebug->leave_sub();
}