PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/sysext/dbal/mod1/index.php

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