コード例 #1
0
 /**
  * Returns the generation expression for virtual columns
  *
  * @param string $column name of the column
  *
  * @return array|boolean associative array of column name and their expressions
  *                       or false on failure
  */
 public function getColumnGenerationExpression($column = null)
 {
     $serverType = PMA_Util::getServerType();
     if ($serverType == 'MySQL' && PMA_MYSQL_INT_VERSION > 50705 && !$GLOBALS['cfg']['Server']['DisableIS']) {
         $sql = "SELECT\r\n                `COLUMN_NAME` AS `Field`,\r\n                `GENERATION_EXPRESSION` AS `Expression`\r\n                FROM\r\n                `information_schema`.`COLUMNS`\r\n                WHERE\r\n                `TABLE_SCHEMA` = '" . PMA_Util::sqlAddSlashes($this->_db_name) . "'\r\n                AND `TABLE_NAME` = '" . PMA_Util::sqlAddSlashes($this->_name) . "'";
         if ($column != null) {
             $sql .= " AND  `COLUMN_NAME` = '" . PMA_Util::sqlAddSlashes($column) . "'";
         }
         $columns = $this->_dbi->fetchResult($sql, 'Field', 'Expression');
         return $columns;
     }
     $createTable = $this->showCreate();
     if (!$createTable) {
         return false;
     }
     $parser = new SqlParser\Parser($createTable);
     /**
      * @var SqlParser\Statements\CreateStatement $stmt
      */
     $stmt = $parser->statements[0];
     $fields = SqlParser\Utils\Table::getFields($stmt);
     if ($column != null) {
         $expression = isset($fields[$column]['expr']) ? substr($fields[$column]['expr'], 1, -1) : '';
         return array($column => $expression);
     }
     $ret = array();
     foreach ($fields as $field => $options) {
         if (isset($options['expr'])) {
             $ret[$field] = substr($options['expr'], 1, -1);
         }
     }
     return $ret;
 }
コード例 #2
0
/**
 * Gets all Relations to foreign tables for a given table or
 * optionally a given column in a table
 *
 * @param string $db     the name of the db to check for
 * @param string $table  the name of the table to check for
 * @param string $column the name of the column to check for
 * @param string $source the source for foreign key information
 *
 * @return array    db,table,column
 *
 * @access  public
 */
function PMA_getForeigners($db, $table, $column = '', $source = 'both')
{
    $cfgRelation = PMA_getRelationsParam();
    $foreign = array();
    if ($cfgRelation['relwork'] && ($source == 'both' || $source == 'internal')) {
        $rel_query = '
            SELECT `master_field`,
                `foreign_db`,
                `foreign_table`,
                `foreign_field`
            FROM ' . PMA\libraries\Util::backquote($cfgRelation['db']) . '.' . PMA\libraries\Util::backquote($cfgRelation['relation']) . '
            WHERE `master_db`    = \'' . PMA\libraries\Util::sqlAddSlashes($db) . '\'
                AND `master_table` = \'' . PMA\libraries\Util::sqlAddSlashes($table) . '\' ';
        if (mb_strlen($column)) {
            $rel_query .= ' AND `master_field` = ' . '\'' . PMA\libraries\Util::sqlAddSlashes($column) . '\'';
        }
        $foreign = $GLOBALS['dbi']->fetchResult($rel_query, 'master_field', null, $GLOBALS['controllink']);
    }
    if (($source == 'both' || $source == 'foreign') && mb_strlen($table)) {
        $tableObj = new Table($table, $db);
        $show_create_table = $tableObj->showCreate();
        if ($show_create_table) {
            $parser = new SqlParser\Parser($show_create_table);
            /**
             * @var CreateStatement $stmt
             */
            $stmt = $parser->statements[0];
            $foreign['foreign_keys_data'] = SqlParser\Utils\Table::getForeignKeys($stmt);
        }
    }
    /**
     * Emulating relations for some information_schema tables
     */
    $isInformationSchema = mb_strtolower($db) == 'information_schema';
    $isMysql = mb_strtolower($db) == 'mysql';
    if (($isInformationSchema || $isMysql) && ($source == 'internal' || $source == 'both')) {
        if ($isInformationSchema) {
            $relations_key = 'information_schema_relations';
            include_once './libraries/information_schema_relations.lib.php';
        } else {
            $relations_key = 'mysql_relations';
            include_once './libraries/mysql_relations.lib.php';
        }
        if (isset($GLOBALS[$relations_key][$table])) {
            foreach ($GLOBALS[$relations_key][$table] as $field => $relations) {
                if ((!mb_strlen($column) || $column == $field) && (!isset($foreign[$field]) || !mb_strlen($foreign[$field]))) {
                    $foreign[$field] = $relations;
                }
            }
        }
    }
    return $foreign;
}
コード例 #3
0
ファイル: tbl_structure.php プロジェクト: Timandes/phpmyadmin
$primary = PMA_Index::getPrimary($table, $db);
$columns_with_index = PMA_getColumnsWithIndex($db, $table, PMA_Index::UNIQUE | PMA_Index::INDEX | PMA_Index::SPATIAL | PMA_Index::FULLTEXT);
$columns_with_unique_index = PMA_getColumnsWithIndex($db, $table, PMA_Index::UNIQUE);
// 3. Get fields
$fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true);
// Get more complete field information
// For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options
// but later, if the analyser returns more information, it
// could be executed for any MySQL version and replace
// the info given by SHOW FULL COLUMNS FROM.
//
// We also need this to correctly learn if a TIMESTAMP is NOT NULL, since
// SHOW FULL COLUMNS or INFORMATION_SCHEMA incorrectly says NULL
// and SHOW CREATE TABLE says NOT NULL (tested
// in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910).
$tableObj = new PMA_Table($table, $db);
$show_create_table = $tableObj->showCreate();
$parser = new SqlParser\Parser($show_create_table);
/**
 * @var CreateStatement $stmt
 */
$stmt = $parser->statements[0];
$create_table_fields = SqlParser\Utils\Table::getFields($stmt);
/**
 * prepare table infos
 */
// action titles (image or string)
$titles = PMA_getActionTitlesArray();
//display table structure
require_once 'libraries/display_structure.inc.php';
$response->addHTML('</div>');