Translation update done using Pootle.
[phpmyadmin.git] / libraries / db_info.inc.php
blob80b8c510b4f7901a331f65516bc81500351cdc36
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 if (empty($table['Comment'])) {
54 $table['Comment'] = $table['Name'];
55 } else {
56 // why?
57 $table['Comment'] .= ' ';
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'];
69 if (isset($table['Create_time']) && !empty($table['Create_time'])) {
70 $tooltip_aliasname[$table['Name']] .= ', ' . __('Creation')
71 . ': ' . PMA_localisedDate(strtotime($table['Create_time']));
74 if (! empty($table['Update_time'])) {
75 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last update')
76 . ': ' . PMA_localisedDate(strtotime($table['Update_time']));
79 if (! empty($table['Check_time'])) {
80 $tooltip_aliasname[$table['Name']] .= ', ' . __('Last check')
81 . ': ' . PMA_localisedDate(strtotime($table['Check_time']));
85 PMA_checkParameters(array('db'));
87 /**
88 * @global bool whether to display extended stats
90 $is_show_stats = $cfg['ShowStats'];
92 /**
93 * @global bool whether selected db is information_schema
95 $db_is_information_schema = false;
97 if (PMA_is_system_schema($db)) {
98 $is_show_stats = false;
99 $db_is_information_schema = true;
103 * @global array information about tables in db
105 $tables = array();
107 // When used in Nested table group mode, only show tables matching the given groupname
108 if (PMA_isValid($tbl_group) && !$cfg['ShowTooltipAliasTB']) {
109 $tbl_group_sql = ' LIKE "' . PMA_escape_mysql_wildcards($tbl_group) . '%"';
110 } else {
111 $tbl_group_sql = '';
114 if ($cfg['ShowTooltip']) {
115 $tooltip_truename = array();
116 $tooltip_aliasname = array();
119 // Special speedup for newer MySQL Versions (in 4.0 format changed)
120 if (true === $cfg['SkipLockedTables']) {
121 $db_info_result = PMA_DBI_query('SHOW OPEN TABLES FROM ' . PMA_backquote($db) . ';');
123 // Blending out tables in use
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 in use memorize tablename
127 if (preg_match('@in_use=[1-9]+@i', $tmp[1])) {
128 $sot_cache[$tmp[0]] = true;
131 PMA_DBI_free_result($db_info_result);
133 if (isset($sot_cache)) {
134 $db_info_result = PMA_DBI_query(
135 'SHOW TABLES FROM ' . PMA_backquote($db) . $tbl_group_sql . ';',
136 null, PMA_DBI_QUERY_STORE);
137 if ($db_info_result && PMA_DBI_num_rows($db_info_result) > 0) {
138 while ($tmp = PMA_DBI_fetch_row($db_info_result)) {
139 if (! isset($sot_cache[$tmp[0]])) {
140 $sts_result = PMA_DBI_query(
141 'SHOW TABLE STATUS FROM ' . PMA_backquote($db)
142 . ' LIKE \'' . PMA_sqlAddSlashes($tmp[0], true) . '\';');
143 $sts_tmp = PMA_DBI_fetch_assoc($sts_result);
144 PMA_DBI_free_result($sts_result);
145 unset($sts_result);
147 if (! isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) {
148 $sts_tmp['Type'] =& $sts_tmp['Engine'];
151 if (!empty($tbl_group) && $cfg['ShowTooltipAliasTB']
152 && !preg_match('@' . preg_quote($tbl_group, '@') . '@i', $sts_tmp['Comment'])) {
153 continue;
156 if ($cfg['ShowTooltip']) {
157 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $sts_tmp);
160 $tables[$sts_tmp['Name']] = $sts_tmp;
161 } else { // table in use
162 $tables[$tmp[0]] = array('Name' => $tmp[0]);
165 if ($GLOBALS['cfg']['NaturalOrder']) {
166 uksort($tables, 'strnatcasecmp');
169 $sot_ready = true;
170 } elseif ($db_info_result) {
171 PMA_DBI_free_result($db_info_result);
173 unset($sot_cache);
175 unset($tmp);
176 } elseif ($db_info_result) {
177 PMA_DBI_free_result($db_info_result);
181 if (! isset($sot_ready)) {
183 // Set some sorting defaults
184 $sort = 'Name';
185 $sort_order = 'ASC';
187 if (isset($_REQUEST['sort'])) {
188 $sortable_name_mappings = array(
189 'table' => 'Name',
190 'records' => 'Rows',
191 'type' => 'Engine',
192 'collation' => 'Collation',
193 'size' => 'Data_length',
194 'overhead' => 'Data_free'
197 // Make sure the sort type is implemented
198 if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
199 $sort = $sortable_name_mappings[$_REQUEST['sort']];
200 if ($_REQUEST['sort_order'] == 'DESC') {
201 $sort_order = 'DESC';
206 if (! empty($tbl_group) && ! $cfg['ShowTooltipAliasTB']) {
207 // only tables for selected group
208 $tables = PMA_DBI_get_tables_full($db, $tbl_group, true, null, 0, false, $sort, $sort_order);
209 } elseif (! empty($tbl_group) && $cfg['ShowTooltipAliasTB']) {
210 // only tables for selected group,
211 // but grouping is done on comment ...
212 $tables = PMA_DBI_get_tables_full($db, $tbl_group, 'comment', null, 0, false, $sort, $sort_order);
213 } else {
214 // all tables in db
215 // - get the total number of tables
216 // (needed for proper working of the MaxTableList feature)
217 $tables = PMA_DBI_get_tables($db);
218 $total_num_tables = count($tables);
219 if (isset($sub_part) && $sub_part == '_export') {
220 // (don't fetch only a subset if we are coming from db_export.php,
221 // because I think it's too risky to display only a subset of the
222 // table names when exporting a db)
225 * @todo Page selector for table names?
227 $tables = PMA_DBI_get_tables_full($db, false, false, null, 0, false, $sort, $sort_order);
228 } else {
229 // fetch the details for a possible limited subset
230 $tables = PMA_DBI_get_tables_full($db, false, false, null, $pos, true, $sort, $sort_order);
234 if ($cfg['ShowTooltip']) {
235 foreach ($tables as $each_table) {
236 PMA_fillTooltip($tooltip_truename, $tooltip_aliasname, $each_table);
242 * @global int count of tables in db
244 $num_tables = count($tables);
245 // (needed for proper working of the MaxTableList feature)
246 if (! isset($total_num_tables)) {
247 $total_num_tables = $num_tables;
251 * cleanup
253 unset($each_table, $tbl_group_sql, $db_info_result);
256 * Displays top menu links
257 * If in an Ajax request, we do not need to show this
259 if ($GLOBALS['is_ajax_request'] != true) {
260 require './libraries/db_links.inc.php';