value of informative entries to display
* @param $query SMWQuery or null, if given add basic data about this query as well
*
* @return string
*/
public static function getStringFrom( $storeName, array $entries, Query $query = null ) {
if ( $query instanceof Query ) {
$preEntries = [];
$preEntries['ASK Query'] = '
' . str_replace( '[', '[', $query->getDescription()->getQueryString() ) . '
';
$entries = array_merge( $preEntries, $entries );
$entries['Query Metrics'] = 'Query-Size:' . $query->getDescription()->getSize() . '
' .
'Query-Depth:' . $query->getDescription()->getDepth();
$errors = '';
$queryErrors = ProcessingErrorMsgHandler::normalizeAndDecodeMessages(
$query->getErrors()
);
foreach ( $queryErrors as $error ) {
$errors .= $error . '
';
}
if ( $errors === '' ) {
$errors = 'None';
}
$entries['Errors and Warnings'] = $errors;
}
$result = '' .
"
$storeName debug output
";
foreach ( $entries as $header => $information ) {
$result .= "
$header
";
if ( $information !== '' ) {
$result .= "$information";
}
}
$result .= '
';
return $result;
}
/**
* @since 2.5
*
* @param string $type
* @param array $rows
*
* @return string
*/
public static function prettifyExplain( $type, $res ) {
$output = '';
// https://dev.mysql.com/doc/refman/5.0/en/explain-output.html
if ( $type === 'mysql' ) {
$output .= '' .
'
' .
'ID | '.
'select_type | '.
'table | '.
'type | '.
'possible_keys | '.
'key | '.
'key_len | '.
'ref | '.
'rows | '.
'Extra |
';
foreach ( $res as $row ) {
if ( isset( $row->EXPLAIN ) ) {
return '' . $row->EXPLAIN . '
';
}
$output .= "" . $row->id .
" | " . $row->select_type .
" | " . $row->table .
" | " . $row->type .
" | " . $row->possible_keys .
" | " . $row->key .
" | " . $row->key_len .
" | " . $row->ref .
" | " . $row->rows .
" | " . $row->Extra . " |
";
}
$output .= '
';
}
if ( $type === 'postgres' ) {
$output .= '';
foreach ( $res as $row ) {
foreach ( $row as $key => $value ) {
$output .= str_replace( [ ' ', '->' ], [ ' ', '└── ' ], $value ) .'
';
}
}
$output .= '
';
}
// SQlite doesn't support this
if ( $type === 'sqlite' ) {
$output .= 'Not supported.';
}
return $output;
}
/**
* @since 2.5
*
* @param string $sparql
*
* @return string
*/
public static function prettifySparql( $sparql ) {
$sparql = str_replace(
[
'[',
':',
' ',
'<',
'>'
],
[
'[',
':',
' ',
'<',
'>'
],
$sparql
);
return '' . $sparql . '
';
}
/**
* @since 2.5
*
* @param string $sql
* @param string $alias
*
* @return string
*/
public static function prettifySql( $sql, $alias ) {
$sql = str_replace(
[
"SELECT DISTINCT",
"FROM",
"INNER JOIN",
"LEFT OUTER JOIN",
"LEFT JOIN",
"RIGHT JOIN",
"WHERE",
"ORDER BY",
"GROUP BY",
"LIMIT",
"OFFSET",
"AND $alias.smw_",
",$alias.smw_",
"AND (",
"))",
"(("
],
[
"SELECT DISTINCT
",
"
FROM
",
"
INNER JOIN
",
"
LEFT OUTER JOIN
",
"
LEFT JOIN
",
"
RIGHT JOIN
",
"
WHERE
",
"
ORDER BY
",
"
GROUP BY
",
"
LIMIT
",
"
OFFSET
",
"
AND $alias.smw_",
",
$alias.smw_",
"
AND (",
")
)",
"(
("
],
$sql
);
return '' . $sql . '
';
}
}