Translation update done using Pootle.
[phpmyadmin.git] / libraries / db_info.inc.php
blobc296f711229dc03b6dc403a491f2de33c11186ed
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
7 * fills tooltip arrays and provides $tables, $num_tables, $is_show_stats
8 * and $db_is_information_schema
10 * speedup view on locked tables
12 * @package PhpMyAdmin
14 if (! defined('PHPMYADMIN')) {
15 exit;
18 /**
19 * requirements
21 require_once './libraries/common.inc.php';
23 /**
24 * limits for table list
26 if (! isset($_SESSION['tmp_user_values']['table_limit_offset']) || $_SESSION['tmp_user_values']['table_limit_offset_db'] != $db) {
27 $_SESSION['tmp_user_values']['table_limit_offset'] = 0;
28 $_SESSION['tmp_user_values']['table_limit_offset_db'] = $db;
30 if (isset($_REQUEST['pos'])) {
31 $_SESSION['tmp_user_values']['table_limit_offset'] = (int) $_REQUEST['pos'];
33 $pos = $_SESSION['tmp_user_values']['table_limit_offset'];
35 /**
36 * fills given tooltip arrays
38 * @param array $tooltip_truename tooltip data
39 * @param array $tooltip_aliasname tooltip data
40 * @param array $table tabledata
42 function PMA_fillTooltip(&$tooltip_truename, &$tooltip_aliasname, $table)
44 if (strstr($table['Comment'], '; InnoDB free') === false) {
45 if (!strstr($table['Comment'], 'InnoDB free') === false) {
46 // here we have just InnoDB generated part
47 $table['Comment'] = '';
49 } else {
50 // remove InnoDB comment from end, just the minimal part (*? is non greedy)
51 $table['Comment'] = preg_replace('@; InnoDB free:.*?$@', '', $table['Comment']);
53 // views have VIEW as comment so it's not a real comment put by a user
54 if ('VIEW' == $table['Comment']) {
55 $table['Comment'] = '';
57 if (empty($table['Comment'])) {
58 $table['Comment'] = $table['Name'];
59 } else {
60 // why?
61 $table['Comment'] .= ' ';
64 if ($GLOBALS['cfg']['ShowTooltipAliasTB']
65 && $GLOBALS['cfg']['ShowTooltipAliasTB'] !== 'nested') {
66 $tooltip_truename[$table['Name']] = $table['Comment'];
67 $tooltip_aliasname[$table['Name']] = $table['Name'];
68 } else {
69 $tooltip_truename[$table['Name']] = $table['Name'];
70 $tooltip_aliasname[$table['Name']] = $table['Comment'];
73 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
74 $tooltip_aliasname[$table['Name']] .= ', ' . __('Creation')
75 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
78 if (! empty($table['Update_time'])) {
79 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last update')
80 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
83 if (! empty($table['Check_time'])) {
84 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last check')
85 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
89 PMA_checkParameters(array('db'));
91 /**
92 * @global bool whether to display extended stats
94 $is_show_stats = $cfg['ShowStats'];
96 /**
97 * @global bool whether selected db is information_schema
99 $db_is_information_schema = false;
101 if (PMA_is_system_schema($db)) {
102 $is_show_stats = false;
103 $db_is_information_schema = true;
107 * @global array information about tables in db
109 $tables = array();
111 // When used in Nested table group mode, only show tables matching the given groupname
112 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
113 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
114 } else {
115 $tbl_group_sql = '';
118 if ($cfg['ShowTooltip']) {
119 $tooltip_truename = array();
120 $tooltip_aliasname = array();
123 // Special speedup for newer MySQL Versions (in 4.0 format changed)
124 if (true === $cfg['SkipLockedTables']) {
125 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
127 // Blending out tables in use
128 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
129 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
130 // if in use memorize tablename
131 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
132 $sot_cache[$tmp[0]] = true;
135 PMA_DBI_free_result($db_info_result);
137 if (isset($sot_cache)) {
138 $db_info_result = PMA_DBI_query(
139 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
140 null, PMA_DBI_QUERY_STORE);
141 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
142 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
143 if (! isset($sot_cache[$tmp[0]])) {
144 $sts_result = PMA_DBI_query(
145 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
146 . ' LIKE \'' . PMA_sqlAddSlashes($tmp[0], true) . '\';');
147 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
148 PMA_DBI_free_result($sts_result);
149 unset($sts_result);
151 if (! isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
152 $sts_tmp['Type'] =& $sts_tmp['Engine'];
155 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
156 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
157 continue;
160 if ($cfg['ShowTooltip']) {
161 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
164 $tables[$sts_tmp['Name']] = $sts_tmp;
165 } else { // table in use
166 $tables[$tmp[0]] = array('Name' => $tmp[0]);
169 if ($GLOBALS['cfg']['NaturalOrder']) {
170 uksort($tables, 'strnatcasecmp');
173 $sot_ready = true;
174 } elseif ($db_info_result) {
175 PMA_DBI_free_result($db_info_result);
177 unset($sot_cache);
179 unset($tmp);
180 } elseif ($db_info_result) {
181 PMA_DBI_free_result($db_info_result);
185 if (! isset($sot_ready)) {
187 // Set some sorting defaults
188 $sort = 'Name';
189 $sort_order = 'ASC';
191 if (isset($_REQUEST['sort'])) {
192 $sortable_name_mappings = array(
193 'table' => 'Name',
194 'records' => 'Rows',
195 'type' => 'Engine',
196 'collation' => 'Collation',
197 'size' => 'Data_length',
198 'overhead' => 'Data_free'
201 // Make sure the sort type is implemented
202 if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
203 $sort = $sortable_name_mappings[$_REQUEST['sort']];
204 if ($_REQUEST['sort_order'] == 'DESC') {
205 $sort_order = 'DESC';
210 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
211 // only tables for selected group
212 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true, null, 0, false, $sort, $sort_order);
213 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
214 // only tables for selected group,
215 // but grouping is done on comment ...
216 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment', null, 0, false, $sort, $sort_order);
217 } else {
218 // all tables in db
219 // - get the total number of tables
220 // (needed for proper working of the MaxTableList feature)
221 $tables = PMA_DBI_get_tables($db);
222 $total_num_tables = count($tables);
223 if (isset($sub_part) && $sub_part == '_export') {
224 // (don't fetch only a subset if we are coming from db_export.php,
225 // because I think it's too risky to display only a subset of the
226 // table names when exporting a db)
229 * @todo Page selector for table names?
231 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false, $sort, $sort_order);
232 } else {
233 // fetch the details for a possible limited subset
234 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true, $sort, $sort_order);
238 if ($cfg['ShowTooltip']) {
239 foreach ($tables as $each_table) {
240 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
246 * @global int count of tables in db
248 $num_tables = count($tables);
249 // (needed for proper working of the MaxTableList feature)
250 if (! isset($total_num_tables)) {
251 $total_num_tables = $num_tables;
255 * cleanup
257 unset($each_table, $tbl_group_sql, $db_info_result);
260 * Displays top menu links
261 * If in an Ajax request, we do not need to show this
263 if ($GLOBALS['is_ajax_request'] != true) {
264 include './libraries/db_links.inc.php';