Added default values and some usability improvements to cached info display in debug...
[Packages/TYPO3.CMS.git] / typo3 / sysext / dbal / mod1 / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2004, 2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * (c) 2004-2007 Karsten Dambekalns (karsten@typo3.org)
7 * All rights reserved
8 *
9 * This script is part of the TYPO3 project. The TYPO3 project is
10 * free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * The GNU General Public License can be found at
16 * http://www.gnu.org/copyleft/gpl.html.
17 *
18 * This script is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * This copyright notice MUST APPEAR in all copies of the script!
24 ***************************************************************/
25 /**
26 * Module 'DBAL Debug' for the 'dbal' extension.
27 *
28 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
29 * @author Karsten Dambekalns <karsten@typo3.org>
30 */
31
32 unset($MCONF);
33 require ('conf.php');
34 require ($BACK_PATH.'init.php');
35 require ($BACK_PATH.'template.php');
36 $LANG->includeLLFile('EXT:dbal/mod1/locallang.xml');
37 require_once (PATH_t3lib.'class.t3lib_scbase.php');
38 $BE_USER->modAccess($MCONF,1);
39
40
41 /**
42 * Script class; Backend module for DBAL extension
43 *
44 * @author Kasper Skaarhoj <kasper@typo3.com>
45 * @author Karsten Dambekalns <karsten@typo3.org>
46 * @package TYPO3
47 * @subpackage dbal
48 */
49 class tx_dbal_module1 extends t3lib_SCbase {
50
51 /**
52 * Adds items to the ->MOD_MENU array. Used for the function menu selector.
53 *
54 * @return void
55 */
56 function menuConfig() {
57 $this->MOD_MENU = Array (
58 'function' => Array (
59 0 => $GLOBALS['LANG']->getLL('Debug_log'),
60 'info' => $GLOBALS['LANG']->getLL('Cached_info'),
61 'sqlcheck' => $GLOBALS['LANG']->getLL('SQL_check'),
62 )
63 );
64 parent::menuConfig();
65 }
66
67 /**
68 * Main function of the module. Write the content to $this->content
69 *
70 * @return void
71 */
72 function main() {
73 global $BACK_PATH,$BE_USER;
74
75 // Clean up settings:
76 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name']);
77
78 // Draw the header.
79 $this->doc = t3lib_div::makeInstance('noDoc');
80 $this->doc->backPath = $BACK_PATH;
81 $this->doc->form='<form action="" method="post">';
82 $this->doc->docType = 'xhtml_trans';
83
84 // JavaScript
85 $this->doc->JScode = $this->doc->wrapScriptTags('
86 script_ended = 0;
87 function jumpToUrl(URL) { //
88 window.location.href = URL;
89 }
90 ');
91
92 // DBAL page title:
93 $this->content.=$this->doc->startPage($GLOBALS['LANG']->getLL('title'));
94 $this->content.=$this->doc->header($GLOBALS['LANG']->getLL('title'));
95 $this->content.=$this->doc->spacer(5);
96 $this->content.=$this->doc->section('',$this->doc->funcMenu('',t3lib_BEfunc::getFuncMenu(0,'SET[function]',$this->MOD_SETTINGS['function'],$this->MOD_MENU['function'])));
97
98 // Debug log:
99 switch($this->MOD_SETTINGS['function']) {
100 case 'info':
101 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('Cached_info'), $this->printCachedInfo());
102 break;
103 case 'sqlcheck':
104 $this->content .= $this->doc->section($GLOBALS['LANG']->getLL('SQL_check'), $this->printSqlCheck());
105 break;
106 case 0:
107 $this->content.= $this->doc->section($GLOBALS['LANG']->getLL('Debug_log'), $this->printLogMgm());
108 break;
109 }
110
111 // ShortCut
112 if ($BE_USER->mayMakeShortcut()) {
113 $this->content.=$this->doc->spacer(20).$this->doc->section('',$this->doc->makeShortcutIcon('id',implode(',',array_keys($this->MOD_MENU)),$this->MCONF['name']));
114 }
115
116 $this->content.=$this->doc->spacer(10);
117 }
118
119 /**
120 * Prints out the module HTML
121 *
122 * @return string HTML output
123 */
124 function printContent() {
125 global $SOBE;
126
127 $this->content.=$this->doc->middle();
128 $this->content.=$this->doc->endPage();
129 echo $this->content;
130 }
131
132 /**
133 * Displays a form to check DBAL SQL methods and parse raw SQL.
134 *
135 * @return string HTML output
136 */
137 function printSqlCheck() {
138 $input = t3lib_div::_GP('tx_dbal');
139
140 $out = '
141 <form name="sql_check" action="index.php" method="post" enctype="'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['form_enctype'].'">
142 <script type="text/javascript">
143 /*<![CDATA[*/
144 function updateQryForm(s) {
145 document.getElementById(\'tx-dbal-result\').style.display = \'none\';
146 switch(s) {
147 case \'SELECT\':
148 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
149 document.getElementById(\'tx-dbal-qryfields\').style.display = \'table-row\';
150 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
151 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
152 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
153 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
154 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
155 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
156 document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
157 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
158 break;
159 case \'INSERT\':
160 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
161 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
162 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'table-row\';
163 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
164 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
165 document.getElementById(\'tx-dbal-qryinto\').style.display = \'table-row\';
166 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
167 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
168 document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
169 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
170 break;
171 case \'UPDATE\':
172 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\';
173 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
174 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
175 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'table-row\';
176 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
177 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
178 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\';
179 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
180 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
181 document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
182 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
183 break;
184 case \'DELETE\':
185 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'none\';
186 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
187 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
188 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
189 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
190 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
191 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
192 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
193 document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
194 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
195 break;
196 }
197 }
198 /*]]>*/
199 </script>
200 <table>
201 <tr class="tableheader bgColor5"><th colspan="2">Easy SQL check</th></tr>
202 <tr><td colspan="2">
203 <select name="tx_dbal[QUERY]"size="1" onchange="updateQryForm(this.options[this.selectedIndex].value)">
204 <option value="SELECT" '.($input['QUERY']=='SELECT'? 'selected="selected"' : '').'>SELECT</option>
205 <option value="INSERT" '.($input['QUERY']=='INSERT'? 'selected="selected"' : '').'>INSERT</option>
206 <option value="UPDATE" '.($input['QUERY']=='UPDATE'? 'selected="selected"' : '').'>UPDATE</option>
207 <option value="DELETE" '.($input['QUERY']=='DELETE' ? 'selected="selected"' : '').'>DELETE</option>
208 </select>
209 </td></tr>
210 <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>
211 <tr id="tx-dbal-qryfields"><td></td><td><input name="tx_dbal[FIELDS]" value="'.$input['FIELDS'].'" type="text" size="30" maxsize="100" /></td></tr>
212 <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>
213 <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>
214 <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>
215 <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>
216 <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>
217 <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>
218 <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>
219 <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>
220 <tr><td></td><td style="text-align:right;"><input type="submit" value="CHECK" /></td></tr>
221 <script type="text/javascript">
222 /*<![CDATA[*/
223 updateQryForm(\''.$input['QUERY'].'\');
224 /*]]>*/
225 </script>
226 ';
227
228 $out .= '<tr id="tx-dbal-result" class="bgColor4"><th>Result:</th><td>';
229 switch($input['QUERY']) {
230 case 'SELECT':
231 $qry = $GLOBALS['TYPO3_DB']->SELECTquery($input['FIELDS'],$input['FROM'],$input['WHERE'],$input['GROUP'],$input['ORDER'],$input['LIMIT']);
232 break;
233 case 'INSERT':
234 $qry = $GLOBALS['TYPO3_DB']->INSERTquery($input['INTO'],$this->createFieldsValuesArray($input['INSERTVALUES']));
235 break;
236 case 'UPDATE':
237 $qry = $GLOBALS['TYPO3_DB']->UPDATEquery($input['UPDATE'],$input['WHERE'],$this->createFieldsValuesArray($input['UPDATEVALUES']));
238 break;
239 case 'DELETE':
240 $qry = $GLOBALS['TYPO3_DB']->DELETEquery($input['FROM'],$input['WHERE']);
241 break;
242 }
243 $out .= '<pre>'.htmlspecialchars($qry).'</pre></td></tr>';
244
245 $out .= '
246 <tr class="tableheader bgColor5"><th colspan="2">RAW SQL check</th></tr>
247 <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>';
248 if(!empty($input['RAWSQL'])) {
249 $out .= '<tr class="bgColor4">';
250 $parseResult = $GLOBALS['TYPO3_DB']->SQLparser->parseSQL($input['RAWSQL']);
251 if (is_array($parseResult)) {
252 $newQuery = $GLOBALS['TYPO3_DB']->SQLparser->compileSQL($parseResult);
253 $testResult = $GLOBALS['TYPO3_DB']->SQLparser->debug_parseSQLpartCompare($input['RAWSQL'], $newQuery);
254 if (!is_array($testResult)) {
255 $out .= '<td colspan="2">'.$newQuery;
256 } else {
257 $out .= '<td colspan="2">'.htmlspecialchars($testResult[0]).'</td></tr>
258 <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]);
259 }
260 } else {
261 $out .= '<th>Result:</th><td style="border:2px solid #f00;">'.$parseResult;
262 }
263 $out .='</td></tr>';
264 }
265
266 $out .='</table></form>';
267 return $out;
268 }
269
270 /**
271 * Parses a very simple text format into an array.
272 *
273 * Each line is seen as a key/value pair that is exploded at =. This is used
274 * in the simple SQL check to input values for INSERT and UPDATE statements.
275 *
276 * @param string $in String to parse into key/value array.
277 * @return array Array created from the input string.
278 */
279 function createFieldsValuesArray($in) {
280 $ret = array();
281 $in = explode(chr(10),$in);
282 foreach ($in as $v) {
283 $fv = explode('=',$v);
284 $ret[$fv[0]] = $fv[1];
285 }
286
287 return $ret;
288 }
289
290 /**
291 * Prints out the cached information about the database.
292 *
293 * The DBAL caches a lot of information, e.g. about auto increment fields,
294 * field types and primary keys. This method formats all this into a HTML
295 * table to display in the BE.
296 *
297 * @return string HTML output
298 */
299 function printCachedInfo() {
300 // Get cmd:
301 if((string)t3lib_div::_GP('cmd') == 'clear') {
302 $GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
303 $GLOBALS['TYPO3_DB']->cacheFieldInfo();
304 }
305
306 $out = '<a name="autoincrement"></a><h2>auto_increment</h2>';
307 $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field</th></tr>';
308 ksort($GLOBALS['TYPO3_DB']->cache_autoIncFields);
309 foreach($GLOBALS['TYPO3_DB']->cache_autoIncFields as $table => $field) {
310 $out .= '<tr>';
311 $out .= '<td>'.$table.'</td>';
312 $out .= '<td>'.$field.'</td>';
313 $out .= '</tr>';
314 }
315 $out .= '</tbody></table>';
316
317 $out .= $this->doc->spacer(5);
318 $out .= '<a name="primarykeys"></a><h2>Primary keys</h2>';
319 $out .= '<table border="1" cellspacing="0"><tbody><tr><th>Table</th><th>Field(s)</th></tr>';
320 ksort($GLOBALS['TYPO3_DB']->cache_primaryKeys);
321 foreach($GLOBALS['TYPO3_DB']->cache_primaryKeys as $table => $field) {
322 $out .= '<tr>';
323 $out .= '<td>'.$table.'</td>';
324 $out .= '<td>'.$field.'</td>';
325 $out .= '</tr>';
326 }
327 $out .= '</tbody></table>';
328
329 $out .= $this->doc->spacer(5);
330 $out .= '<a name="fieldtypes"></a><h2>Field types</h2>';
331 $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>';
332 ksort($GLOBALS['TYPO3_DB']->cache_fieldType);
333 foreach($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fields) {
334 $out .= '<th colspan="5">'.$table.'</th>';
335 foreach($fields as $field => $data) {
336 $out .= '<tr>';
337 $out .= '<td>'.$field.'</td>';
338 $out .= '<td>'.$data['type'].'</td>';
339 $out .= '<td>'.$data['metaType'].'</td>';
340 $out .= '<td>'.($data['notnull']?'NOT NULL':'').'</td>';
341 $out .= '<td>'.$data['default'].'</td>';
342 $out .= '</tr>';
343 }
344 }
345 $out .= '</tbody></table>';
346
347 $out .= $this->doc->spacer(5);
348 $out .= '<a name="metatypes"></a><h2>Metatype explanation</h2>';
349 $out .= '<pre>
350 C: Varchar, capped to 255 characters.
351 X: Larger varchar, capped to 4000 characters (to be compatible with Oracle).
352 XL: For Oracle, returns CLOB, otherwise the largest varchar size.
353
354 C2: Multibyte varchar
355 X2: Multibyte varchar (largest size)
356
357 B: BLOB (binary large object)
358
359 D: Date (some databases do not support this, and we return a datetime type)
360 T: Datetime or Timestamp
361 L: Integer field suitable for storing booleans (0 or 1)
362 I: Integer (mapped to I4)
363 I1: 1-byte integer
364 I2: 2-byte integer
365 I4: 4-byte integer
366 I8: 8-byte integer
367 F: Floating point number
368 N: Numeric or decimal number</pre>';
369
370 $menu = '<a href="index.php?cmd=clear">CLEAR DATA</a><hr />';
371 $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 />';
372
373 return $menu.$out;
374 }
375
376 /**
377 * Printing the debug-log from the DBAL extension
378 *
379 * To enabled debugging, you will have to enabled it in the configuration!
380 *
381 * @return string HTML content
382 */
383 function printLogMgm() {
384
385 // Disable debugging in any case...
386 $GLOBALS['TYPO3_DB']->debug = FALSE;
387
388 // Get cmd:
389 $cmd = (string)t3lib_div::_GP('cmd');
390 switch($cmd) {
391 case 'flush':
392 $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog','');
393 $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog_where','');
394 $outStr = 'Log FLUSHED!';
395 break;
396 case 'joins':
397 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('table_join,exec_time,query,script','tx_dbal_debuglog','table_join!=\'\'', 'table_join,script,exec_time,query');
398
399 // Init vars in which to pick up the query result:
400 $tableIndex = array();
401 $tRows = array();
402 $tRows[] = '
403 <tr>
404 <td>Execution time</td>
405 <td>Table joins</td>
406 <td>Script</td>
407 <td>Query</td>
408 </tr>';
409
410 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
411 $tableArray = $GLOBALS['TYPO3_DB']->SQLparser->parseFromTables($row['table_join']);
412
413 // Create table name index:
414 foreach($tableArray as $a) {
415 foreach($tableArray as $b) {
416 if ($b['table']!=$a['table']) {
417 $tableIndex[$a['table']][$b['table']]=1;
418 }
419 }
420 }
421
422 // Create output row
423 $tRows[] = '
424 <tr>
425 <td>'.htmlspecialchars($row['exec_time']).'</td>
426 <td>'.htmlspecialchars($row['table_join']).'</td>
427 <td>'.htmlspecialchars($row['script']).'</td>
428 <td>'.htmlspecialchars($row['query']).'</td>
429 </tr>';
430 }
431
432 // Printing direct joins:
433 $outStr.= '<h4>Direct joins:</h4>'.t3lib_div::view_array($tableIndex);
434
435
436 // Printing total dependencies:
437 foreach($tableIndex as $priTable => $a) {
438 foreach($tableIndex as $tableN => $v) {
439 foreach($v as $tableP => $vv) {
440 if ($tableP == $priTable) {
441 $tableIndex[$priTable] = array_merge($v, $a);
442 }
443 }
444 }
445 }
446 $outStr.= '<h4>Total dependencies:</h4>'.t3lib_div::view_array($tableIndex);
447
448 // Printing data rows:
449 $outStr.= '
450 <table border="1" cellspacing="0">'.implode('',$tRows).'
451 </table>';
452 break;
453 case 'errors':
454
455 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('serdata,exec_time,query,script','tx_dbal_debuglog','errorFlag>0','','tstamp DESC');
456
457 // Init vars in which to pick up the query result:
458 $tRows = array();
459 $tRows[] = '
460 <tr>
461 <td>Execution time</td>
462 <td>Error data</td>
463 <td>Script</td>
464 <td>Query</td>
465 </tr>';
466
467 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
468 // Create output row
469 $tRows[] = '
470 <tr>
471 <td>'.htmlspecialchars($row['exec_time']).'</td>
472 <td>'.t3lib_div::view_array(unserialize($row['serdata'])).'</td>
473 <td>'.htmlspecialchars($row['script']).'</td>
474 <td>'.htmlspecialchars($row['query']).'</td>
475 </tr>';
476 }
477
478 // Printing data rows:
479 $outStr.= '
480 <table border="1" cellspacing="0">'.implode('',$tRows).'
481 </table>';
482 break;
483 case 'parsing':
484 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('query,serdata','tx_dbal_debuglog','errorFlag&2=2');
485 $tRows = array();
486 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
487 // Create output row
488 $tRows[] = '
489 <tr>
490 <td>'.htmlspecialchars($row['query']).'</td>
491 </tr>';
492 }
493
494 // Printing data rows:
495 $outStr.= '
496 <table border="1" cellspacing="0">'.implode('',$tRows).'
497 </table>';
498 break;
499 case 'where':
500 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script,tablename,whereclause','tx_dbal_debuglog_where','','','tstamp DESC');
501 $tRows = array();
502 $tRows[] = '
503 <tr>
504 <td>Time</td>
505 <td>Script</td>
506 <td>Table</td>
507 <td>WHERE clause</td>
508 </tr>';
509 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
510 $tRows[] = '
511 <tr>
512 <td>'.t3lib_BEfunc::datetime($row['tstamp']).'</td>
513 <td>'.htmlspecialchars($row['script']).'</td>
514 <td>'.htmlspecialchars($row['tablename']).'</td>
515 <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>
516 </tr>';
517 }
518
519 $outStr = '
520 <table border="1" cellspacing="0">'.implode('',$tRows).'
521 </table>';
522 break;
523 default:
524
525 // Look for request to view specific script exec:
526 $specTime = t3lib_div::_GP('specTime');
527
528 if ($specTime) {
529 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('exec_time,errorFlag,table_join,serdata,query','tx_dbal_debuglog','tstamp='.(int)$specTime);
530 $tRows = array();
531 $tRows[] = '
532 <tr>
533 <td>Execution time</td>
534 <td>Error</td>
535 <td>Table joins</td>
536 <td>Data</td>
537 <td>Query</td>
538 </tr>';
539 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
540 $tRows[] = '
541 <tr>
542 <td>'.htmlspecialchars($row['exec_time']).'</td>
543 <td>'.($row['errorFlag'] ? 1 : 0).'</td>
544 <td>'.htmlspecialchars($row['table_join']).'</td>
545 <td>'.t3lib_div::view_array(unserialize($row['serdata'])).'</td>
546 <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>
547 </tr>';
548 }
549 } else {
550 $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');
551 $tRows = array();
552 $tRows[] = '
553 <tr>
554 <td>Time</td>
555 <td># of queries</td>
556 <td>Error</td>
557 <td>Time (ms)</td>
558 <td>Script</td>
559 </tr>';
560 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
561 $tRows[] = '
562 <tr>
563 <td>'.t3lib_BEfunc::datetime($row['tstamp']).'</td>
564 <td>'.htmlspecialchars($row['qrycount']).'</td>
565 <td>'.($row['error'] ? '<strong style="color:#f00">ERR</strong>' : '').'</td>
566 <td>'.htmlspecialchars($row['calc_sum']).'</td>
567 <td><a href="index.php?specTime='.intval($row['tstamp']).'">'.htmlspecialchars($row['script']).'</a></td>
568 </tr>';
569 }
570 }
571 $outStr = '
572 <table border="1" cellspacing="0">'.implode('',$tRows).'
573 </table>';
574
575 break;
576 }
577
578 $menu = '
579 <a href="index.php?cmd=flush">FLUSH LOG</a> -
580 <a href="index.php?cmd=joins">JOINS</a> -
581 <a href="index.php?cmd=errors">ERRORS</a> -
582 <a href="index.php?cmd=parsing">PARSING</a> -
583 <a href="index.php">LOG</a> -
584 <a href="index.php?cmd=where">WHERE</a> -
585
586 <a href="'.htmlspecialchars(t3lib_div::linkThisScript()).'" target="tx_debuglog">[New window]</a>
587 <hr />
588 ';
589 return $menu.$outStr;
590 }
591 }
592
593 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']) {
594 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']);
595 }
596
597
598
599
600 // Make instance:
601 $SOBE = t3lib_div::makeInstance('tx_dbal_module1');
602 $SOBE->init();
603 $SOBE->main();
604 $SOBE->printContent();
605 ?>