@@ -407,18 +407,16 @@ public static function getMessage(
407407
408408 if ($ sqlQuery === null ) {
409409 if (! empty ($ GLOBALS ['display_query ' ])) {
410- $ sqlQuery = $ GLOBALS ['display_query ' ];
411- } elseif (! empty ($ GLOBALS ['unparsed_sql ' ])) {
412- $ sqlQuery = $ GLOBALS ['unparsed_sql ' ];
410+ $ sqlQuery = (string ) $ GLOBALS ['display_query ' ];
413411 } elseif (! empty ($ GLOBALS ['sql_query ' ])) {
414- $ sqlQuery = $ GLOBALS ['sql_query ' ];
412+ $ sqlQuery = ( string ) $ GLOBALS ['sql_query ' ];
415413 } else {
416414 $ sqlQuery = '' ;
417415 }
418416 }
419417
420418 $ config = Config::getInstance ();
421- $ renderSql = $ config ->settings ['ShowSQL ' ] == true && ! empty ( $ sqlQuery) && $ sqlQuery !== '; ' ;
419+ $ renderSql = $ config ->settings ['ShowSQL ' ] == true && $ sqlQuery !== '' && $ sqlQuery !== '; ' ;
422420
423421 if (isset ($ GLOBALS ['using_bookmark_message ' ])) {
424422 $ retval .= $ GLOBALS ['using_bookmark_message ' ]->getDisplay ();
@@ -455,34 +453,19 @@ public static function getMessage(
455453 $ retval .= ' ' . $ message ->getMessage () . "\n" ;
456454 $ retval .= '</div> ' . "\n" ;
457455
458- $ queryTooBig = false ;
459-
460- $ queryLength = mb_strlen ($ sqlQuery );
461- if ($ queryLength > $ config ->settings ['MaxCharactersInDisplayedSQL ' ]) {
462- // when the query is large (for example an INSERT of binary
463- // data), the parser chokes; so avoid parsing the query
464- $ queryTooBig = true ;
465- $ queryBase = mb_substr ($ sqlQuery , 0 , $ config ->settings ['MaxCharactersInDisplayedSQL ' ]) . '[...] ' ;
466- } else {
467- $ queryBase = $ sqlQuery ;
468- }
469-
470456 // Html format the query to be displayed
471457 // If we want to show some sql code it is easiest to create it here
472458 /* SQL-Parser-Analyzer */
473459
474460 if (! empty ($ GLOBALS ['show_as_php ' ])) {
475461 $ newLine = '\\n"<br> ' . "\n" . ' . " ' ;
476- $ queryBase = htmlspecialchars (addslashes ($ queryBase ));
462+ $ queryBase = htmlspecialchars (addslashes ($ sqlQuery ));
477463 $ queryBase = preg_replace ('/((\015\012)|(\015)|(\012))/ ' , $ newLine , $ queryBase );
478464 $ queryBase = '<code class="php" dir="ltr"><pre> ' . "\n"
479465 . '$sql = " ' . $ queryBase . '"; ' . "\n"
480466 . '</pre></code> ' ;
481- } elseif ($ queryTooBig ) {
482- $ queryBase = '<code class="sql" dir="ltr"><pre> ' . "\n"
483- . htmlspecialchars ($ queryBase , ENT_COMPAT ) . '</pre></code> ' ;
484467 } else {
485- $ queryBase = self ::formatSql ($ queryBase );
468+ $ queryBase = self ::formatSql ($ sqlQuery , true );
486469 }
487470
488471 // Prepares links that may be displayed to edit/explain the query
@@ -507,6 +490,7 @@ public static function getMessage(
507490 // but only explain a SELECT (that has not been explained)
508491 /* SQL-Parser-Analyzer */
509492 $ explainLink = '' ;
493+ $ queryTooBig = mb_strlen ($ sqlQuery ) > $ config ->settings ['MaxCharactersInDisplayedSQL ' ];
510494 $ isSelect = preg_match ('@^SELECT[[:space:]]+@i ' , $ sqlQuery );
511495 if (! empty ($ config ->settings ['SQLQuery ' ]['Explain ' ]) && ! $ queryTooBig ) {
512496 $ explainParams = $ urlParams ;
@@ -1085,8 +1069,6 @@ public static function getListNavigator(
10851069 * @param bool $truncate truncate the query if it is too long
10861070 *
10871071 * @return string the formatted sql
1088- *
1089- * @global array $cfg the configuration array
10901072 */
10911073 public static function formatSql (string $ sqlQuery , bool $ truncate = false ): string
10921074 {
0 commit comments