showCreate() 공개 메소드

Returns the CREATE statement for this table
public showCreate ( ) : mixed
리턴 mixed
예제 #1
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;
}