PageRenderTime 51ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/pma/libraries/db_info.inc.php

https://bitbucket.org/pavolve/masterskayaludmila
PHP | 266 lines | 166 code | 31 blank | 69 comment | 59 complexity | 91dfa5b07406895f9952ae2f0f20fa4e MD5 | raw file
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Gets the list of the table in the current db and informations about these
  5. * tables if possible
  6. *
  7. * fills tooltip arrays and provides $tables, $num_tables, $is_show_stats
  8. * and $db_is_information_schema
  9. *
  10. * speedup view on locked tables
  11. *
  12. * @package PhpMyAdmin
  13. */
  14. if (! defined('PHPMYADMIN')) {
  15. exit;
  16. }
  17. /**
  18. * requirements
  19. */
  20. require_once './libraries/common.inc.php';
  21. /**
  22. * limits for table list
  23. */
  24. if (! isset($_SESSION['tmp_user_values']['table_limit_offset']) || $_SESSION['tmp_user_values']['table_limit_offset_db'] != $db) {
  25. $_SESSION['tmp_user_values']['table_limit_offset'] = 0;
  26. $_SESSION['tmp_user_values']['table_limit_offset_db'] = $db;
  27. }
  28. if (isset($_REQUEST['pos'])) {
  29. $_SESSION['tmp_user_values']['table_limit_offset'] = (int) $_REQUEST['pos'];
  30. }
  31. $pos = $_SESSION['tmp_user_values']['table_limit_offset'];
  32. /**
  33. * fills given tooltip arrays
  34. *
  35. * @param array $tooltip_truename tooltip data
  36. * @param array $tooltip_aliasname tooltip data
  37. * @param array $table tabledata
  38. */
  39. function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
  40. {
  41. if (strstr($table['Comment'], '; InnoDB free') === false) {
  42. if (!strstr($table['Comment'], 'InnoDB free') === false) {
  43. // here we have just InnoDB generated part
  44. $table['Comment'] = '';
  45. }
  46. } else {
  47. // remove InnoDB comment from end, just the minimal part (*? is non greedy)
  48. $table['Comment'] = preg_replace('@; InnoDB free:.*?$@', '', $table['Comment']);
  49. }
  50. // views have VIEW as comment so it's not a real comment put by a user
  51. if ('VIEW' == $table['Comment']) {
  52. $table['Comment'] = '';
  53. }
  54. if (empty($table['Comment'])) {
  55. $table['Comment'] = $table['Name'];
  56. } else {
  57. // why?
  58. $table['Comment'] .= ' ';
  59. }
  60. if ($GLOBALS['cfg']['ShowTooltipAliasTB']
  61. && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested') {
  62. $tooltip_truename[$table['Name']] = $table['Comment'];
  63. $tooltip_aliasname[$table['Name']] = $table['Name'];
  64. } else {
  65. $tooltip_truename[$table['Name']] = $table['Name'];
  66. $tooltip_aliasname[$table['Name']] = $table['Comment'];
  67. }
  68. if (isset($table['Create_time']) && !empty($table['Create_time'])) {
  69. $tooltip_aliasname[$table['Name']] .= ', ' . __('Creation')
  70. . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
  71. }
  72. if (! empty($table['Update_time'])) {
  73. $tooltip_aliasname[$table['Name']] .= ', ' . __('Last update')
  74. . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
  75. }
  76. if (! empty($table['Check_time'])) {
  77. $tooltip_aliasname[$table['Name']] .= ', ' . __('Last check')
  78. . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
  79. }
  80. }
  81. PMA_checkParameters(array('db'));
  82. /**
  83. * @global bool whether to display extended stats
  84. */
  85. $is_show_stats = $cfg['ShowStats'];
  86. /**
  87. * @global bool whether selected db is information_schema
  88. */
  89. $db_is_information_schema = false;
  90. if (PMA_is_system_schema($db)) {
  91. $is_show_stats = false;
  92. $db_is_information_schema = true;
  93. }
  94. /**
  95. * @global array information about tables in db
  96. */
  97. $tables = array();
  98. // When used in Nested table group mode, only show tables matching the given groupname
  99. if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
  100. $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
  101. } else {
  102. $tbl_group_sql = '';
  103. }
  104. if ($cfg['ShowTooltip']) {
  105. $tooltip_truename = array();
  106. $tooltip_aliasname = array();
  107. }
  108. // Special speedup for newer MySQL Versions (in 4.0 format changed)
  109. if (true === $cfg['SkipLockedTables']) {
  110. $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
  111. // Blending out tables in use
  112. if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
  113. while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
  114. // if in use memorize tablename
  115. if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
  116. $sot_cache[$tmp[0]] = true;
  117. }
  118. }
  119. PMA_DBI_free_result($db_info_result);
  120. if (isset($sot_cache)) {
  121. $db_info_result = PMA_DBI_query(
  122. 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
  123. null, PMA_DBI_QUERY_STORE);
  124. if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
  125. while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
  126. if (! isset($sot_cache[$tmp[0]])) {
  127. $sts_result = PMA_DBI_query(
  128. 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
  129. . ' LIKE \'' . PMA_sqlAddSlashes($tmp[0], true) . '\';');
  130. $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
  131. PMA_DBI_free_result($sts_result);
  132. unset($sts_result);
  133. if (! isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
  134. $sts_tmp['Type'] =& $sts_tmp['Engine'];
  135. }
  136. if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
  137. && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
  138. continue;
  139. }
  140. if ($cfg['ShowTooltip']) {
  141. PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
  142. }
  143. $tables[$sts_tmp['Name']] = $sts_tmp;
  144. } else { // table in use
  145. $tables[$tmp[0]] = array('Name' => $tmp[0]);
  146. }
  147. }
  148. if ($GLOBALS['cfg']['NaturalOrder']) {
  149. uksort($tables, 'strnatcasecmp');
  150. }
  151. $sot_ready = true;
  152. } elseif ($db_info_result) {
  153. PMA_DBI_free_result($db_info_result);
  154. }
  155. unset($sot_cache);
  156. }
  157. unset($tmp);
  158. } elseif ($db_info_result) {
  159. PMA_DBI_free_result($db_info_result);
  160. }
  161. }
  162. if (! isset($sot_ready)) {
  163. // Set some sorting defaults
  164. $sort = 'Name';
  165. $sort_order = 'ASC';
  166. if (isset($_REQUEST['sort'])) {
  167. $sortable_name_mappings = array(
  168. 'table' => 'Name',
  169. 'records' => 'Rows',
  170. 'type' => 'Engine',
  171. 'collation' => 'Collation',
  172. 'size' => 'Data_length',
  173. 'overhead' => 'Data_free'
  174. );
  175. // Make sure the sort type is implemented
  176. if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
  177. $sort = $sortable_name_mappings[$_REQUEST['sort']];
  178. if ($_REQUEST['sort_order'] == 'DESC') {
  179. $sort_order = 'DESC';
  180. }
  181. }
  182. }
  183. if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
  184. // only tables for selected group
  185. $tables = PMA_DBI_get_tables_full($db, $tbl_group, true, null, 0, false, $sort, $sort_order);
  186. } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
  187. // only tables for selected group,
  188. // but grouping is done on comment ...
  189. $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment', null, 0, false, $sort, $sort_order);
  190. } else {
  191. // all tables in db
  192. // - get the total number of tables
  193. // (needed for proper working of the MaxTableList feature)
  194. $tables = PMA_DBI_get_tables($db);
  195. $total_num_tables = count($tables);
  196. if (isset($sub_part) && $sub_part == '_export') {
  197. // (don't fetch only a subset if we are coming from db_export.php,
  198. // because I think it's too risky to display only a subset of the
  199. // table names when exporting a db)
  200. /**
  201. *
  202. * @todo Page selector for table names?
  203. */
  204. $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false, $sort, $sort_order);
  205. } else {
  206. // fetch the details for a possible limited subset
  207. $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true, $sort, $sort_order);
  208. }
  209. }
  210. if ($cfg['ShowTooltip']) {
  211. foreach ($tables as $each_table) {
  212. PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
  213. }
  214. }
  215. }
  216. /**
  217. * @global int count of tables in db
  218. */
  219. $num_tables = count($tables);
  220. // (needed for proper working of the MaxTableList feature)
  221. if (! isset($total_num_tables)) {
  222. $total_num_tables = $num_tables;
  223. }
  224. /**
  225. * cleanup
  226. */
  227. unset($each_table, $tbl_group_sql, $db_info_result);
  228. /**
  229. * Displays top menu links
  230. * If in an Ajax request, we do not need to show this
  231. */
  232. if ($GLOBALS['is_ajax_request'] != true) {
  233. include './libraries/db_links.inc.php';
  234. }
  235. ?>