2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Functionality for the navigation tree
6 * @package PhpMyAdmin-Navigation
8 if (! defined('PHPMYADMIN')) {
13 * Represents a columns node in the navigation tree
15 * @package PhpMyAdmin-Navigation
17 class Node_Table
extends Node
20 * Initialises the class
22 * @param string $name An identifier for the new node
23 * @param int $type Type of node, may be one of CONTAINER or OBJECT
24 * @param bool $is_group Whether this object has been created
25 * while grouping nodes
29 public function __construct($name, $type = Node
::OBJECT, $is_group = false)
31 parent
::__construct($name, $type, $is_group);
32 $this->icon
= PMA_Util
::getImage('b_browse.png');
34 'text' => 'sql.php?server=' . $GLOBALS['server']
35 . '&db=%2$s&table=%1$s'
36 . '&pos=0&token=' . $GLOBALS['token'],
37 'icon' => $GLOBALS['cfg']['NavigationTreeDefaultTabTable']
38 . '?server=' . $GLOBALS['server']
39 . '&db=%2$s&table=%1$s&token=' . $GLOBALS['token']
44 * Returns the number of children of type $type present inside this container
45 * This method is overridden by the Node_Database and Node_Table classes
47 * @param string $type The type of item we are looking for
48 * ('columns' or 'indexes')
49 * @param string $searchClause A string used to filter the results of the query
53 public function getPresence($type = '', $searchClause = '')
56 $db = $this->realParent()->real_name
;
57 $table = $this->real_name
;
60 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
61 $db = PMA_Util
::sqlAddSlashes($db);
62 $table = PMA_Util
::sqlAddSlashes($table);
63 $query = "SELECT COUNT(*) ";
64 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
65 $query .= "WHERE `TABLE_NAME`='$table' ";
66 $query .= "AND `TABLE_SCHEMA`='$db'";
67 $retval = (int)PMA_DBI_fetch_value($query);
69 $db = PMA_Util
::backquote($db);
70 $table = PMA_Util
::backquote($table);
71 $query = "SHOW COLUMNS FROM $table FROM $db";
72 $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
76 $db = PMA_Util
::backquote($db);
77 $table = PMA_Util
::backquote($table);
78 $query = "SHOW INDEXES FROM $table FROM $db";
79 $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
82 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
83 $db = PMA_Util
::sqlAddSlashes($db);
84 $table = PMA_Util
::sqlAddSlashes($table);
85 $query = "SELECT COUNT(*) ";
86 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
87 $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
88 $query .= "AND `EVENT_OBJECT_TABLE`='$table'";
89 $retval = (int)PMA_DBI_fetch_value($query);
91 $db = PMA_Util
::backquote($db);
92 $table = PMA_Util
::sqlAddSlashes($table);
93 $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
94 $retval = (int)PMA_DBI_num_rows(PMA_DBI_try_query($query));
104 * Returns the names of children of type $type present inside this container
105 * This method is overridden by the Node_Database and Node_Table classes
107 * @param string $type The type of item we are looking for
108 * ('tables', 'views', etc)
109 * @param int $pos The offset of the list within the results
110 * @param string $searchClause A string used to filter the results of the query
114 public function getData($type, $pos, $searchClause = '')
116 $maxItems = $GLOBALS['cfg']['MaxNavigationItems'];
118 $db = $this->realParent()->real_name
;
119 $table = $this->real_name
;
122 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
123 $db = PMA_Util
::sqlAddSlashes($db);
124 $table = PMA_Util
::sqlAddSlashes($table);
125 $query = "SELECT `COLUMN_NAME` AS `name` ";
126 $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` ";
127 $query .= "WHERE `TABLE_NAME`='$table' ";
128 $query .= "AND `TABLE_SCHEMA`='$db' ";
129 $query .= "ORDER BY `COLUMN_NAME` ASC ";
130 $query .= "LIMIT " . intval($pos) . ", $maxItems";
131 $retval = PMA_DBI_fetch_result($query);
133 $db = PMA_Util
::backquote($db);
134 $table = PMA_Util
::backquote($table);
135 $query = "SHOW COLUMNS FROM $table FROM $db";
136 $handle = PMA_DBI_try_query($query);
137 if ($handle !== false) {
139 while ($arr = PMA_DBI_fetch_array($handle)) {
140 if ($pos <= 0 && $count < $maxItems) {
141 $retval[] = $arr['Field'];
150 $db = PMA_Util
::backquote($db);
151 $table = PMA_Util
::backquote($table);
152 $query = "SHOW INDEXES FROM $table FROM $db";
153 $handle = PMA_DBI_try_query($query);
154 if ($handle !== false) {
156 while ($arr = PMA_DBI_fetch_array($handle)) {
157 if (! in_array($arr['Key_name'], $retval)) {
158 if ($pos <= 0 && $count < $maxItems) {
159 $retval[] = $arr['Key_name'];
168 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
169 $db = PMA_Util
::sqlAddSlashes($db);
170 $table = PMA_Util
::sqlAddSlashes($table);
171 $query = "SELECT `TRIGGER_NAME` AS `name` ";
172 $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
173 $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' ";
174 $query .= "AND `EVENT_OBJECT_TABLE`='$table' ";
175 $query .= "ORDER BY `TRIGGER_NAME` ASC ";
176 $query .= "LIMIT " . intval($pos) . ", $maxItems";
177 $retval = PMA_DBI_fetch_result($query);
179 $db = PMA_Util
::backquote($db);
180 $table = PMA_Util
::sqlAddSlashes($table);
181 $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'";
182 $handle = PMA_DBI_try_query($query);
183 if ($handle !== false) {
185 while ($arr = PMA_DBI_fetch_array($handle)) {
186 if ($pos <= 0 && $count < $maxItems) {
187 $retval[] = $arr['Trigger'];
202 * Returns the comment associated with node
203 * This method should be overridden by specific type of nodes
207 public function getComment()
209 $db = $this->realParent()->real_name
;
210 $table = PMA_Util
::sqlAddSlashes($this->real_name
);
211 if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) {
212 $db = PMA_Util
::sqlAddSlashes($db);
213 $query = "SELECT `TABLE_COMMENT` ";
214 $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` ";
215 $query .= "WHERE `TABLE_SCHEMA`='$db' ";
216 $query .= "AND `TABLE_NAME`='$table' ";
217 $retval = PMA_DBI_fetch_value($query);
219 $db = PMA_Util
::backquote($db);
220 $query = "SHOW TABLE STATUS FROM $db ";
221 $query .= "WHERE Name = '$table'";
222 $arr = PMA_DBI_fetch_assoc(PMA_DBI_try_query($query));
223 $retval = $arr['Comment'];