TYPO3 API  SVNRelease
index.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2004-2009 Kasper Skårhøj (kasperYYYY@typo3.com)
00006  *  (c) 2004-2009 Karsten Dambekalns (karsten@typo3.org)
00007  *  All rights reserved
00008  *
00009  *  This script is part of the TYPO3 project. The TYPO3 project is
00010  *  free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  The GNU General Public License can be found at
00016  *  http://www.gnu.org/copyleft/gpl.html.
00017  *
00018  *  This script is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *  GNU General Public License for more details.
00022  *
00023  *  This copyright notice MUST APPEAR in all copies of the script!
00024  ***************************************************************/
00025 
00026 /**
00027  * Module 'DBAL Debug' for the 'dbal' extension.
00028  *
00029  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00030  * @author  Karsten Dambekalns <karsten@typo3.org>
00031  */
00032 
00033 $LANG->includeLLFile('EXT:dbal/mod1/locallang.xml');
00034 $BE_USER->modAccess($MCONF, 1);
00035 
00036 
00037 /**
00038  * Script class; Backend module for DBAL extension
00039  *
00040  * @author  Kasper Skårhøj <kasper@typo3.com>
00041  * @author  Karsten Dambekalns <karsten@typo3.org>
00042  * @package TYPO3
00043  * @subpackage dbal
00044  */
00045 class tx_dbal_module1 extends t3lib_SCbase {
00046 
00047     /**
00048      * @var string
00049      */
00050     protected $thisScript;
00051 
00052     /**
00053      * Adds items to the ->MOD_MENU array. Used for the function menu selector.
00054      *
00055      * @return  void
00056      */
00057     public function menuConfig() {
00058         $this->MOD_MENU = array(
00059             'function' => array(
00060                 0 => $GLOBALS['LANG']->getLL('Debug_log'),
00061                 'info' => $GLOBALS['LANG']->getLL('Cached_info'),
00062                 'sqlcheck' => $GLOBALS['LANG']->getLL('SQL_check'),
00063             )
00064         );
00065         parent::menuConfig();
00066     }
00067 
00068     /**
00069      * Main function of the module. Write the content to $this->content
00070      *
00071      * @return  void
00072      */
00073     public function main() {
00074 
00075         $this->thisScript = 'mod.php?M=' . $this->MCONF['name'];
00076 
00077         // Clean up settings:
00078         $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
00079 
00080         // Draw the header
00081         $this->doc = t3lib_div::makeInstance('noDoc');
00082         $this->doc->backPath = $GLOBALS['BACK_PATH'];
00083         $this->doc->form = '<form action="" method="post">';
00084 
00085         // JavaScript
00086         $this->doc->JScode = $this->doc->wrapScriptTags('
00087                 script_ended = 0;
00088                 function jumpToUrl(URL) {   //
00089                     window.location.href = URL;
00090                 }
00091             ');
00092 
00093         // DBAL page title:
00094         $this->content .= $this->doc->startPage($GLOBALS['LANG']->getLL('title'));
00095         $this->content .= $this->doc->header($GLOBALS['LANG']->getLL('title'));
00096         $this->content .= $this->doc->spacer(5);
00097         $this->content .= $this->doc->section('', $this->doc->funcMenu('', t3lib_BEfunc::getFuncMenu(0, 'SET[function]', $this->MOD_SETTINGS['function'], $this->MOD_MENU['function'])));
00098 
00099         // Debug log:
00100         switch ($this->MOD_SETTINGS['function']) {
00101             case 'info':
00102                 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Cached_info'), $this->printCachedInfo());
00103                 break;
00104             case 'sqlcheck':
00105                 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('SQL_check'), $this->printSqlCheck());
00106                 break;
00107             case 0:
00108                 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Debug_log'), $this->printLogMgm());
00109                 break;
00110         }
00111 
00112         // ShortCut
00113         if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
00114             $this->content .= $this->doc->spacer(20) . $this->doc->section('', $this->doc->makeShortcutIcon('id', implode(',', array_keys($this->MOD_MENU)), $this->MCONF['name']));
00115         }
00116 
00117         $this->content .= $this->doc->spacer(10);
00118     }
00119 
00120     /**
00121      * Prints out the module HTML
00122      *
00123      * @return  string HTML output
00124      */
00125     public function printContent() {
00126         $this->content .= $this->doc->endPage();
00127         echo $this->content;
00128     }
00129 
00130     /**
00131      * Displays a form to check DBAL SQL methods and parse raw SQL.
00132      *
00133      * @return string HTML output
00134      */
00135     protected function printSqlCheck() {
00136         $input = t3lib_div::_GP('tx_dbal');
00137 
00138         $out = '
00139             <form name="sql_check" action="' . $this->thisScript . '" method="post" enctype="' . $GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'] . '">
00140             <script type="text/javascript">
00141 /*<![CDATA[*/
00142 function updateQryForm(s) {
00143     document.getElementById(\'tx-dbal-result\').style.display = \'none\';
00144     switch(s) {
00145     case \'SELECT\':
00146         document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
00147         document.getElementById(\'tx-dbal-qryfields\').style.display = \'table-row\';
00148         document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
00149         document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
00150         document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
00151         document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
00152         document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
00153         document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
00154         document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
00155         document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
00156     break;
00157     case \'INSERT\':
00158         document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
00159         document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
00160         document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'table-row\';
00161         document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
00162         document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
00163         document.getElementById(\'tx-dbal-qryinto\').style.display = \'table-row\';
00164         document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
00165         document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
00166         document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
00167         document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
00168     break;
00169     case \'UPDATE\':
00170         document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\';
00171         document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
00172         document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
00173         document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'table-row\';
00174         document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
00175         document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
00176         document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\';
00177         document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
00178         document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
00179         document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
00180         document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
00181     break;
00182     case \'DELETE\':
00183         document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
00184         document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
00185         document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
00186         document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
00187         document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
00188         document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
00189         document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
00190         document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
00191         document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
00192         document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
00193     break;
00194     }
00195 }
00196 /*]]>*/
00197                 </script>
00198         <table>
00199         <tr class="tableheader bgColor5"><th colspan="2">Easy SQL check</th></tr>
00200         <tr><td colspan="2">
00201         <select name="tx_dbal[QUERY]"size="1" onchange="updateQryForm(this.options[this.selectedIndex].value)">
00202          <option value="SELECT" ' . ($input['QUERY'] === 'SELECT' ? 'selected="selected"' : '') . '>SELECT</option>
00203          <option value="INSERT" ' . ($input['QUERY'] === 'INSERT' ? 'selected="selected"' : '') . '>INSERT</option>
00204          <option value="UPDATE" ' . ($input['QUERY'] === 'UPDATE' ? 'selected="selected"' : '') . '>UPDATE</option>
00205          <option value="DELETE" ' . ($input['QUERY'] === 'DELETE' ? 'selected="selected"' : '') . '>DELETE</option>
00206         </select>
00207         </td></tr>
00208         <tr id="tx-dbal-qryupdate" style="display:none;"><td></td><td><input name="tx_dbal[UPDATE]" value="' . $input['UPDATE'] . '" type="text" size="30" maxsize="100" /></td></tr>
00209         <tr id="tx-dbal-qryfields"><td></td><td><input name="tx_dbal[FIELDS]" value="' . $input['FIELDS'] . '" type="text" size="30" maxsize="100" /></td></tr>
00210         <tr id="tx-dbal-qryinsertvalues" style="display:none;"><td></td><td><textarea name="tx_dbal[INSERTVALUES]" cols="30" rows="4">' . $input['INSERTVALUES'] . '</textarea></td></tr>
00211         <tr id="tx-dbal-qryupdatevalues" style="display:none;"><th>SET</th><td><textarea name="tx_dbal[UPDATEVALUES]" cols="30" rows="4">' . $input['UPDATEVALUES'] . '</textarea></td></tr>
00212         <tr id="tx-dbal-qryfrom"><th>FROM</th><td><input name="tx_dbal[FROM]" value="' . $input['FROM'] . '" type="text" size="30" maxsize="100" /></td></tr>
00213         <tr id="tx-dbal-qryinto" style="display:none;"><th>INTO</th><td><input name="tx_dbal[INTO]" value="' . $input['INTO'] . '" type="text" size="30" maxsize="100" /></td></tr>
00214         <tr id="tx-dbal-qrywhere"><th>WHERE</th><td><input name="tx_dbal[WHERE]" value="' . $input['WHERE'] . '" type="text" size="30" maxsize="100" /></td></tr>
00215         <tr id="tx-dbal-qrygroup"><th>GROUP BY</th><td><input name="tx_dbal[GROUP]" value="' . $input['GROUP'] . '" type="text" size="30" maxsize="100" /></td></tr>
00216         <tr id="tx-dbal-qryorder"><th>ORDER BY</th><td><input name="tx_dbal[ORDER]" value="' . $input['ORDER'] . '" type="text" size="30" maxsize="100" /></td></tr>
00217         <tr id="tx-dbal-qrylimit"><th>LIMIT</th><td><input name="tx_dbal[LIMIT]" value="' . $input['LIMIT'] . '" type="text" size="30" maxsize="100" /></td></tr>
00218             <tr><td></td><td style="text-align:right;"><input type="submit" value="CHECK" /></td></tr>
00219             <script type="text/javascript">
00220 /*<![CDATA[*/
00221 updateQryForm(\'' . $input['QUERY'] . '\');
00222 /*]]>*/
00223                 </script>
00224             ';
00225 
00226         $out .= '<tr id="tx-dbal-result" class="bgColor4"><th>Result:</th><td>';
00227         switch ($input['QUERY']) {
00228             case 'SELECT':
00229                 $qry = $GLOBALS['TYPO3_DB']->SELECTquery($input['FIELDS'], $input['FROM'], $input['WHERE'], $input['GROUP'], $input['ORDER'], $input['LIMIT']);
00230                 break;
00231             case 'INSERT':
00232                 $qry = $GLOBALS['TYPO3_DB']->INSERTquery($input['INTO'], $this->createFieldsValuesArray($input['INSERTVALUES']));
00233                 break;
00234             case 'UPDATE':
00235                 $qry = $GLOBALS['TYPO3_DB']->UPDATEquery($input['UPDATE'], $input['WHERE'], $this->createFieldsValuesArray($input['UPDATEVALUES']));
00236                 break;
00237             case 'DELETE':
00238                 $qry = $GLOBALS['TYPO3_DB']->DELETEquery($input['FROM'], $input['WHERE']);
00239                 break;
00240         }
00241         $out .= '<pre>' . htmlspecialchars($qry) . '</pre></td></tr>';
00242 
00243         $out .= '
00244             <tr class="tableheader bgColor5"><th colspan="2">RAW SQL check</th></tr>
00245             <tr><td colspan="2" style="text-align:right;"><textarea name="tx_dbal[RAWSQL]" cols="60" rows="5">' . $input['RAWSQL'] . '</textarea><br /><input type="submit" value="CHECK" /></td></tr>';
00246         if (!empty($input['RAWSQL'])) {
00247             $out .= '<tr class="bgColor4">';
00248             $parseResult = $GLOBALS['TYPO3_DB']->SQLparser->parseSQL($input['RAWSQL']);
00249             if (is_array($parseResult)) {
00250                 $newQuery = $GLOBALS['TYPO3_DB']->SQLparser->compileSQL($parseResult);
00251                 $testResult = $GLOBALS['TYPO3_DB']->SQLparser->debug_parseSQLpartCompare($input['RAWSQL'], $newQuery);
00252                 if (!is_array($testResult)) {
00253                     $out .= '<td colspan="2">' . $newQuery;
00254                 } else {
00255                     $out .= '<td colspan="2">' . htmlspecialchars($testResult[0]) . '</td></tr>
00256                     <tr><th>Error:</th><td style="border:2px solid #f00;">Input query did not match the parsed and recompiled query exactly (not observing whitespace):<br />' . htmlspecialchars($testResult[1]);
00257                 }
00258             } else {
00259                 $out .= '<th>Result:</th><td style="border:2px solid #f00;">' . $parseResult;
00260             }
00261             $out .= '</td></tr>';
00262         }
00263 
00264         $out .= '</table></form>';
00265         return $out;
00266     }
00267 
00268     /**
00269      * Parses a very simple text format into an array.
00270      *
00271      * Each line is seen as a key/value pair that is exploded at =. This is used
00272      * in the simple SQL check to input values for INSERT and UPDATE statements.
00273      *
00274      * @param string $in String to parse into key/value array.
00275      * @return array Array created from the input string.
00276      */
00277     protected function createFieldsValuesArray($in) {
00278         $ret = array();
00279         $in = explode(chr(10), $in);
00280         foreach ($in as $v) {
00281             $fv = explode('=', $v);
00282             $ret[$fv[0]] = $fv[1];
00283         }
00284 
00285         return $ret;
00286     }
00287 
00288     /**
00289      * Prints out the cached information about the database.
00290      *
00291      * The DBAL caches a lot of information, e.g. about auto increment fields,
00292      * field types and primary keys. This method formats all this into a HTML
00293      * table to display in the BE.
00294      *
00295      * @return string   HTML output
00296      */
00297     protected function printCachedInfo() {
00298         // Get cmd:
00299         if ((string) t3lib_div::_GP('cmd') === 'clear') {
00300             $GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
00301             $GLOBALS['TYPO3_DB']->cacheFieldInfo();
00302         }
00303 
00304         $out = '<a name="autoincrement"></a><h2>auto_increment</h2>';
00305         $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field</th></tr>';
00306         ksort($GLOBALS['TYPO3_DB']->cache_autoIncFields);
00307         foreach ($GLOBALS['TYPO3_DB']->cache_autoIncFields as $table => $field) {
00308             $out .= '<tr>';
00309             $out .= '<td>' . $table . '</td>';
00310             $out .= '<td>' . $field . '</td>';
00311             $out .= '</tr>';
00312         }
00313         $out .= '</tbody></table>';
00314 
00315         $out .= $this->doc->spacer(5);
00316         $out .= '<a name="primarykeys"></a><h2>Primary keys</h2>';
00317         $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field(s)</th></tr>';
00318         ksort($GLOBALS['TYPO3_DB']->cache_primaryKeys);
00319         foreach ($GLOBALS['TYPO3_DB']->cache_primaryKeys as $table => $field) {
00320             $out .= '<tr>';
00321             $out .= '<td>' . $table . '</td>';
00322             $out .= '<td>' . $field . '</td>';
00323             $out .= '</tr>';
00324         }
00325         $out .= '</tbody></table>';
00326 
00327         $out .= $this->doc->spacer(5);
00328         $out .= '<a name="fieldtypes"></a><h2>Field types</h2>';
00329         $out .= '<table border="1" cellspacing="0"><tbody><tr><th colspan="5">Table</th></tr><tr><th>Field</th><th>Type</th><th><a href="#metatypes">Metatype</a></th><th>NOT NULL</th><th>Default</th></th></tr>';
00330         ksort($GLOBALS['TYPO3_DB']->cache_fieldType);
00331         foreach ($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fields) {
00332             $out .= '<th colspan="5">' . $table . '</th>';
00333             foreach ($fields as $field => $data) {
00334                 $out .= '<tr>';
00335                 $out .= '<td>' . $field . '</td>';
00336                 $out .= '<td>' . $data['type'] . '</td>';
00337                 $out .= '<td>' . $data['metaType'] . '</td>';
00338                 $out .= '<td>' . ($data['notnull'] ? 'NOT NULL' : '') . '</td>';
00339                 $out .= '<td>' . $data['default'] . '</td>';
00340                 $out .= '</tr>';
00341             }
00342         }
00343         $out .= '</tbody></table>';
00344 
00345         $out .= $this->doc->spacer(5);
00346         $out .= '<a name="metatypes"></a><h2>Metatype explanation</h2>';
00347         $out .= '<pre>
00348   C:  Varchar, capped to 255 characters.
00349   X:  Larger varchar, capped to 4000 characters (to be compatible with Oracle).
00350   XL: For Oracle, returns CLOB, otherwise the largest varchar size.
00351 
00352   C2: Multibyte varchar
00353   X2: Multibyte varchar (largest size)
00354 
00355   B:  BLOB (binary large object)
00356 
00357   D:  Date (some databases do not support this, and we return a datetime type)
00358   T:  Datetime or Timestamp
00359   L:  Integer field suitable for storing booleans (0 or 1)
00360   I:  Integer (mapped to I4)
00361   I1: 1-byte integer
00362   I2: 2-byte integer
00363   I4: 4-byte integer
00364   I8: 8-byte integer
00365   F:  Floating point number
00366   N:  Numeric or decimal number</pre>';
00367 
00368         $menu = '<a href="' . $this->thisScript . '&amp;cmd=clear">CLEAR DATA</a><hr />';
00369         $menu .= '<a href="#autoincrement">auto_increment</a> | <a href="#primarykeys">Primary keys</a> | <a href="#fieldtypes">Field types</a> | <a href="#metatypes">Metatype explanation</a><hr />';
00370 
00371         return $menu . $out;
00372     }
00373 
00374     /**
00375      * Printing the debug-log from the DBAL extension
00376      *
00377      * To enabled debugging, you will have to enabled it in the configuration!
00378      *
00379      * @return  string HTML content
00380      */
00381     protected function printLogMgm() {
00382 
00383         // Disable debugging in any case...
00384         $GLOBALS['TYPO3_DB']->debug = FALSE;
00385 
00386         // Get cmd:
00387         $cmd = (string) t3lib_div::_GP('cmd');
00388         switch ($cmd) {
00389             case 'flush':
00390                 $res = $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_dbal_debuglog');
00391                 $res = $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_dbal_debuglog_where');
00392                 $outStr = 'Log FLUSHED!';
00393                 break;
00394             case 'joins':
00395                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('table_join,exec_time,query,script', 'tx_dbal_debuglog', 'table_join!=\'\'', 'table_join,script,exec_time,query');
00396 
00397                 // Init vars in which to pick up the query result:
00398                 $tableIndex = array();
00399                 $tRows = array();
00400                 $tRows[] = '
00401                     <tr>
00402                         <td>Execution time</td>
00403                         <td>Table joins</td>
00404                         <td>Script</td>
00405                         <td>Query</td>
00406                     </tr>';
00407 
00408                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00409                     $tableArray = $GLOBALS['TYPO3_DB']->SQLparser->parseFromTables($row['table_join']);
00410 
00411                     // Create table name index:
00412                     foreach ($tableArray as $a) {
00413                         foreach ($tableArray as $b) {
00414                             if ($b['table'] != $a['table']) {
00415                                 $tableIndex[$a['table']][$b['table']] = 1;
00416                             }
00417                         }
00418                     }
00419 
00420                     // Create output row
00421                     $tRows[] = '
00422                         <tr>
00423                             <td>' . htmlspecialchars($row['exec_time']) . '</td>
00424                             <td>' . htmlspecialchars($row['table_join']) . '</td>
00425                             <td>' . htmlspecialchars($row['script']) . '</td>
00426                             <td>' . htmlspecialchars($row['query']) . '</td>
00427                         </tr>';
00428                 }
00429 
00430                 // Printing direct joins:
00431                 $outStr .= '<h4>Direct joins:</h4>' . t3lib_div::view_array($tableIndex);
00432 
00433 
00434                 // Printing total dependencies:
00435                 foreach ($tableIndex as $priTable => $a) {
00436                     foreach ($tableIndex as $tableN => $v) {
00437                         foreach ($v as $tableP => $vv) {
00438                             if ($tableP == $priTable) {
00439                                 $tableIndex[$priTable] = array_merge($v, $a);
00440                             }
00441                         }
00442                     }
00443                 }
00444                 $outStr .= '<h4>Total dependencies:</h4>' . t3lib_div::view_array($tableIndex);
00445 
00446                 // Printing data rows:
00447                 $outStr .= '
00448                     <table border="1" cellspacing="0">' . implode('', $tRows) . '
00449                     </table>';
00450                 break;
00451             case 'errors':
00452 
00453                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('serdata,exec_time,query,script', 'tx_dbal_debuglog', 'errorFlag>0', '', 'tstamp DESC');
00454 
00455                 // Init vars in which to pick up the query result:
00456                 $tRows = array();
00457                 $tRows[] = '
00458                     <tr>
00459                         <td>Execution time</td>
00460                         <td>Error data</td>
00461                         <td>Script</td>
00462                         <td>Query</td>
00463                     </tr>';
00464 
00465                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00466                     // Create output row
00467                     $tRows[] = '
00468                         <tr>
00469                             <td>' . htmlspecialchars($row['exec_time']) . '</td>
00470                             <td>' . t3lib_div::view_array(unserialize($row['serdata'])) . '</td>
00471                             <td>' . htmlspecialchars($row['script']) . '</td>
00472                             <td>' . htmlspecialchars($row['query']) . '</td>
00473                         </tr>';
00474                 }
00475 
00476                 // Printing data rows:
00477                 $outStr .= '
00478                     <table border="1" cellspacing="0">' . implode('', $tRows) . '
00479                     </table>';
00480                 break;
00481             case 'parsing':
00482                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('query,serdata', 'tx_dbal_debuglog', 'errorFlag&2=2');
00483                 $tRows = array();
00484                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00485                     // Create output row
00486                     $tRows[] = '
00487                         <tr>
00488                             <td>' . htmlspecialchars($row['query']) . '</td>
00489                         </tr>';
00490                 }
00491 
00492                 // Printing data rows:
00493                 $outStr .= '
00494                     <table border="1" cellspacing="0">' . implode('', $tRows) . '
00495                     </table>';
00496                 break;
00497             case 'where':
00498                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script,tablename,whereclause', 'tx_dbal_debuglog_where', '', '', 'tstamp DESC');
00499                 $tRows = array();
00500                 $tRows[] = '
00501                     <tr>
00502                         <td>Time</td>
00503                         <td>Script</td>
00504                         <td>Table</td>
00505                         <td>WHERE clause</td>
00506                     </tr>';
00507                 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00508                     $tRows[] = '
00509                         <tr>
00510                             <td>' . t3lib_BEfunc::datetime($row['tstamp']) . '</td>
00511                             <td>' . htmlspecialchars($row['script']) . '</td>
00512                             <td>' . htmlspecialchars($row['tablename']) . '</td>
00513                                 <td>' . str_replace(array('\'\'', '""', 'IS NULL', 'IS NOT NULL'), array('<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">\'\'</span>', '<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">""</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NULL</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NOT NULL</span>'), htmlspecialchars($row['whereclause'])) . '</td>
00514                         </tr>';
00515                 }
00516 
00517                 $outStr = '
00518                     <table border="1" cellspacing="0">' . implode('', $tRows) . '
00519                     </table>';
00520                 break;
00521             default:
00522 
00523                 // Look for request to view specific script exec:
00524                 $specTime = t3lib_div::_GP('specTime');
00525 
00526                 if ($specTime) {
00527                     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('exec_time,errorFlag,table_join,serdata,query', 'tx_dbal_debuglog', 'tstamp=' . (int) $specTime);
00528                     $tRows = array();
00529                     $tRows[] = '
00530                         <tr>
00531                             <td>Execution time</td>
00532                             <td>Error</td>
00533                             <td>Table joins</td>
00534                             <td>Data</td>
00535                             <td>Query</td>
00536                         </tr>';
00537                     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00538                         $tRows[] = '
00539                             <tr>
00540                                 <td>' . htmlspecialchars($row['exec_time']) . '</td>
00541                                 <td>' . ($row['errorFlag'] ? 1 : 0) . '</td>
00542                                 <td>' . htmlspecialchars($row['table_join']) . '</td>
00543                                 <td>' . t3lib_div::view_array(unserialize($row['serdata'])) . '</td>
00544                                 <td>' . str_replace(array('\'\'', '""', 'IS NULL', 'IS NOT NULL'), array('<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">\'\'</span>', '<span style="background-color:#ff0000;color:#ffffff;padding:2px;font-weight:bold;">""</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NULL</span>', '<span style="background-color:#00ff00;color:#ffffff;padding:2px;font-weight:bold;">IS NOT NULL</span>'), htmlspecialchars($row['query'])) . '</td>
00545                             </tr>';
00546                     }
00547                 } else {
00548                     $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script, SUM(exec_time) as calc_sum, count(*) AS qrycount, MAX(errorFlag) as error', 'tx_dbal_debuglog', '', 'tstamp,script', 'tstamp DESC');
00549                     $tRows = array();
00550                     $tRows[] = '
00551                         <tr>
00552                             <td>Time</td>
00553                             <td># of queries</td>
00554                             <td>Error</td>
00555                             <td>Time (ms)</td>
00556                             <td>Script</td>
00557                         </tr>';
00558                     while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00559                         $tRows[] = '
00560                             <tr>
00561                                 <td>' . t3lib_BEfunc::datetime($row['tstamp']) . '</td>
00562                                 <td>' . htmlspecialchars($row['qrycount']) . '</td>
00563                                 <td>' . ($row['error'] ? '<strong style="color:#f00">ERR</strong>' : '') . '</td>
00564                                 <td>' . htmlspecialchars($row['calc_sum']) . '</td>
00565                                 <td><a href="' . $this->thisScript . '&amp;specTime=' . intval($row['tstamp']) . '">' . htmlspecialchars($row['script']) . '</a></td>
00566                             </tr>';
00567                     }
00568                 }
00569                 $outStr = '
00570                     <table border="1" cellspacing="0">' . implode('', $tRows) . '
00571                     </table>';
00572 
00573                 break;
00574         }
00575 
00576         $menu = '
00577                     <a href="' . $this->thisScript . '&amp;cmd=flush">FLUSH LOG</a> -
00578                     <a href="' . $this->thisScript . '&amp;cmd=joins">JOINS</a> -
00579                     <a href="' . $this->thisScript . '&amp;cmd=errors">ERRORS</a> -
00580                     <a href="' . $this->thisScript . '&amp;cmd=parsing">PARSING</a> -
00581                     <a href="' . $this->thisScript . '">LOG</a> -
00582                     <a href="' . $this->thisScript . '&amp;cmd=where">WHERE</a> -
00583 
00584                     <a href="' . htmlspecialchars(t3lib_div::linkThisScript()) . '" target="tx_debuglog">[New window]</a>
00585                     <hr />
00586         ';
00587         return $menu . $outStr;
00588     }
00589 }
00590 
00591 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php'])) {
00592     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']);
00593 }
00594 
00595 
00596 // Make instance:
00597 $SOBE = t3lib_div::makeInstance('tx_dbal_module1');
00598 $SOBE->init();
00599 $SOBE->main();
00600 $SOBE->printContent();
00601 
00602 ?>