Update of DBAL sysext to 0.9.9
[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-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 = '<table border="1" cellspacing="0"><caption>auto_increment</caption><tbody><tr><th>Table</th><th>Field</th></tr>';
307 ksort($GLOBALS['TYPO3_DB']->cache_autoIncFields);
308 foreach($GLOBALS['TYPO3_DB']->cache_autoIncFields as $table => $field) {
309 $out .= '<tr>';
310 $out .= '<td>'.$table.'</td>';
311 $out .= '<td>'.$field.'</td>';
312 $out .= '</tr>';
313 }
314 $out .= '</tbody></table>';
315 $out .= $this->doc->spacer(5);
316 $out .= '<table border="1" cellspacing="0"><caption>Primary keys</caption><tbody><tr><th>Table</th><th>Field(s)</th></tr>';
317 ksort($GLOBALS['TYPO3_DB']->cache_primaryKeys);
318 foreach($GLOBALS['TYPO3_DB']->cache_primaryKeys as $table => $field) {
319 $out .= '<tr>';
320 $out .= '<td>'.$table.'</td>';
321 $out .= '<td>'.$field.'</td>';
322 $out .= '</tr>';
323 }
324 $out .= '</tbody></table>';
325 $out .= $this->doc->spacer(5);
326 $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>';
327 ksort($GLOBALS['TYPO3_DB']->cache_fieldType);
328 foreach($GLOBALS['TYPO3_DB']->cache_fieldType as $table => $fields) {
329 $out .= '<th colspan="4">'.$table.'</th>';
330 foreach($fields as $field => $data) {
331 $out .= '<tr>';
332 $out .= '<td>'.$field.'</td>';
333 $out .= '<td>'.$data['type'].'</td>';
334 $out .= '<td>'.$data['metaType'].'</td>';
335 $out .= '<td>'.$data['notnull'].'</td>';
336 $out .= '</tr>';
337 }
338 }
339 $out .= '</tbody></table>';
340
341 $menu = '<a href="index.php?cmd=clear">CLEAR DATA</a><hr />';
342
343 return $menu.$out;
344 }
345
346 /**
347 * Printing the debug-log from the DBAL extension
348 *
349 * To enabled debugging, you will have to enabled it in the configuration!
350 *
351 * @return string HTML content
352 */
353 function printLogMgm() {
354
355 // Disable debugging in any case...
356 $GLOBALS['TYPO3_DB']->debug = FALSE;
357
358 // Get cmd:
359 $cmd = (string)t3lib_div::_GP('cmd');
360 switch($cmd) {
361 case 'flush':
362 $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog','');
363 $res = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_dbal_debuglog_where','');
364 $outStr = 'Log FLUSHED!';
365 break;
366 case 'joins':
367 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('table_join,exec_time,query,script','tx_dbal_debuglog','table_join!=\'\'', 'table_join,script,exec_time,query');
368
369 // Init vars in which to pick up the query result:
370 $tableIndex = array();
371 $tRows = array();
372 $tRows[] = '
373 <tr>
374 <td>Execution time</td>
375 <td>Table joins</td>
376 <td>Script</td>
377 <td>Query</td>
378 </tr>';
379
380 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
381 $tableArray = $GLOBALS['TYPO3_DB']->SQLparser->parseFromTables($row['table_join']);
382
383 // Create table name index:
384 foreach($tableArray as $a) {
385 foreach($tableArray as $b) {
386 if ($b['table']!=$a['table']) {
387 $tableIndex[$a['table']][$b['table']]=1;
388 }
389 }
390 }
391
392 // Create output row
393 $tRows[] = '
394 <tr>
395 <td>'.htmlspecialchars($row['exec_time']).'</td>
396 <td>'.htmlspecialchars($row['table_join']).'</td>
397 <td>'.htmlspecialchars($row['script']).'</td>
398 <td>'.htmlspecialchars($row['query']).'</td>
399 </tr>';
400 }
401
402 // Printing direct joins:
403 $outStr.= '<h4>Direct joins:</h4>'.t3lib_div::view_array($tableIndex);
404
405
406 // Printing total dependencies:
407 foreach($tableIndex as $priTable => $a) {
408 foreach($tableIndex as $tableN => $v) {
409 foreach($v as $tableP => $vv) {
410 if ($tableP == $priTable) {
411 $tableIndex[$priTable] = array_merge($v, $a);
412 }
413 }
414 }
415 }
416 $outStr.= '<h4>Total dependencies:</h4>'.t3lib_div::view_array($tableIndex);
417
418 // Printing data rows:
419 $outStr.= '
420 <table border="1" cellspacing="0">'.implode('',$tRows).'
421 </table>';
422 break;
423 case 'errors':
424
425 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('serdata,exec_time,query,script','tx_dbal_debuglog','errorFlag>0','','tstamp DESC');
426
427 // Init vars in which to pick up the query result:
428 $tRows = array();
429 $tRows[] = '
430 <tr>
431 <td>Execution time</td>
432 <td>Error data</td>
433 <td>Script</td>
434 <td>Query</td>
435 </tr>';
436
437 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
438 // Create output row
439 $tRows[] = '
440 <tr>
441 <td>'.htmlspecialchars($row['exec_time']).'</td>
442 <td>'.t3lib_div::view_array(unserialize($row['serdata'])).'</td>
443 <td>'.htmlspecialchars($row['script']).'</td>
444 <td>'.htmlspecialchars($row['query']).'</td>
445 </tr>';
446 }
447
448 // Printing data rows:
449 $outStr.= '
450 <table border="1" cellspacing="0">'.implode('',$tRows).'
451 </table>';
452 break;
453 case 'parsing':
454 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('query,serdata','tx_dbal_debuglog','errorFlag&2=2');
455 $tRows = array();
456 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
457 // Create output row
458 $tRows[] = '
459 <tr>
460 <td>'.htmlspecialchars($row['query']).'</td>
461 </tr>';
462 }
463
464 // Printing data rows:
465 $outStr.= '
466 <table border="1" cellspacing="0">'.implode('',$tRows).'
467 </table>';
468 break;
469 case 'where':
470 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('tstamp,script,tablename,whereclause','tx_dbal_debuglog_where','','','tstamp DESC');
471 $tRows = array();
472 $tRows[] = '
473 <tr>
474 <td>Time</td>
475 <td>Script</td>
476 <td>Table</td>
477 <td>WHERE clause</td>
478 </tr>';
479 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
480 $tRows[] = '
481 <tr>
482 <td>'.t3lib_BEfunc::datetime($row['tstamp']).'</td>
483 <td>'.htmlspecialchars($row['script']).'</td>
484 <td>'.htmlspecialchars($row['tablename']).'</td>
485 <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>
486 </tr>';
487 }
488
489 $outStr = '
490 <table border="1" cellspacing="0">'.implode('',$tRows).'
491 </table>';
492 break;
493 default:
494
495 // Look for request to view specific script exec:
496 $specTime = t3lib_div::_GP('specTime');
497
498 if ($specTime) {
499 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*','tx_dbal_debuglog','tstamp='.intval($specTime));
500 $tRows = array();
501 $tRows[] = '
502 <tr>
503 <td>Execution time</td>
504 <td>Error</td>
505 <td>Table joins</td>
506 <td>Data</td>
507 <td>Query</td>
508 </tr>';
509 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
510 $tRows[] = '
511 <tr>
512 <td>'.htmlspecialchars($row['exec_time']).'</td>
513 <td>'.($row['errorFlag'] ? 1 : 0).'</td>
514 <td>'.htmlspecialchars($row['table_join']).'</td>
515 <td>'.t3lib_div::view_array(unserialize($row['serdata'])).'</td>
516 <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>
517 </tr>';
518 }
519 } else {
520 $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');
521 $tRows = array();
522 $tRows[] = '
523 <tr>
524 <td>Time</td>
525 <td># of queries</td>
526 <td>Error</td>
527 <td>Time (ms)</td>
528 <td>Script</td>
529 </tr>';
530 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
531 $tRows[] = '
532 <tr>
533 <td>'.t3lib_BEfunc::datetime($row['tstamp']).'</td>
534 <td>'.htmlspecialchars($row['qrycount']).'</td>
535 <td>'.($row['error'] ? '<strong style="color:#f00">ERR</strong>' : '').'</td>
536 <td>'.htmlspecialchars($row['calc_sum']).'</td>
537 <td><a href="index.php?specTime='.intval($row['tstamp']).'">'.htmlspecialchars($row['script']).'</a></td>
538 </tr>';
539 }
540 }
541 $outStr = '
542 <table border="1" cellspacing="0">'.implode('',$tRows).'
543 </table>';
544
545 break;
546 }
547
548 $menu = '
549 <a href="index.php?cmd=flush">FLUSH LOG</a> -
550 <a href="index.php?cmd=joins">JOINS</a> -
551 <a href="index.php?cmd=errors">ERRORS</a> -
552 <a href="index.php?cmd=parsing">PARSING</a> -
553 <a href="index.php">LOG</a> -
554 <a href="index.php?cmd=where">WHERE</a> -
555
556 <a href="'.htmlspecialchars(t3lib_div::linkThisScript()).'" target="tx_debuglog">[New window]</a>
557 <hr />
558 ';
559 return $menu.$outStr;
560 }
561 }
562
563 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']) {
564 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/dbal/mod1/index.php']);
565 }
566
567
568
569
570 // Make instance:
571 $SOBE = t3lib_div::makeInstance('tx_dbal_module1');
572 $SOBE->init();
573 $SOBE->main();
574 $SOBE->printContent();
575 ?>