Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/phpmyadmin/phpmyadmin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Desportes <williamdes@wdes.fr>2020-05-16 15:38:52 +0300
committerWilliam Desportes <williamdes@wdes.fr>2020-05-16 15:39:00 +0300
commit1cc7f7801266340f200c23cfd7403106265ac2fa (patch)
tree4d267f1eef04646ad4beb61cf24e65ec21b920ee /libraries
parentf2d349df407a80dd3370afe79430ac364161c65d (diff)
Split part of the logic of getQueryFromRequest into processFunctionSpecificParameters
Signed-off-by: William Desportes <williamdes@wdes.fr>
Diffstat (limited to 'libraries')
-rw-r--r--libraries/classes/Database/Routines.php111
1 files changed, 64 insertions, 47 deletions
diff --git a/libraries/classes/Database/Routines.php b/libraries/classes/Database/Routines.php
index ebd25f59d1..fc93f17db3 100644
--- a/libraries/classes/Database/Routines.php
+++ b/libraries/classes/Database/Routines.php
@@ -1183,13 +1183,75 @@ class Routines
}
/**
+ * Set the found errors and build the query
+ *
+ * @param string $query The existing query
+ * @param bool $warnedAboutLength If the length warning was given
+ */
+ private function processFunctionSpecificParameters(
+ string $query,
+ bool $warnedAboutLength
+ ): string {
+ global $errors, $dbi;
+
+ $itemReturnType = $_POST['item_returntype'] ?? null;
+
+ if (! empty($itemReturnType)
+ && in_array(
+ $itemReturnType,
+ Util::getSupportedDatatypes()
+ )
+ ) {
+ $query .= 'RETURNS ' . $itemReturnType;
+ } else {
+ $errors[] = __('You must provide a valid return type for the routine.');
+ }
+ if (! empty($_POST['item_returnlength'])
+ && ! preg_match(
+ '@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|'
+ . 'MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT|SERIAL|BOOLEAN)$@i',
+ $itemReturnType
+ )
+ ) {
+ $query .= '(' . $_POST['item_returnlength'] . ')';
+ } elseif (empty($_POST['item_returnlength'])
+ && preg_match(
+ '@^(ENUM|SET|VARCHAR|VARBINARY)$@i',
+ $itemReturnType
+ )
+ ) {
+ if (! $warnedAboutLength) {
+ $errors[] = __(
+ 'You must provide length/values for routine parameters'
+ . ' of type ENUM, SET, VARCHAR and VARBINARY.'
+ );
+ }
+ }
+ if (! empty($_POST['item_returnopts_text'])) {
+ if ($dbi->types->getTypeClass($itemReturnType) == 'CHAR') {
+ $query .= ' CHARSET '
+ . mb_strtolower($_POST['item_returnopts_text']);
+ }
+ }
+ if (! empty($_POST['item_returnopts_num'])) {
+ if ($dbi->types->getTypeClass($itemReturnType) == 'NUMBER') {
+ $query .= ' '
+ . mb_strtoupper($_POST['item_returnopts_num']);
+ }
+ }
+ $query .= ' ';
+
+ return $query;
+ }
+
+ /**
* Composes the query necessary to create a routine from an HTTP request.
*
* @return string The CREATE [ROUTINE | PROCEDURE] query.
*/
public function getQueryFromRequest(): string
{
- global $errors, $dbi;
+ global $errors;
$itemType = $_POST['item_type'] ?? '';
$itemDefiner = $_POST['item_definer'] ?? '';
@@ -1265,52 +1327,7 @@ class Routines
$query .= '(' . $params . ') ';
if ($itemType == 'FUNCTION') {
- $itemReturnType = $_POST['item_returntype'] ?? null;
-
- if (! empty($itemReturnType)
- && in_array(
- $itemReturnType,
- Util::getSupportedDatatypes()
- )
- ) {
- $query .= 'RETURNS ' . $itemReturnType;
- } else {
- $errors[] = __('You must provide a valid return type for the routine.');
- }
- if (! empty($_POST['item_returnlength'])
- && ! preg_match(
- '@^(DATE|DATETIME|TIME|TINYBLOB|TINYTEXT|BLOB|TEXT|'
- . 'MEDIUMBLOB|MEDIUMTEXT|LONGBLOB|LONGTEXT|SERIAL|BOOLEAN)$@i',
- $itemReturnType
- )
- ) {
- $query .= '(' . $_POST['item_returnlength'] . ')';
- } elseif (empty($_POST['item_returnlength'])
- && preg_match(
- '@^(ENUM|SET|VARCHAR|VARBINARY)$@i',
- $itemReturnType
- )
- ) {
- if (! $warnedAboutLength) {
- $errors[] = __(
- 'You must provide length/values for routine parameters'
- . ' of type ENUM, SET, VARCHAR and VARBINARY.'
- );
- }
- }
- if (! empty($_POST['item_returnopts_text'])) {
- if ($dbi->types->getTypeClass($itemReturnType) == 'CHAR') {
- $query .= ' CHARSET '
- . mb_strtolower($_POST['item_returnopts_text']);
- }
- }
- if (! empty($_POST['item_returnopts_num'])) {
- if ($dbi->types->getTypeClass($itemReturnType) == 'NUMBER') {
- $query .= ' '
- . mb_strtoupper($_POST['item_returnopts_num']);
- }
- }
- $query .= ' ';
+ $query = $this->processFunctionSpecificParameters($query, $warnedAboutLength);
}
if (! empty($_POST['item_comment'])) {
$query .= "COMMENT '" . $this->dbi->escapeString($_POST['item_comment'])