Add $wgDebugDumpSqlLength
authorBrad Jorsch <bjorsch@wikimedia.org>
Fri, 27 Jun 2014 14:18:56 +0000 (10:18 -0400)
committerAnomie <bjorsch@wikimedia.org>
Wed, 23 Jul 2014 11:15:49 +0000 (11:15 +0000)
When $wgDebugDumpSql is set, the logged queries are truncated to 500
bytes. This is often not enough if you're wanting to actually debug
the queries instead of just seeing that queries were executed.

Change-Id: Iad3abd20c11d647834aa5546a1a9c82916c6519f

includes/DefaultSettings.php
includes/db/Database.php

index 86b7533..4d248ac 100644 (file)
@@ -5000,6 +5000,13 @@ $wgDebugDBTransactions = false;
  */
 $wgDebugDumpSql = false;
 
+/**
+ * Trim logged SQL queries to this many bytes. Set 0/false/null to do no
+ * trimming.
+ * @since 1.24
+ */
+$wgDebugDumpSqlLength = 500;
+
 /**
  * Map of string log group names to log destinations.
  *
index 3207a1b..e13c053 100644 (file)
@@ -1028,7 +1028,7 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
         *     for a successful read query, or false on failure if $tempIgnore set
         */
        public function query( $sql, $fname = __METHOD__, $tempIgnore = false ) {
-               global $wgUser, $wgDebugDBTransactions;
+               global $wgUser, $wgDebugDBTransactions, $wgDebugDumpSqlLength;
 
                $this->mLastQuery = $sql;
                if ( $this->isWriteQuery( $sql ) ) {
@@ -1102,7 +1102,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        static $cnt = 0;
 
                        $cnt++;
-                       $sqlx = substr( $commentedSql, 0, 500 );
+                       $sqlx = $wgDebugDumpSqlLength ? substr( $commentedSql, 0, $wgDebugDumpSqlLength )
+                               : $commentedSql;
                        $sqlx = strtr( $sqlx, "\t\n", '  ' );
 
                        $master = $isMaster ? 'master' : 'slave';
@@ -1133,7 +1134,8 @@ abstract class DatabaseBase implements IDatabase, DatabaseType {
                        if ( $this->ping() ) {
                                global $wgRequestTime;
                                wfDebug( "Reconnected\n" );
-                               $sqlx = substr( $commentedSql, 0, 500 );
+                               $sqlx = $wgDebugDumpSqlLength ? substr( $commentedSql, 0, $wgDebugDumpSqlLength )
+                                       : $commentedSql;
                                $sqlx = strtr( $sqlx, "\t\n", '  ' );
                                $elapsed = round( microtime( true ) - $wgRequestTime, 3 );
                                if ( $elapsed < 300 ) {