Commit 8cd45997 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixes #11325. SQL CALL() has never been used before. Should be fine now....

Fixes #11325. SQL CALL() has never been used before. Should be fine now. Unsupported: Multiple (like query_multi()) - only the first one will be returned.
parent 73a4b007
Pipeline #4034 passed with stages
in 6 minutes and 14 seconds
......@@ -86,7 +86,7 @@ class Database {
// DB Init
if ($dbInit !== false && $dbInit != '') {
$arr = explode(';', $dbInit);
foreach ($arr AS $sql) {
foreach ($arr as $sql) {
$sql = trim($sql);
if ('' != $sql) {
$this->sql($sql);
......@@ -253,6 +253,9 @@ class Database {
default:
throw new \DbException($specificMessage . "Unknown mode: $mode", ERROR_UNKNOWN_MODE);
}
$this->freeResult();
} elseif ($queryType === QUERY_TYPE_INSERT) {
$result = $stat[DB_INSERT_ID];
} else {
......@@ -416,6 +419,7 @@ class Database {
case 'SHOW':
case 'DESCRIBE':
case 'EXPLAIN':
case 'CALL':
if (false === ($result = $this->mysqli_stmt->get_result())) {
throw new \DbException(
json_encode([ERROR_MESSAGE_TO_USER => 'Error DB execute', ERROR_MESSAGE_TO_DEVELOPER => '[ mysqli: ' . $this->mysqli_stmt->errno . ' ] ' . $this->mysqli_stmt->error . $specificMessage]),
......@@ -449,7 +453,6 @@ class Database {
case 'ALTER':
case 'DROP':
case 'CREATE':
case 'CALL':
$queryType = QUERY_TYPE_CONTROL;
$stat[DB_AFFECTED_ROWS] = 0;
$count = $stat[DB_AFFECTED_ROWS];
......@@ -621,7 +624,7 @@ class Database {
}
/**
* Fetch all rows of the result as associative array.
* Fetch all rows of the result.
*
* mode:
* ROW_IMPLODE_ALL: Return string. All cells of all rows imploded to one string.
......@@ -638,6 +641,9 @@ class Database {
*
*/
private function fetchAll($mode = '', &$keys = array()) {
$result = null;
if ($this->mysqli_result == null || $this->mysqli_result == false) {
return false;
}
......@@ -648,12 +654,10 @@ class Database {
switch ($mode) {
case ROW_IMPLODE_ALL:
$str = "";
$result = "";
foreach ($this->mysqli_result->fetch_all(MYSQLI_NUM) as $row) {
$str .= implode($row);
$result .= implode($row);
}
return $str;
break;
case ROW_KEYS:
......@@ -663,12 +667,14 @@ class Database {
$keys[$ii] = $this->mysqli_result->fetch_field_direct($ii)->name;
}
return $this->mysqli_result->fetch_all(MYSQLI_NUM);
$result = $this->mysqli_result->fetch_all(MYSQLI_NUM);
break;
default:
return $this->mysqli_result->fetch_all(MYSQLI_ASSOC);
$result = $this->mysqli_result->fetch_all(MYSQLI_ASSOC);
}
return $result;
}
/**
......@@ -740,7 +746,7 @@ class Database {
private function getFieldDefinitionFromTable($table, $columnName) {
$tableDefinition = $this->getTableDefinition($table);
foreach ($tableDefinition AS $row) {
foreach ($tableDefinition as $row) {
if ($row["Field"] == $columnName) {
return $row;
}
......@@ -841,7 +847,7 @@ class Database {
if (!$this->existTable($table)) {
$sql = "CREATE TABLE $table (";
foreach ($columnDefinition AS $key => $value) {
foreach ($columnDefinition as $key => $value) {
$cols[] = "`" . $key . "` " . $value . " NOT NULL,";
}
$sql .= implode(',', $cols);
......@@ -1001,12 +1007,18 @@ class Database {
}
// discard all results: this is important - if missed, following calls on $mysqli will fail.
$this->freeResult();
}
/**
* Free all results. If there are multiple, free them all. Required at least for multi_query() (mysqli) and call() (mysql)
*/
private function freeResult() {
do {
if ($res = $this->mysqli->store_result()) {
$res->free();
}
} while ($this->mysqli->more_results() && $this->mysqli->next_result());
}
/**
......@@ -1049,7 +1061,7 @@ class Database {
$sql = 'SELECT `pathFileName` FROM `' . TABLE_NAME_SPLIT . '` WHERE `tableName`=? AND `xId`=?';
$data = $this->sql($sql, ROW_REGULAR, [$tableName, $xId]);
foreach ($data AS $row) {
foreach ($data as $row) {
if (!empty($row['pathFileName']) && is_writable($row['pathFileName'])) {
HelperFile::unlink($row['pathFileName']);
}
......
Supports Markdown
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