' . "\n"
. '$sql = "' . $queryBase . '";' . "\n"
. '';
} elseif ($queryTooBig) {
$queryBase = '' . "\n"
. htmlspecialchars($queryBase, ENT_COMPAT) . '';
} else {
$queryBase = self::formatSql($queryBase);
}
// Prepares links that may be displayed to edit/explain the query
// (don't go to default pages, we must go to the page
// where the query box is available)
// Basic url query part
$urlParams = [];
if (! isset($GLOBALS['db'])) {
$GLOBALS['db'] = '';
}
if (strlen($GLOBALS['db']) > 0) {
$urlParams['db'] = $GLOBALS['db'];
if (strlen($GLOBALS['table']) > 0) {
$urlParams['table'] = $GLOBALS['table'];
$editLinkRoute = '/table/sql';
} else {
$editLinkRoute = '/database/sql';
}
} else {
$editLinkRoute = '/server/sql';
}
// Want to have the query explained
// but only explain a SELECT (that has not been explained)
/* SQL-Parser-Analyzer */
$explainLink = '';
$isSelect = preg_match('@^SELECT[[:space:]]+@i', $sqlQuery);
if (! empty($config->settings['SQLQuery']['Explain']) && ! $queryTooBig) {
$explainParams = $urlParams;
if ($isSelect) {
$explainParams['sql_query'] = 'EXPLAIN ' . $sqlQuery;
$explainLink = '' . __('Static analysis:') . '
'; $errorMessage .= '' . sprintf( __('%d errors were found during analysis.'), count($errors), ) . '
'; $errorMessage .= '' . __('SQL query:') . '' . self::showCopyToClipboard( $sqlQuery, ) . "\n"; $formattedSqlToLower = mb_strtolower($formattedSql); // TODO: Show documentation for all statement types. if (mb_strstr($formattedSqlToLower, 'select')) { // please show me help to the error on select $errorMessage .= MySQLDocumentation::show('SELECT'); } if ($isModifyLink) { $urlParams = ['sql_query' => $sqlQuery, 'show_query' => 1]; if (strlen($GLOBALS['table']) > 0) { $urlParams['db'] = $GLOBALS['db']; $urlParams['table'] = $GLOBALS['table']; $doEditGoto = ''; } elseif (strlen($GLOBALS['db']) > 0) { $urlParams['db'] = $GLOBALS['db']; $doEditGoto = ''; } else { $doEditGoto = ''; } $errorMessage .= $doEditGoto . self::getIcon('b_edit', __('Edit')) . ''; } $errorMessage .= '
' . "\n" . '' . "\n" . $formattedSql . "\n" . '
' . "\n"; } // Display server's error. if ($serverMessage !== '') { $serverMessage = (string) preg_replace("@((\015\012)|(\015)|(\012)){3,}@", "\n\n", $serverMessage); // Adds a link to MySQL documentation. $errorMessage .= '' . "\n" . ' ' . __('MySQL said: ') . '' . MySQLDocumentation::show('server-error-reference') . "\n" . '
' . "\n"; // The error message will be displayed within a CODE segment. // To preserve original formatting, but allow word-wrapping, // a couple of replacements are done. // All non-single blanks and TAB-characters are replaced with their // HTML-counterpart $serverMessage = str_replace( [' ', "\t"], [' ', ' '], $serverMessage, ); // Replace line breaks $serverMessage = nl2br($serverMessage); $errorMessage .= '' . $serverMessage . '
';
return sprintf($template, $title, $alt, $attributeString);
}
/**
* Displays a link, or a link with code to trigger POST request.
*
* POST is used in following cases:
*
* - URL is too long
* - URL components are over Suhosin limits
* - There is SQL query in the parameters
*
* @param string $urlPath the URL
* @param array' . "\n"
. htmlspecialchars($sqlQuery, ENT_COMPAT) . "\n"
. '';
}
/**
* This function processes the datatypes supported by the DB,
* as specified in Types->getColumns() and returns an HTML snippet that
* creates a drop-down list.
*
* @param string $selected The value to mark as selected in HTML mode
*/
public static function getSupportedDatatypes(string $selected): string
{
// NOTE: the SELECT tag is not included in this snippet.
$retval = '';
$dbi = DatabaseInterface::getInstance();
foreach ($dbi->types->getColumns() as $key => $value) {
if (is_array($value)) {
$retval .= '';
continue;
}
$isLengthRestricted = Compatibility::isIntegersSupportLength($value, '2', $dbi);
$retval .= sprintf(
'',
$isLengthRestricted ? 0 : 1,
$selected === $value ? 'selected="selected"' : '',
$dbi->types->getTypeDescription($value),
$value,
);
}
return $retval;
}
}