Connection: error handling fixes
gitea/php-vn-lib/pipeline/head This commit looks good Details

This commit is contained in:
Juan Ferrer 2023-01-16 10:23:24 +01:00
parent 2ae2cad4e7
commit 4e8ab125c4
2 changed files with 24 additions and 18 deletions

View File

@ -277,11 +277,12 @@ class Connection {
* @return mixed The value or %NULL if error * @return mixed The value or %NULL if error
*/ */
function multiQuery($query, $params = NULL) { function multiQuery($query, $params = NULL) {
$success = $this->conn->multi_query($this->renderDebug($query, $params)); try {
$success = $this->conn->multi_query($this->renderDebug($query, $params));
if (!$success) } catch (\Exception $err) {
$this->checkError(); $this->catchError($err);
}
if (!$success) $this->checkError();
return $success; return $success;
} }
@ -297,11 +298,12 @@ class Connection {
} }
function storeResult() { function storeResult() {
$result = $this->conn->store_result(); try {
$result = $this->conn->store_result();
if (!$result) } catch (\Exception $err) {
$this->checkError(); $this->catchError($err);
}
if (!$result) $this->checkError();
return $result; return $result;
} }
@ -310,22 +312,26 @@ class Connection {
} }
function nextResult() { function nextResult() {
$hasNext = $this->conn->next_result(); try {
$hasNext = $this->conn->next_result();
} catch (\Exception $err) {
$this->catchError($err);
}
$this->checkError(); $this->checkError();
return $hasNext; 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, * Check if there has been an error in the last query or multiquery,
* throwing a @Exception exception if any. * throwing a @Exception exception if any.
*/ */
function checkError() { function checkError() {
if ($this->conn->errno) { if ($this->conn->errno)
if ($this->conn->errno != 1644) throw new Exception($this->conn->errno, $this->conn->error);
throw new Exception($this->conn->errno, $this->conn->error);
else
throw new \Vn\Lib\UserException($this->conn->error, $this->conn->errno);
}
} }
/** /**

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
php-vn-lib (2.1.12) stable; urgency=low php-vn-lib (2.1.13) stable; urgency=low
* Initial Release. * Initial Release.