From 28649d1feedf494c736da54defea6a56341cd035 Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Wed, 14 Sep 2016 21:31:25 +0200
Subject: [PATCH] more detailed handling of error modes

---
 lib/Redmine/DB/MySQL.pm | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/lib/Redmine/DB/MySQL.pm b/lib/Redmine/DB/MySQL.pm
index 78b912c..d52d2ed 100644
--- a/lib/Redmine/DB/MySQL.pm
+++ b/lib/Redmine/DB/MySQL.pm
@@ -86,7 +86,14 @@ sub get_all_x
 
   my $sth= $dbh->prepare($ss) or print $dbh->errstr;
   # print "sth=[$sth]\n";
-  $sth->execute(@v);
+  my $rc= $sth->execute(@v);
+  # print __LINE__, "rc=[$rc]\n";
+  unless (defined ($rc))
+  {
+    print __LINE__, " rc=[$rc] ", $dbh->errstr(), "\n";
+    print __LINE__, " caller: ", join (' ', caller()), "\n";
+    return undef;
+  }
 
   my $t= $self->table($table);
   my $tt= {};
@@ -240,7 +247,14 @@ sub insert
   print "ssi=[$ssi]\n";
   print "vals: ", join (',', @vals), "\n";
   my $sth= $dbh->prepare($ssi);
-  $sth->execute(@vals);
+  my $rc= $sth->execute(@vals);
+  unless (defined ($rc))
+  {
+    print __LINE__, " rc=[$rc] ", $dbh->errstr(), "\n";
+    print __LINE__, " caller: ", join (' ', caller()), "\n";
+    return undef;
+  }
+
   print "ERROR: ", $dbh->errstr() if ($dbh->err);
   $sth->finish();
 
@@ -288,8 +302,15 @@ sub update
   }
 
   my $sth= $dbh->prepare($ssu);
-  $sth->execute(@vals);
-  print "ERROR: ", $dbh->errstr() if ($dbh->err);
+  my $rc= $sth->execute(@vals);
+
+  unless (defined ($rc))
+  {
+    print __LINE__, " rc=[$rc] ", $dbh->errstr(), "\n";
+    print __LINE__, " caller: ", join (' ', caller()), "\n";
+    return undef;
+  }
+
   $sth->finish();
 }
 
-- 
GitLab