added japanese language
[openemr.git] / phpmyadmin / libraries / db_info.inc.php
blobb33e06e7bf2aa60a75d0160461777b901616d3fd
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_system_schema
10 * speedup view on locked tables
12 * @package PhpMyAdmin
14 if (! defined('PHPMYADMIN')) {
15 exit;
18 /**
19 * limits for table list
21 if (! isset($_SESSION['tmpval']['table_limit_offset'])
22 || $_SESSION['tmpval']['table_limit_offset_db'] != $db
23 ) {
24 $_SESSION['tmpval']['table_limit_offset'] = 0;
25 $_SESSION['tmpval']['table_limit_offset_db'] = $db;
27 if (isset($_REQUEST['pos'])) {
28 $_SESSION['tmpval']['table_limit_offset'] = (int) $_REQUEST['pos'];
30 $pos = $_SESSION['tmpval']['table_limit_offset'];
32 PMA_Util::checkParameters(array('db'));
34 /**
35 * @global bool whether to display extended stats
37 $is_show_stats = $cfg['ShowStats'];
39 /**
40 * @global bool whether selected db is information_schema
42 $db_is_system_schema = false;
44 if ($GLOBALS['dbi']->isSystemSchema($db)) {
45 $is_show_stats = false;
46 $db_is_system_schema = true;
49 /**
50 * @global array information about tables in db
52 $tables = array();
54 $tooltip_truename = array();
55 $tooltip_aliasname = array();
57 // Special speedup for newer MySQL Versions (in 4.0 format changed)
58 if (true === $cfg['SkipLockedTables'] && ! PMA_DRIZZLE) {
59 $db_info_result = $GLOBALS['dbi']->query(
60 'SHOW OPEN TABLES FROM ' . PMA_Util::backquote($db) . ';'
63 // Blending out tables in use
64 if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) {
65 while ($tmp = $GLOBALS['dbi']->fetchAssoc($db_info_result)) {
66 // if in use, memorize table name
67 if ($tmp['In_use'] > 0) {
68 $sot_cache[$tmp['Table']] = true;
71 $GLOBALS['dbi']->freeResult($db_info_result);
73 if (isset($sot_cache)) {
74 $db_info_result = false;
76 $tblGroupSql = "";
77 $whereAdded = false;
78 if (PMA_isValid($_REQUEST['tbl_group'])) {
79 $group = PMA_Util::escapeMysqlWildcards($_REQUEST['tbl_group']);
80 $groupWithSeperator = PMA_Util::escapeMysqlWildcards(
81 $_REQUEST['tbl_group']
82 . $GLOBALS['cfg']['NavigationTreeTableSeparator']
84 $tblGroupSql .= " WHERE ("
85 . PMA_Util::backquote('Tables_in_' . $db)
86 . " LIKE '" . $groupWithSeperator . "%'"
87 . " OR "
88 . PMA_Util::backquote('Tables_in_' . $db)
89 . " LIKE '" . $group . "')";
90 $whereAdded = true;
92 if (PMA_isValid($_REQUEST['tbl_type'], array('table', 'view'))) {
93 $tblGroupSql .= $whereAdded ? " AND" : " WHERE";
94 if ($_REQUEST['tbl_type'] == 'view') {
95 $tblGroupSql .= " `Table_type` != 'BASE TABLE'";
96 } else {
97 $tblGroupSql .= " `Table_type` = 'BASE TABLE'";
100 $db_info_result = $GLOBALS['dbi']->query(
101 'SHOW FULL TABLES FROM ' . PMA_Util::backquote($db) . $tblGroupSql,
102 null, PMA_DatabaseInterface::QUERY_STORE
104 unset($tblGroupSql, $whereAdded);
106 if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) {
107 while ($tmp = $GLOBALS['dbi']->fetchRow($db_info_result)) {
108 if (! isset($sot_cache[$tmp[0]])) {
109 $sts_result = $GLOBALS['dbi']->query(
110 "SHOW TABLE STATUS FROM " . PMA_Util::backquote($db)
111 . " LIKE '" . PMA_Util::sqlAddSlashes($tmp[0], true)
112 . "';"
114 $sts_tmp = $GLOBALS['dbi']->fetchAssoc($sts_result);
115 $GLOBALS['dbi']->freeResult($sts_result);
116 unset($sts_result);
118 $tableArray = $GLOBALS['dbi']->copyTableProperties(
119 array($sts_tmp), $db
121 $tables[$sts_tmp['Name']] = $tableArray[0];
122 } else { // table in use
123 $tables[$tmp[0]] = array(
124 'TABLE_NAME' => $tmp[0],
125 'ENGINE' => '',
126 'TABLE_TYPE' => '',
127 'TABLE_ROWS' => 0,
131 if ($GLOBALS['cfg']['NaturalOrder']) {
132 uksort($tables, 'strnatcasecmp');
135 $sot_ready = true;
136 } elseif ($db_info_result) {
137 $GLOBALS['dbi']->freeResult($db_info_result);
139 unset($sot_cache);
141 unset($tmp);
142 } elseif ($db_info_result) {
143 $GLOBALS['dbi']->freeResult($db_info_result);
147 if (! isset($sot_ready)) {
149 // Set some sorting defaults
150 $sort = 'Name';
151 $sort_order = 'ASC';
153 if (isset($_REQUEST['sort'])) {
154 $sortable_name_mappings = array(
155 'table' => 'Name',
156 'records' => 'Rows',
157 'type' => 'Engine',
158 'collation' => 'Collation',
159 'size' => 'Data_length',
160 'overhead' => 'Data_free',
161 'creation' => 'Create_time',
162 'last_update' => 'Update_time',
163 'last_check' => 'Check_time'
166 // Make sure the sort type is implemented
167 if (isset($sortable_name_mappings[$_REQUEST['sort']])) {
168 $sort = $sortable_name_mappings[$_REQUEST['sort']];
169 if ($_REQUEST['sort_order'] == 'DESC') {
170 $sort_order = 'DESC';
175 $tbl_group = false;
176 $groupWithSeperator = false;
177 $tbl_type = null;
178 $limit_offset = 0;
179 $limit_count = false;
180 $groupTable = array();
182 if (! empty($_REQUEST['tbl_group']) || ! empty($_REQUEST['tbl_type'])) {
183 if (! empty($_REQUEST['tbl_type'])) {
184 // only tables for selected type
185 $tbl_type = $_REQUEST['tbl_type'];
187 if (! empty($_REQUEST['tbl_group'])) {
188 // only tables for selected group
189 $tbl_group = $_REQUEST['tbl_group'];
190 // include the table with the exact name of the group if such exists
191 $groupTable = $GLOBALS['dbi']->getTablesFull(
192 $db, $tbl_group, false, null, $limit_offset,
193 $limit_count, $sort, $sort_order, $tbl_type
195 $groupWithSeperator = $tbl_group
196 . $GLOBALS['cfg']['NavigationTreeTableSeparator'];
198 } else {
199 // all tables in db
200 // - get the total number of tables
201 // (needed for proper working of the MaxTableList feature)
202 $tables = $GLOBALS['dbi']->getTables($db);
203 $total_num_tables = count($tables);
204 if (isset($sub_part) && $sub_part == '_export') {
205 // (don't fetch only a subset if we are coming from db_export.php,
206 // because I think it's too risky to display only a subset of the
207 // table names when exporting a db)
210 * @todo Page selector for table names?
212 } else {
213 // fetch the details for a possible limited subset
214 $limit_offset = $pos;
215 $limit_count = true;
218 $tables = array_merge(
219 $groupTable,
220 $GLOBALS['dbi']->getTablesFull(
221 $db, $groupWithSeperator, ($groupWithSeperator != false), null,
222 $limit_offset, $limit_count, $sort, $sort_order, $tbl_type
228 * @global int count of tables in db
230 $num_tables = count($tables);
231 // (needed for proper working of the MaxTableList feature)
232 if (! isset($total_num_tables)) {
233 $total_num_tables = $num_tables;
237 * cleanup
239 unset($each_table, $db_info_result);
242 * If coming from a Show MySQL link on the home page,
243 * put something in $sub_part
245 if (empty($sub_part)) {
246 $sub_part = '_structure';