PMA\libraries\navigation\nodes\NodeTable::getData PHP Method

getData() public method

Returns the names of children of type $type present inside this container This method is overridden by the PMA\libraries\navigation\nodes\NodeDatabase and PMA\libraries\navigation\nodes\NodeTable classes
public getData ( string $type, integer $pos, string $searchClause = '' ) : array
$type string The type of item we are looking for ('tables', 'views', etc)
$pos integer The offset of the list within the results
$searchClause string 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']['Server']['DisableIS']) {
                    $db = $GLOBALS['dbi']->escapeString($db);
                    $table = $GLOBALS['dbi']->escapeString($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 = $GLOBALS['dbi']->fetchResult($query);
                    break;
                }
                $db = Util::backquote($db);
                $table = Util::backquote($table);
                $query = "SHOW COLUMNS FROM {$table} FROM {$db}";
                $handle = $GLOBALS['dbi']->tryQuery($query);
                if ($handle === false) {
                    break;
                }
                $count = 0;
                if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
                    while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                        if ($count < $maxItems) {
                            $retval[] = $arr['Field'];
                            $count++;
                        } else {
                            break;
                        }
                    }
                }
                break;
            case 'indexes':
                $db = Util::backquote($db);
                $table = Util::backquote($table);
                $query = "SHOW INDEXES FROM {$table} FROM {$db}";
                $handle = $GLOBALS['dbi']->tryQuery($query);
                if ($handle === false) {
                    break;
                }
                $count = 0;
                while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                    if (in_array($arr['Key_name'], $retval)) {
                        continue;
                    }
                    if ($pos <= 0 && $count < $maxItems) {
                        $retval[] = $arr['Key_name'];
                        $count++;
                    }
                    $pos--;
                }
                break;
            case 'triggers':
                if (!$GLOBALS['cfg']['Server']['DisableIS']) {
                    $db = $GLOBALS['dbi']->escapeString($db);
                    $table = $GLOBALS['dbi']->escapeString($table);
                    $query = "SELECT `TRIGGER_NAME` AS `name` ";
                    $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` ";
                    $query .= "WHERE `EVENT_OBJECT_SCHEMA` " . Util::getCollateForIS() . "='{$db}' ";
                    $query .= "AND `EVENT_OBJECT_TABLE` " . Util::getCollateForIS() . "='{$table}' ";
                    $query .= "ORDER BY `TRIGGER_NAME` ASC ";
                    $query .= "LIMIT " . intval($pos) . ", {$maxItems}";
                    $retval = $GLOBALS['dbi']->fetchResult($query);
                    break;
                }
                $db = Util::backquote($db);
                $table = $GLOBALS['dbi']->escapeString($table);
                $query = "SHOW TRIGGERS FROM {$db} WHERE `Table` = '{$table}'";
                $handle = $GLOBALS['dbi']->tryQuery($query);
                if ($handle === false) {
                    break;
                }
                $count = 0;
                if ($GLOBALS['dbi']->dataSeek($handle, $pos)) {
                    while ($arr = $GLOBALS['dbi']->fetchArray($handle)) {
                        if ($count < $maxItems) {
                            $retval[] = $arr['Trigger'];
                            $count++;
                        } else {
                            break;
                        }
                    }
                }
                break;
            default:
                break;
        }
        return $retval;
    }