From e8784e42ff819b1f4effd6c86eaadfe90b361a20 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 1 Aug 2016 11:01:46 +0200 Subject: [PATCH] Notes: single-dbh --- SL/Notes.pm | 43 ++++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/SL/Notes.pm b/SL/Notes.pm index 38959f429..d7d657ce4 100644 --- a/SL/Notes.pm +++ b/SL/Notes.pm @@ -4,6 +4,7 @@ package Notes; use SL::Common; use SL::DBUtils; +use SL::DB; use strict; @@ -16,24 +17,24 @@ sub save { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); - my ($query, @values); + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; + my ($query, @values); - if (!$params{id}) { - ($params{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('note_id')|); - $query = qq|INSERT INTO notes (created_by, trans_id, trans_module, subject, body, id) - VALUES ((SELECT id FROM employee WHERE login = ?), ?, ?, ?, ?, ?)|; - push @values, $::myconfig{login}, conv_i($params{trans_id}), $params{trans_module}; + if (!$params{id}) { + ($params{id}) = selectrow_query($form, $dbh, qq|SELECT nextval('note_id')|); + $query = qq|INSERT INTO notes (created_by, trans_id, trans_module, subject, body, id) + VALUES ((SELECT id FROM employee WHERE login = ?), ?, ?, ?, ?, ?)|; + push @values, $::myconfig{login}, conv_i($params{trans_id}), $params{trans_module}; - } else { - $query = qq|UPDATE notes SET subject = ?, body = ? WHERE id = ?|; - } + } else { + $query = qq|UPDATE notes SET subject = ?, body = ? WHERE id = ?|; + } - push @values, $params{subject}, $params{body}, conv_i($params{id}); + push @values, $params{subject}, $params{body}, conv_i($params{id}); - do_query($form, $dbh, $query, @values); - - $dbh->commit() unless ($params{dbh}); + do_query($form, $dbh, $query, @values); + }); $main::lxdebug->leave_sub(); @@ -71,14 +72,14 @@ sub delete { my $myconfig = \%main::myconfig; my $form = $main::form; - my $dbh = $params{dbh} || $form->get_standard_dbh($myconfig); - my $id = conv_i($params{id}); - - do_query($form, $dbh, qq|DELETE FROM follow_up_links WHERE follow_up_id IN (SELECT DISTINCT id FROM follow_ups WHERE note_id = ?)|, $id); - do_query($form, $dbh, qq|DELETE FROM follow_ups WHERE note_id = ?|, $id); - do_query($form, $dbh, qq|DELETE FROM notes WHERE id = ?|, $id); + SL::DB->client->with_transaction(sub { + my $dbh = $params{dbh} || SL::DB->client->dbh; + my $id = conv_i($params{id}); - $dbh->commit() unless ($params{dbh}); + do_query($form, $dbh, qq|DELETE FROM follow_up_links WHERE follow_up_id IN (SELECT DISTINCT id FROM follow_ups WHERE note_id = ?)|, $id); + do_query($form, $dbh, qq|DELETE FROM follow_ups WHERE note_id = ?|, $id); + do_query($form, $dbh, qq|DELETE FROM notes WHERE id = ?|, $id); + }); $main::lxdebug->leave_sub(); } -- 2.20.1