Commit 1ed25e87 authored by Carsten  Rose's avatar Carsten Rose

Fixes #11075

parent b452306e
Pipeline #3726 passed with stages
in 4 minutes and 45 seconds
......@@ -175,13 +175,13 @@ class Database {
* Else an exception. ROW_EXPECT_GE_1: Like 'ROW_REGULAR'. Throws an exception if there is an empty resultset.
* ROW_KEYS: Return 2-dimensional num(!) array. Every query row is one array row. $keys are the column names.
*
* @param $sql
* @param string $sql
* @param string $mode
* @param array $parameterArray
* @param string $specificMessage
* @param array $keys
* @param array $stat DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
* @param array $skipErrno
* @param array $skipErrno Array of ERRNO numbers, which should be skipped and not throw an error.
*
* @return array|int
* SELECT | SHOW | DESCRIBE | EXPLAIN: see $mode
......@@ -349,7 +349,7 @@ class Database {
* the query.
* @param array $stat DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
* @param string $specificMessage
* @param array $skipErrno
* @param array $skipErrno Array of ERRNO numbers, which should be skipped and not throw an error.
*
* @return int|mixed
* @throws \CodeException
......@@ -360,8 +360,6 @@ class Database {
$sqlLogMode = $this->isSqlModify($sql) ? SQL_LOG_MODE_MODIFY : SQL_LOG_MODE_ALL;
$errno = 0;
$result = 0;
$stat = array();
$errorMsg[ERROR_MESSAGE_TO_USER] = empty($specificMessage) ? 'SQL error' : $specificMessage;
......@@ -370,53 +368,44 @@ class Database {
$this->store->setVar(SYSTEM_SQL_PARAM_ARRAY, $parameterArray, STORE_SYSTEM);
}
// if ($specificMessage !== '') {
// $specificMessage = ' - ' . $specificMessage;
// }
// Logfile
$this->dbLog($sqlLogMode, $sql, $parameterArray);
if (false === ($this->mysqli_stmt = $this->mysqli->prepare($sql))) {
if ($skipErrno === array() && false === array_search($this->mysqli->errno, $skipErrno)) {
$errno = $this->mysqli->errno;
if ($skipErrno === array() && false === array_search($errno, $skipErrno)) {
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
$errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = $this->getSqlHint($sql, $this->mysqli->error);
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli->errno . ' ] ' . $this->mysqli->error;
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $errno . ' ] ' . $this->mysqli->error;
throw new \DbException(json_encode($errorMsg), ERROR_DB_PREPARE);
} else {
$errno = $this->mysqli->errno;
}
}
if (count($parameterArray) > 0) {
if (false === $this->prepareBindParam($parameterArray)) {
if ($skipErrno !== array() && false === array_search($this->mysqli->errno, $skipErrno)) {
$errno = $this->mysqli_stmt->errno;
if ($skipErrno === array() && false === array_search($errno, $skipErrno)) {
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
$errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = $this->getSqlHint($sql, $this->mysqli->error);
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error;
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $errno . ' ] ' . $this->mysqli_stmt->error;
throw new \DbException(json_encode($errorMsg), ERROR_DB_BIND);
} else {
$errno = $this->mysqli->errno;
}
}
}
if (false === $this->mysqli_stmt->execute()) {
if ($skipErrno !== array() && false === array_search($this->mysqli->errno, $skipErrno)) {
$errno = $this->mysqli->errno;
if ($skipErrno === array() || false === array_search($errno, $skipErrno)) {
$this->dbLog(SQL_LOG_MODE_ERROR, $sql, $parameterArray);
$errorMsg[ERROR_MESSAGE_TO_DEVELOPER] = $this->getSqlHint($sql, $this->mysqli->error);
$errorMsg[ERROR_MESSAGE_OS] = '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error;
throw new \DbException(json_encode($errorMsg), ERROR_DB_EXECUTE);
} else {
$errno = $this->mysqli->errno;
}
}
$msg = '';
$count = 0;
if ($errno === 0) {
$command = strtoupper(explode(' ', $sql, 2)[0]);
} else {
......
......@@ -242,6 +242,17 @@ class DatabaseTest extends AbstractDatabaseTest {
$this->dbArray[DB_INDEX_DEFAULT]->sql('some garbage');
}
/**
* @expectedException DbException
*
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
*/
public function testReportException() {
$this->dbArray[DB_INDEX_DEFAULT]->sql("INSERT INTO Person (`id`,`name`) VALUES (1,'test')");
}
/**
* Check to skip mysqli errno 1060
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment