1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
<?php /* vim: set expandtab sw=4 ts=4 sts=4: */ /** * Functionality for the navigation tree * * @package PhpMyAdmin-Navigation */ if (! defined('PHPMYADMIN')) { exit; }
/** * Represents a columns node in the navigation tree * * @package PhpMyAdmin-Navigation */ class Node_Table extends Node { /** * Initialises the class * * @param string $name An identifier for the new node * @param int $type Type of node, may be one of CONTAINER or OBJECT * @param bool $is_group Whether this object has been created * while grouping nodes * * @return Node_Table */ public function __construct($name, $type = Node::OBJECT, $is_group = false) { parent::__construct($name, $type, $is_group); switch ($GLOBALS['cfg']['NavigationTreeDefaultTabTable']) { case 'tbl_structure.php': $title = __('Structure'); break; case 'tbl_sql.php': $title = __('SQL'); break; case 'tbl_select.php': $title = __('Search'); break; case 'tbl_change.php': $title = __('Insert'); break; case 'sql.php': $title = __('Browse'); break; }
$this->icon = PMA_Util::getImage('b_browse.png', $title); $this->links = array( 'text' => $GLOBALS['cfg']['DefaultTabTable'] . '?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s' . '&pos=0&token=' . $GLOBALS['token'], 'icon' => $GLOBALS['cfg']['NavigationTreeDefaultTabTable'] . '?server=' . $GLOBALS['server'] . '&db=%2$s&table=%1$s&token=' . $GLOBALS['token'] ); $this->classes = 'table'; }
/** * Returns the number of children of type $type present inside this container * This method is overridden by the Node_Database and Node_Table classes * * @param string $type The type of item we are looking for * ('columns' or 'indexes') * @param string $searchClause A string used to filter the results of the query * * @return int */ public function getPresence($type = '', $searchClause = '') { $retval = 0; $db = $this->realParent()->real_name; $table = $this->real_name; switch ($type) { case 'columns': if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SELECT COUNT(*) "; $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` "; $query .= "WHERE `TABLE_NAME`='$table' "; $query .= "AND `TABLE_SCHEMA`='$db'"; $retval = (int)PMA_DBI_fetch_value($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW COLUMNS FROM $table FROM $db"; $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query)); } break; case 'indexes': $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW INDEXES FROM $table FROM $db"; $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query)); break; case 'triggers': if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SELECT COUNT(*) "; $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` "; $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' "; $query .= "AND `EVENT_OBJECT_TABLE`='$table'"; $retval = (int)PMA_DBI_fetch_value($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'"; $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query)); } break; default: break; } return $retval; }
/** * Returns the names of children of type $type present inside this container * This method is overridden by the Node_Database and Node_Table classes * * @param string $type The type of item we are looking for * ('tables', 'views', etc) * @param int $pos The offset of the list within the results * @param string $searchClause A string used to filter the results of the query * * @return array */ public function getData($type, $pos, $searchClause = '') { $maxItems = $GLOBALS['cfg']['MaxNavigationItems']; $retval = array(); $db = $this->realParent()->real_name; $table = $this->real_name; switch ($type) { case 'columns': if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SELECT `COLUMN_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` "; $query .= "WHERE `TABLE_NAME`='$table' "; $query .= "AND `TABLE_SCHEMA`='$db' "; $query .= "ORDER BY `COLUMN_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; $retval = PMA_DBI_fetch_result($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW COLUMNS FROM $table FROM $db"; $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Field']; $count++; } $pos--; } } } break; case 'indexes': $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW INDEXES FROM $table FROM $db"; $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if (! in_array($arr['Key_name'], $retval)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Key_name']; $count++; } $pos--; } } } break; case 'triggers': if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $db = PMA_Util::sqlAddSlashes($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SELECT `TRIGGER_NAME` AS `name` "; $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` "; $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' "; $query .= "AND `EVENT_OBJECT_TABLE`='$table' "; $query .= "ORDER BY `TRIGGER_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; $retval = PMA_DBI_fetch_result($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'"; $handle = PMA_DBI_try_query($query); if ($handle !== false) { $count = 0; while ($arr = PMA_DBI_fetch_array($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Trigger']; $count++; } $pos--; } } } break; default: break; } return $retval; } }
?>
|