From: Mr. E23 Date: Tue, 18 Nov 2003 23:43:41 +0000 (+0000) Subject: Changed the way SQL queries are logged by profiling X-Git-Tag: 1.1.0~142 X-Git-Url: https://git.cyclocoop.org/%7B%24admin_url%7Dmembres/fiche.php?a=commitdiff_plain;h=2044513a3611cc524aa402d6a527b0aac0b8abba;p=lhc%2Fweb%2Fwiklou.git Changed the way SQL queries are logged by profiling --- diff --git a/includes/DatabaseFunctions.php b/includes/DatabaseFunctions.php index d753a016d9..753d2c8109 100644 --- a/includes/DatabaseFunctions.php +++ b/includes/DatabaseFunctions.php @@ -95,7 +95,11 @@ function wfEmergencyAbort( $msg = "" ) { function wfQuery( $sql, $db, $fname = "" ) { global $wgLastDatabaseQuery, $wgOut, $wgDebugDumpSql; - $profName = "wfQuery(\"" . strtr( substr($sql, 0, 80 ), "\t\n\r", " " ) . "...\")"; + + # wfGeneralizeSQL will probably cut down the query to reasonable + # logging size most of the time. The substr is really just a sanity check. + $profName = "wfQuery: " . substr( wfGeneralizeSQL( $sql ), 0, 255 ); + wfProfileIn( $profName ); if ( !is_numeric( $db ) ) { @@ -191,6 +195,18 @@ function wfInvertTimestamp( $ts ) { ); } +# Removes most variables from an SQL query and replaces them with X or N for numbers. +# It's only slightly flawed. Don't use for anything important. +function wfGeneralizeSQL( $sql ) +{ + # This could be done faster with some arrays and a single preg_replace, + # but this show more clearly what's going on. + $sql = preg_replace ( "/-?\d+/" , "N", $sql); + $sql = preg_replace ( "/([\'\"]).+?[^\\\\]\\1/", "\\1X\\1", $sql); + $sql = preg_replace ( "/\s+/", " ", $sql); + return $sql; +} + function wfFieldExists( $table, $field ) { $fname = "wfFieldExists";