' . "\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'];
$editLink = Url::getFromRoute('/table/sql');
} else {
$editLink = Url::getFromRoute('/database/sql');
}
} else {
$editLink = Url::getFromRoute('/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($cfg['SQLQuery']['Explain']) && ! $queryTooBig) {
$explainParams = $urlParams;
if ($isSelect) {
$explainParams['sql_query'] = 'EXPLAIN ' . $sqlQuery;
$explainLink = ' [ '
. self::linkOrButton(
Url::getFromRoute('/import'),
$explainParams,
__('Explain SQL')
) . ' ]';
} elseif (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $sqlQuery)) {
$explainParams['sql_query'] = mb_substr($sqlQuery, 8);
$explainLink = ' [ '
. self::linkOrButton(
Url::getFromRoute('/import'),
$explainParams,
__('Skip Explain SQL')
) . ']';
}
}
$urlParams['sql_query'] = $sqlQuery;
$urlParams['show_query'] = 1;
// even if the query is big and was truncated, offer the chance
// to edit it (unless it's enormous, see linkOrButton() )
if (! empty($cfg['SQLQuery']['Edit']) && empty($GLOBALS['show_as_php'])) {
$editLink = ' [ '
. self::linkOrButton($editLink, $urlParams, __('Edit'))
. ' ]';
} else {
$editLink = '';
}
// Also we would like to get the SQL formed in some nice
// php-code
if (! empty($cfg['SQLQuery']['ShowAsPHP']) && ! $queryTooBig) {
if (! empty($GLOBALS['show_as_php'])) {
$phpLink = ' [ '
. self::linkOrButton(
Url::getFromRoute('/import'),
$urlParams,
__('Without PHP code')
)
. ' ]';
$phpLink .= ' [ '
. self::linkOrButton(
Url::getFromRoute('/import'),
$urlParams,
__('Submit query')
)
. ' ]';
} else {
$phpParams = $urlParams;
$phpParams['show_as_php'] = 1;
$phpLink = ' [ '
. self::linkOrButton(
Url::getFromRoute('/import'),
$phpParams,
__('Create PHP code')
)
. ' ]';
}
} else {
$phpLink = '';
}
// Refresh query
if (
! empty($cfg['SQLQuery']['Refresh'])
&& ! isset($GLOBALS['show_as_php']) // 'Submit query' does the same
&& preg_match('@^(SELECT|SHOW)[[:space:]]+@i', $sqlQuery)
) {
$refreshLink = Url::getFromRoute('/sql', $urlParams);
$refreshLink = ' [ '
. self::linkOrButton($refreshLink, $urlParams, __('Refresh')) . ' ]';
} else {
$refreshLink = '';
}
$retval .= '' . __('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($table) > 0) { $urlParams['db'] = $db; $urlParams['table'] = $table; $doEditGoto = ''; } elseif (strlen($db) > 0) { $urlParams['db'] = $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 . '
' . "\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($selected): string
{
global $dbi;
// NOTE: the SELECT tag is not included in this snippet.
$retval = '';
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;
}
}