ChangeLog
[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, 2005 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-qryfields\').style.display = \'table-row\';
149 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
150 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
151 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
152 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
153 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
154 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
155 document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
156 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
157 break;
158 case \'INSERT\':
159 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
160 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'table-row\';
161 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
162 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
163 document.getElementById(\'tx-dbal-qryinto\').style.display = \'table-row\';
164 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
165 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'table-row\';
166 document.getElementById(\'tx-dbal-qryorder\').style.display = \'table-row\';
167 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'table-row\';
168 break;
169 case \'UPDATE\':
170 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
171 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
172 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'table-row\';
173 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'none\';
174 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
175 document.getElementById(\'tx-dbal-qryupdate\').style.display = \'table-row\';
176 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
177 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
178 document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
179 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
180 break;
181 case \'DELETE\':
182 document.getElementById(\'tx-dbal-qryfields\').style.display = \'none\';
183 document.getElementById(\'tx-dbal-qryinsertvalues\').style.display = \'none\';
184 document.getElementById(\'tx-dbal-qryupdatevalues\').style.display = \'none\';
185 document.getElementById(\'tx-dbal-qryfrom\').style.display = \'table-row\';
186 document.getElementById(\'tx-dbal-qryinto\').style.display = \'none\';
187 document.getElementById(\'tx-dbal-qrywhere\').style.display = \'table-row\';
188 document.getElementById(\'tx-dbal-qrygroup\').style.display = \'none\';
189 document.getElementById(\'tx-dbal-qryorder\').style.display = \'none\';
190 document.getElementById(\'tx-dbal-qrylimit\').style.display = \'none\';
191 break;
192 }
193 }
194 /*]]>*/
195 </script>
196 <table>
197 <tr class="tableheader bgColor5"><th colspan="2">Easy SQL check</th></tr>
198 <tr><td colspan="2">
199 <select name="tx_dbal[QUERY]"size="1" onchange="updateQryForm(this.options[this.selectedIndex].value)">
200 <option value="SELECT" '.($input['QUERY']=='SELECT'? 'selected="selected"' : '').'>SELECT</option>
201 <option value="INSERT" '.($input['QUERY']=='INSERT'? 'selected="selected"' : '').'>INSERT</option>
202 <option value="UPDATE" '.($input['QUERY']=='UPDATE'? 'selected="selected"' : '').'>UPDATE</option>
203 <option value="DELETE" '.($input['QUERY']=='DELETE' ? 'selected="selected"' : '').'">DELETE</option>
204 </select>
205 </td></tr>
206 <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>
207 <tr id="tx-dbal-qryfields"><td></td><td><input name="tx_dbal[FIELDS]" value="'.$input['FIELDS'].'" type="text" size="30" maxsize="100" /></td></tr>
208 <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>
209 <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>
210 <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>
211 <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>
212 <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>
213 <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>
214 <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>
215 <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>
216 <tr><td></td><td style="text-align:right;"><input type="submit" value="CHECK" /></td></tr>
217 <script type="text/javascript">
218 /*<![CDATA[*/
219 updateQryForm(\''.$input['QUERY'].'\');
220 /*]]>*/
221 </script>
222 ';
223
224 $out .= '<tr id="tx-dbal-result" class="bgColor4"><th>Result:</th><td>';
225 switch($input['QUERY']) {
226 case 'SELECT':
227 $qry = $GLOBALS['TYPO3_DB']->SELECTquery($input['FIELDS'],$input['FROM'],$input['WHERE'],$input['GROUP'],$input['ORDER'],$input['LIMIT']);
228 break;
229 case 'INSERT':
230 $qry = $GLOBALS['TYPO3_DB']->INSERTquery($input['INTO'],$this->createFieldsValuesArray($input['INSERTVALUES']));
231 break;
232 case 'UPDATE':
233 $qry = $GLOBALS['TYPO3_DB']->UPDATEquery($input['UPDATE'],$input['WHERE'],$this->createFieldsValuesArray($input['UPDATEVALUES']));
234 break;
235 case 'DELETE':
236 $qry = $GLOBALS['TYPO3_DB']->DELETEquery($input['FROM'],$input['WHERE']);
237 break;
238 }
239 $out .= '<pre>'.htmlspecialchars($qry).'</pre></td></tr>';
240
241 $out .= '
242 <tr class="tableheader bgColor5"><th colspan="2">RAW SQL check</th></tr>
243 <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>';
244 if(!empty($input['RAWSQL'])) {
245 $out .= '<tr class="bgColor4">';
246 $parseResult = $GLOBALS['TYPO3_DB']->SQLparser->parseSQL($input['RAWSQL']);
247 if (is_array($parseResult)) {
248 $newQuery = $GLOBALS['TYPO3_DB']->SQLparser->compileSQL($parseResult);
249 $testResult = $GLOBALS['TYPO3_DB']->SQLparser->debug_parseSQLpartCompare($input['RAWSQL'], $newQuery);
250 if (!is_array($testResult)) {
251 $out .= '<td colspan="2">'.$newQuery;
252 } else {
253 $out .= '<td colspan="2">'.htmlspecialchars($testResult[0]).'</td></tr>
254 <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]);
255 }
256 } else {
257 $out .= '<th>Result:</th><td style="border:2px solid #f00;">'.$parseResult;
258 }
259 $out .='</td></tr>';
260 }
261
262 $out .='</table></form>';
263 return $out;
264 }
265
266 /**
267 * Parses a very simple text format into an array.
268 *
269 * Each line is seen as a key/value pair that is exploded at =. This is used
270 * in the simple SQL check to input values for INSERT and UPDATE statements.
271 *
272 * @param string $in String to parse into key/value array.
273 * @return array Array created from the input string.
274 */
275 function createFieldsValuesArray($in) {
276 $ret = array();
277 $in = explode(chr(10),$in);
278 foreach ($in as $v) {
279 $fv = explode('=',$v);
280 $ret[$fv[0]] = $fv[1];
281 }
282
283 return $ret;
284 }
285
286 /**
287 * Prints out the cached information about the database.
288 *
289 * The DBAL caches a lot of information, e.g. about auto increment fields,
290 * field types and primary keys. This method formats all this into a HTML
291 * table to display in the BE.
292 *
293 * @return string HTML output
294 */
295 function printCachedInfo() {
296 // Get cmd:
297 if((string)t3lib_div::_GP('cmd') == 'clear') {
298 $GLOBALS['TYPO3_DB']->clearCachedFieldInfo();
299 $GLOBALS['TYPO3_DB']->cacheFieldInfo();
300 }
301
302 $out = '<table border="1" cellspacing="0"><caption>auto_increment</caption><tbody><tr><th>Table</th><th>Field</th></tr>';
303 ksort($GLOBALS['TYPO3_DB']->cache_autoIncFields);
304 foreach($GLOBALS['TYPO3_DB']->cache_autoIncFields as $table => $field) {
305 $out .= '<tr>';
306 $out .= '<td>'.$table.'</td>';
307 $out .= '<td>'.$field.'</td>';
308 $out .= '</tr>';
309 }
310 $out .= '</tbody></table>';
311 $out .= $this->doc->spacer(5);
312 $out .= '<table border="1" cellspacing="0"><caption>Primary keys</caption><tbody><tr><th>Table</th><th>Field(s)</th></tr>';
313 ksort($GLOBALS['TYPO3_DB']->cache_primaryKeys);
314 foreach($GLOBALS['TYPO3_DB']->cache_primaryKeys as $table => $field) {
315 $out .= '<tr>';
316 $out .= '<td>'.$table.'</td>';
317 $out .= '<td>'.$field.'</td>';
318 $out .= '</tr>';
319 }
320 $out .= '</tbody></table>';
321 $out .= $this->doc->spacer(5);
322 $out .= '<table border="1" cellspacing="0"><caption>Field types</caption><tbody><tr><th colspan="4">Table</th></tr><tr><th>Field</th><th>Type</th><th>Metatype</th><th>NOT NULL</th></th></tr>';
323 ksort($GLOBALS['TYPO3_DB']->cache_fieldType);
324 foreach($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fields) {
325 $out .= '<th colspan="4">'.$table.'</th>';
326 foreach($fields as $field => $data) {
327 $out .= '<tr>';
328 $out .= '<td>'.$field.'</td>';
329 $out .= '<td>'.$data['type'].'</td>';
330 $out .= '<td>'.$data['metaType'].'</td>';
331 $out .= '<td>'.$data['notnull'].'</td>';
332 $out .= '</tr>';
333 }
334 }
335 $out .= '</tbody></table>';
336
337 $menu = '<a href="index.php?cmd=clear">CLEAR DATA</a><hr />';
338
339 return $menu.$out;
340 }
341
342 /**
343 * Printing the debug-log from the DBAL extension
344 *
345 * To enabled debugging, you will have to enabled it in the configuration!
346 *
347 * @return string HTML content
348 */
349 function printLogMgm() {
350
351 // Disable debugging in any case...
352 $GLOBALS['TYPO3_DB']->debug = FALSE;
353
354 // Get cmd:
355 $cmd = (string)t3lib_div::_GP('cmd');
356 switch($cmd) {
357 case 'flush':
358 $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog','');
359 $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog_where','');
360 $outStr = 'Log FLUSHED!';
361 break;
362 case 'joins':
363 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('table_join,exec_time,query,script','tx_dbal_debuglog','table_join!=\'\'', 'table_join,script,exec_time,query');
364
365 // Init vars in which to pick up the query result:
366 $tableIndex = array();
367 $tRows = array();
368 $tRows[] = '
369 <tr>
370 <td>Execution time</td>
371 <td>Table joins</td>
372 <td>Script</td>
373 <td>Query</td>
374 </tr>';
375
376 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
377 $tableArray = $GLOBALS['TYPO3_DB']->SQLparser->parseFromTables($row['table_join']);
378
379 // Create table name index:
380 foreach($tableArray as $a) {
381 foreach($tableArray as $b) {
382 if ($b['table']!=$a['table']) {
383 $tableIndex[$a['table']][$b['table']]=1;
384 }
385 }
386 }
387
388 // Create output row
389 $tRows[] = '
390 <tr>
391 <td>'.htmlspecialchars($row['exec_time']).'</td>
392 <td>'.htmlspecialchars($row['table_join']).'</td>
393 <td>'.htmlspecialchars($row['script']).'</td>
394 <td>'.htmlspecialchars($row['query']).'</td>
395 </tr>';
396 }
397
398 // Printing direct joins:
399 $outStr.= '<h4>Direct joins:</h4>'.t3lib_div::view_array($tableIndex);
400
401
402 // Printing total dependencies:
403 foreach($tableIndex as $priTable => $a) {
404 foreach($tableIndex as $tableN => $v) {
405 foreach($v as $tableP => $vv) {
406 if ($tableP == $priTable) {
407 $tableIndex[$priTable] = array_merge($v, $a);
408 }
409 }
410 }
411 }
412 $outStr.= '<h4>Total dependencies:</h4>'.t3lib_div::view_array($tableIndex);
413
414 // Printing data rows:
415 $outStr.= '
416 <table border="1" cellspacing="0">'.implode('',$tRows).'
417 </table>';
418 break;
419 case 'errors':
420
421 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('serdata,exec_time,query,script','tx_dbal_debuglog','errorFlag>0','','tstamp DESC');
422
423 // Init vars in which to pick up the query result:
424 $tRows = array();
425 $tRows[] = '
426 <tr>
427 <td>Execution time</td>
428 <td>Error data</td>
429 <td>Script</td>
430 <td>Query</td>
431 </tr>';
432
433 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
434 // Create output row
435 $tRows[] = '
436 <tr>
437 <td>'.htmlspecialchars($row['exec_time']).'</td>
438 <td>'.t3lib_div::view_array(unserialize($row['serdata'])).'</td>
439 <td>'.htmlspecialchars($row['script']).'</td>
440 <td>'.htmlspecialchars($row['query']).'</td>
441 </tr>';
442 }
443
444 // Printing data rows:
445 $outStr.= '
446 <table border="1" cellspacing="0">'.implode('',$tRows).'
447 </table>';
448 break;
449 case 'parsing':
450 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('query,serdata','tx_dbal_debuglog','errorFlag&2=2');
451 $tRows = array();
452 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
453 // Create output row
454 $tRows[] = '
455 <tr>
456 <td>'.htmlspecialchars($row['query']).'</td>
457 </tr>';
458 }
459
460 // Printing data rows:
461 $outStr.= '
462 <table border="1" cellspacing="0">'.implode('',$tRows).'
463 </table>';
464 break;
465 case 'where':
466 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script,tablename,whereclause','tx_dbal_debuglog_where','','','tstamp DESC');
467 $tRows = array();
468 $tRows[] = '
469 <tr>
470 <td>Time</td>
471 <td>Script</td>
472 <td>Table</td>
473 <td>WHERE clause</td>
474 </tr>';
475 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
476 $tRows[] = '
477 <tr>
478 <td>'.t3lib_BEfunc::datetime($row['tstamp']).'</td>
479 <td>'.htmlspecialchars($row['script']).'</td>
480 <td>'.htmlspecialchars($row['tablename']).'</td>
481 <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>
482 </tr>';
483 }
484
485 $outStr = '
486 <table border="1" cellspacing="0">'.implode('',$tRows).'
487 </table>';
488 break;
489 default:
490
491 // Look for request to view specific script exec:
492 $specTime = t3lib_div::_GP('specTime');
493
494 if ($specTime) {
495 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','tx_dbal_debuglog','tstamp='.intval($specTime));
496 $tRows = array();
497 $tRows[] = '
498 <tr>
499 <td>Execution time</td>
500 <td>Error</td>
501 <td>Table joins</td>
502 <td>Data</td>
503 <td>Query</td>
504 </tr>';
505 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
506 $tRows[] = '
507 <tr>
508 <td>'.htmlspecialchars($row['exec_time']).'</td>
509 <td>'.($row['errorFlag'] ? 1 : 0).'</td>
510 <td>'.htmlspecialchars($row['table_join']).'</td>
511 <td>'.t3lib_div::view_array(unserialize($row['serdata'])).'</td>
512 <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>
513 </tr>';
514 }
515 } else {
516 $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');
517 $tRows = array();
518 $tRows[] = '
519 <tr>
520 <td>Time</td>
521 <td># of queries</td>
522 <td>Error</td>
523 <td>Time (ms)</td>
524 <td>Script</td>
525 </tr>';
526 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
527 $tRows[] = '
528 <tr>
529 <td>'.t3lib_BEfunc::datetime($row['tstamp']).'</td>
530 <td>'.htmlspecialchars($row['qrycount']).'</td>
531 <td>'.($row['error'] ? '<strong style="color:#f00">ERR</strong>' : '').'</td>
532 <td>'.htmlspecialchars($row['calc_sum']).'</td>
533 <td><a href="index.php?specTime='.intval($row['tstamp']).'">'.htmlspecialchars($row['script']).'</a></td>
534 </tr>';
535 }
536 }
537 $outStr = '
538 <table border="1" cellspacing="0">'.implode('',$tRows).'
539 </table>';
540
541 break;
542 }
543
544 $menu = '
545 <a href="index.php?cmd=flush">FLUSH LOG</a> -
546 <a href="index.php?cmd=joins">JOINS</a> -
547 <a href="index.php?cmd=errors">ERRORS</a> -
548 <a href="index.php?cmd=parsing">PARSING</a> -
549 <a href="index.php">LOG</a> -
550 <a href="index.php?cmd=where">WHERE</a> -
551
552 <a href="'.htmlspecialchars(t3lib_div::linkThisScript()).'" target="tx_debuglog">[New window]</a>
553 <hr />
554 ';
555 return $menu.$outStr;
556 }
557 }
558
559 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']) {
560 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']);
561 }
562
563
564
565
566 // Make instance:
567 $SOBE = t3lib_div::makeInstance('tx_dbal_module1');
568 $SOBE->init();
569 $SOBE->main();
570 $SOBE->printContent();
571 ?>