PMA\libraries\plugins\export\ExportSql::_getTableDefForView PHP Method

_getTableDefForView() private method

Returns CREATE definition that matches $view's structure
private _getTableDefForView ( string $db, string $view, string $crlf, boolean $add_semicolon = true, array $aliases = [] ) : string
$db string the database name
$view string the view name
$crlf string the end of line sequence
$add_semicolon boolean whether to add semicolon and end-of-line at the end
$aliases array Aliases of db/table/columns
return string resulting schema
    private function _getTableDefForView($db, $view, $crlf, $add_semicolon = true, $aliases = array())
    {
        $db_alias = $db;
        $view_alias = $view;
        $this->initAlias($aliases, $db_alias, $view_alias);
        $create_query = "CREATE TABLE";
        if (isset($GLOBALS['sql_if_not_exists'])) {
            $create_query .= " IF NOT EXISTS ";
        }
        $create_query .= Util::backquote($view_alias) . "(" . $crlf;
        $columns = $GLOBALS['dbi']->getColumns($db, $view, null, true);
        $firstCol = true;
        foreach ($columns as $column) {
            $col_alias = $column['Field'];
            if (!empty($aliases[$db]['tables'][$view]['columns'][$col_alias])) {
                $col_alias = $aliases[$db]['tables'][$view]['columns'][$col_alias];
            }
            $extracted_columnspec = Util::extractColumnSpec($column['Type']);
            if (!$firstCol) {
                $create_query .= "," . $crlf;
            }
            $create_query .= "    " . Util::backquote($col_alias);
            $create_query .= " " . $column['Type'];
            if ($extracted_columnspec['can_contain_collation'] && !empty($column['Collation'])) {
                $create_query .= " COLLATE " . $column['Collation'];
            }
            if ($column['Null'] == 'NO') {
                $create_query .= " NOT NULL";
            }
            if (isset($column['Default'])) {
                $create_query .= " DEFAULT '" . $GLOBALS['dbi']->escapeString($column['Default']) . "'";
            } else {
                if ($column['Null'] == 'YES') {
                    $create_query .= " DEFAULT NULL";
                }
            }
            if (!empty($column['Comment'])) {
                $create_query .= " COMMENT '" . $GLOBALS['dbi']->escapeString($column['Comment']) . "'";
            }
            $firstCol = false;
        }
        $create_query .= $crlf . ")" . ($add_semicolon ? ';' : '') . $crlf;
        if (isset($GLOBALS['sql_compatibility'])) {
            $compat = $GLOBALS['sql_compatibility'];
        } else {
            $compat = 'NONE';
        }
        if ($compat == 'MSSQL') {
            $create_query = $this->_makeCreateTableMSSQLCompatible($create_query);
        }
        return $create_query;
    }