Changeset 1373

Show
Ignore:
Timestamp:
01/03/12 10:16:49 (18 months ago)
Author:
vakopian
Message:

code by alex, reviewed vakopian. To be changed: the way jquery is included. Fixes #129

Location:
framework/branches/2.0
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • framework/branches/2.0/assets/_core/php/profile.php

    r936 r1373  
    1515        $objProfileArray = QType::Cast($objProfileArray, QType::ArrayType); 
    1616        $intCount = count($objProfileArray); 
     17         
     18        function PrintExplainStatement($strOriginalQuery) { 
     19                global $intDatabaseIndex; 
     20                if (substr_count($strOriginalQuery, "AUTOCOMMIT=1") > 0) { 
     21                        return null;  
     22                } 
     23                $result = ""; 
     24                 
     25                $objDb = QApplication::$Database[$intDatabaseIndex]; 
     26                $objDbResult = $objDb->ExplainStatement($strOriginalQuery); 
     27                if (!$objDbResult) { 
     28                        return ""; 
     29                } 
     30                 
     31                $result .= "<table class='explainTable' border=1>"; 
     32                $headersShown = false; 
     33                while ($mixRow = $objDbResult->FetchArray()) { 
     34                        if (!$headersShown) { 
     35                                $result .= "<thead class='header'>"; 
     36                                foreach ($mixRow as $key=>$value) { 
     37                                        if (!is_numeric($key)) { 
     38                                                $result .= "<td>" . $key . "</td>"; 
     39                                                $headersShown = true; 
     40                                        } 
     41                                } 
     42                                $result .= '</thead>'; 
     43                        } 
     44                        $result .= "<tr>"; 
     45                        foreach ($mixRow as $key=>$value) { 
     46                                        if (!is_numeric($key)) { 
     47                                                $result .= "<td>" . $value . "</td>"; 
     48                                        } 
     49                        } 
     50                        $result .= "</tr>"; 
     51                } 
     52                $result .= "</table>"; 
     53                return $result; 
     54        } 
    1755?> 
    1856<!DOCTYPE html> 
     
    2159        <title>QCubed Development Framework - Database Profiling Tool</title> 
    2260        <style type="text/css">@import url("<?php _p(__VIRTUAL_DIRECTORY__ . __CSS_ASSETS__); ?>/corepage.css");</style> 
     61        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
    2362        <script type="text/javascript"> 
    24                 function Toggle(strWhatId, strButtonId) { 
     63                function Toggle(strWhatId) { 
    2564                        var obj = document.getElementById(strWhatId); 
    26                         var objButton = document.getElementById(strButtonId); 
     65                        var objButton = document.getElementById("button" + strWhatId); 
    2766 
    2867                        if (obj && objButton) { 
    2968                                if (obj.style.display == "block") { 
    3069                                        obj.style.display = "none"; 
    31                                         objButton.innerHTML = "Show"; 
    32                                 } 
     70                                        objButton.innerHTML = objButton.innerHTML.replace("Hide", "Show"); 
     71                                } 
     72                                 
    3373                                else { 
    3474                                        obj.style.display = "block"; 
    35                                         objButton.innerHTML = "Hide"; 
     75                                        objButton.innerHTML = objButton.innerHTML.replace("Show", "Hide"); 
    3676                                } 
    3777                        } 
     
    4080 
    4181                function ShowAll() { 
    42                         for (var intIndex = 1; intIndex <= <?php _p($intCount); ?>; intIndex++) { 
    43                                 var objQuery = document.getElementById('query' + intIndex); 
    44                                 var objButton = document.getElementById('button' + intIndex); 
    45                                 objQuery.style.display = "block"; 
    46                                 objButton.innerHTML = "Hide"; 
    47                         } 
     82                        jQuery(".querySection, .explainSection").each(function() { 
     83                                if ($(this).css('display') == "none") { 
     84                                        Toggle(this.id); 
     85                                } 
     86                        }); 
     87 
    4888                        return false; 
    4989                } 
    5090 
    5191                function HideAll() { 
    52                         for (var intIndex = 1; intIndex <= <?php _p($intCount); ?>; intIndex++) { 
    53                                 var objQuery = document.getElementById('query' + intIndex); 
    54                                 var objButton = document.getElementById('button' + intIndex); 
    55                                 objQuery.style.display = "none"; 
    56                                 objButton.innerHTML = "Show"; 
    57                         } 
     92                        jQuery(".querySection, .explainSection").each(function() { 
     93                                if ($(this).css('display') == "block") { 
     94                                        Toggle(this.id); 
     95                                } 
     96                        }); 
    5897                        return false; 
    5998                } 
    6099        </script> 
     100        <style> 
     101                .explainTable { 
     102                        border: 1px solid black;  
     103                        border-collapse:collapse; 
     104                        margin-top: 5px; 
     105                } 
     106                .explainTable td { 
     107                        padding: 4px; 
     108                } 
     109                .explainTable .header td { 
     110                        background: #CCC; 
     111                        font-weight: bold; 
     112                } 
     113        </style> 
    61114</head> 
    62115<body> 
     
    115168                        <span class="function"> 
    116169                                Called by <?php _p($strClass . $strType . $strFunction . '(' . implode(', ', $objArgs) . ')'); ?> 
    117                                 <a href="#" onClick="return Toggle('query<?php _p($intIndex); ?>', 'button<?php _p($intIndex); ?>')" id="button<?php _p($intIndex); ?>" class="smallbutton"> 
    118                                         Show 
    119                                 </a> 
    120170                        </span>&nbsp;&nbsp;<br/> 
    121171                        <span class="function_details"> 
    122172                                <b>File: </b><?php _p($strFile); ?>; &nbsp;&nbsp;<b>Line: </b><?php _p($strLine); ?> 
    123173                        </span> 
    124                         <pre id="query<?php _p($intIndex); ?>" style="display: none"><code><?php _p($strQuery); ?></code></pre> 
    125174<?php 
    126175                        //mark slow query - those that take over 1 second 
     
    130179                                echo'<div class="time">'; 
    131180                        printf("Query took %.1f ms", $dblTimeInfo * 1000); 
     181?> 
     182                        <?php $explainStatement = PrintExplainStatement($strQuery); ?> 
     183                        <a href="#" onClick="return Toggle('query<?php _p($intIndex); ?>')" id="buttonquery<?php _p($intIndex); ?>" class="queryButton smallbutton"> 
     184                                Show SQL 
     185                        </a> 
     186                        <?php if ($explainStatement) { ?> 
     187                        &nbsp;&nbsp; 
     188                        <a href="#" onClick="return Toggle('explain<?php _p($intIndex); ?>')" id="buttonexplain<?php _p($intIndex); ?>" class="explainButton smallbutton"> 
     189                                Show EXPLAIN statement 
     190                        </a> 
     191                        <?php } ?> 
     192                         
     193                        <pre id="query<?php _p($intIndex); ?>" style="display: none" class="querySection"><code><?php _p($strQuery); ?></code></pre> 
     194                        <div id="explain<?php _p($intIndex); ?>" style="display: none" class="explainSection"><?php echo $explainStatement; ?></div>                             
     195<?php                    
    132196                        echo '</div>'; 
    133197?> 
  • framework/branches/2.0/includes/qcubed/_core/database/QMySqliDatabase.class.php

    r1368 r1373  
    381381                                throw new Exception("Invalid Table Description"); 
    382382                } 
     383 
     384                public function ExplainStatement($sql) { 
     385                        return $this->Query("EXPLAIN " . $sql); 
     386                } 
    383387        } 
    384388 
  • framework/branches/2.0/includes/qcubed/_core/database/QOracleDatabase.class.php

    r1368 r1373  
    567567                throw new Exception("Invalid Table Description"); 
    568568        } 
     569 
     570        public function ExplainStatement($sql) { 
     571                return $this->Query("EXPLAIN PLAN FOR " . $sql); 
     572        } 
    569573} 
    570574 
  • framework/branches/2.0/includes/qcubed/_core/database/QPostgreSqlDatabase.class.php

    r1368 r1373  
    420420                        return $objForeignKeyArray; 
    421421                } 
     422 
     423                public function ExplainStatement($sql) { 
     424                        return $this->Query("EXPLAIN " . $sql); 
     425                } 
    422426        } 
    423427 
  • framework/branches/2.0/includes/qcubed/_core/framework/QDatabaseBase.class.php

    r1370 r1373  
    391391                        } 
    392392                } 
     393 
     394                /** 
     395                 * Executes the explain statement for a given query and returns the output without any transformation. 
     396                 * If the database adapter does not support EXPLAIN statements, returns null. 
     397                 * 
     398                 * @param $strSql 
     399                 */ 
     400                public function ExplainStatement($sql) { 
     401                        return null; 
     402                } 
    393403        } 
    394404