Connection: error handling fixes
gitea/php-vn-lib/pipeline/head This commit looks good
Details
gitea/php-vn-lib/pipeline/head This commit looks good
Details
This commit is contained in:
parent
2ae2cad4e7
commit
4e8ab125c4
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
php-vn-lib (2.1.12) stable; urgency=low
|
||||
php-vn-lib (2.1.13) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
Loading…
Reference in New Issue