From 4e8ab125c4dc87b10f9c8257b2afed25f12b539c Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Mon, 16 Jan 2023 10:23:24 +0100 Subject: [PATCH] Connection: error handling fixes --- db/connection.php | 40 +++++++++++++++++++++++----------------- debian/changelog | 2 +- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/db/connection.php b/db/connection.php index 8d3d76b..5992e44 100644 --- a/db/connection.php +++ b/db/connection.php @@ -277,11 +277,12 @@ class Connection { * @return mixed The value or %NULL if error */ function multiQuery($query, $params = NULL) { - $success = $this->conn->multi_query($this->renderDebug($query, $params)); - - if (!$success) - $this->checkError(); - + try { + $success = $this->conn->multi_query($this->renderDebug($query, $params)); + } catch (\Exception $err) { + $this->catchError($err); + } + if (!$success) $this->checkError(); return $success; } @@ -297,11 +298,12 @@ class Connection { } function storeResult() { - $result = $this->conn->store_result(); - - if (!$result) - $this->checkError(); - + try { + $result = $this->conn->store_result(); + } catch (\Exception $err) { + $this->catchError($err); + } + if (!$result) $this->checkError(); return $result; } @@ -310,22 +312,26 @@ class Connection { } function nextResult() { - $hasNext = $this->conn->next_result(); + try { + $hasNext = $this->conn->next_result(); + } catch (\Exception $err) { + $this->catchError($err); + } $this->checkError(); return $hasNext; } + function catchError($err) { + throw new Exception($err->getCode(), $err->getMessage()); + } + /** * Check if there has been an error in the last query or multiquery, * throwing a @Exception exception if any. */ function checkError() { - if ($this->conn->errno) { - if ($this->conn->errno != 1644) - throw new Exception($this->conn->errno, $this->conn->error); - else - throw new \Vn\Lib\UserException($this->conn->error, $this->conn->errno); - } + if ($this->conn->errno) + throw new Exception($this->conn->errno, $this->conn->error); } /** diff --git a/debian/changelog b/debian/changelog index 058231d..12cfe07 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -php-vn-lib (2.1.12) stable; urgency=low +php-vn-lib (2.1.13) stable; urgency=low * Initial Release.