Generates a unique, short SQL table alias.

@param string $tableName Table name
@param string $dqlAlias  The DQL alias.

@return string Generated table alias.
342271
public function getSQLTableAlias($tableName, $dqlAlias = '')
    {
        $tableName .= ($dqlAlias) ? '@[' . $dqlAlias . ']' : '';

        if ( ! isset($this->tableAliasMap[$tableName])) {
            $this->tableAliasMap[$tableName] = (preg_match('/[a-z]/i', $tableName[0]) ? strtolower($tableName[0]) : 't')
                . $this->tableAliasCounter++ . '_';
        }

        return $this->tableAliasMap[$tableName];
    }
579966
public function getTableCreateSql($tableName)
    {
        $sql = sprintf('SHOW CREATE TABLE %s', $this->ident($tableName));
        $result = $this->pdo->query($sql)->fetch();

        return $result['CREATE TABLE'];
    }
672445
private function buildTableName(): string
    {
        $table = '{db_prefix}' . $this->table;
        
        $no_alias_methods = [
            'REPLACE',
            'INSERT'
        ];
        
        if (in_array($this->method, $no_alias_methods)) {
            return $table;
        }
        
        if (! empty($this->alias)) {
            $table .= ' AS ' . $this->alias;
        }
        
        return $table;
    }
702607
protected function getTableSelects($tableName,$tableAlias = null)
  {
    $key = $tableName . '.' . $tableAlias;
    
    if (!isset($this->tableSelects[$key])) 
    {
      $this->loadTable($tableName,$tableAlias);
    }
    return $this->tableSelects[$key];
  }
648529
public function table($table, $alias = null)
    {
        if ($alias) {
            $table = [$alias => $table];
        } elseif (!is_array($table)) {
            $table = [$table];
        }

        $this->joins = [];
        foreach ($table as $alias => $name) {
            if ($name instanceof QueryInterface) {
                $expression = '(' . $name->getQuery() . ')';
            } else {
                $expression = $this->connection->quoteIdentifier($name);
            }
            if (is_string($alias)) {
                $this->tables[$alias] = $expression . ' ' . $alias;
            } else {
                $this->tables[$name] = $expression;
            }
        }

        return $this;
    }
780959
public function getPrimaryKey($tableAlias = '')
    {
        $output = '';

        if (!empty($tableAlias)) {
            $output .= '`' . $tableAlias . '`.';
        }

        $output .= '`'.static::ID_COLUMN.'`';

        return $output;
    }
311448
public function from($tableName, $alias = null)
    {
        $rel = $this->currentOrClone();
        
        if ($alias) {
            $rel->select->from([$alias => $tableName]);
        } else {
            $rel->select->from($tableName);
        }
        return $rel;
    }
562305
protected function generateUniqueAlias(File $phpcsFile, string $shortName, string $fullName): ?string
    {
        $alias = $shortName;
        $count = 0;
        $pieces = explode('\\', $fullName);
        if ($this->isSameVendor($phpcsFile, $fullName)) {
            $pieces = array_reverse($pieces);
            array_shift($pieces);
        }

        // To avoid collisions with PHP core classes we try to add this prefix for all root namespaced classes
        if (count($pieces) < 1) {
            array_unshift($pieces, 'Php');
        }

        while (isset($this->allStatements[$alias]) || $this->className && $alias === $this->className) {
            $alias = $shortName;

            if (count($pieces) - 1 < $count) {
                return null;
            }

            $prefix = '';
            for ($i = 0; $i <= $count; ++$i) {
                $prefix .= $pieces[$i];
            }

            $alias = $prefix . $alias;

            $count++;
        }

        return $alias;
    }
274206
public function transform(QueryBuilder $qb, $dqlAlias)
    {
        $field = ArgumentToOperandConverter::toField($this->field);
        $value = ArgumentToOperandConverter::toValue($this->value);

        $field = $field->transform($qb, $dqlAlias);
        $value = $value->transform($qb, $dqlAlias);

        return sprintf('(%s %s %s)', $field, $this->operation, $value);
    }
753819
public function from($table, ...$tables)
    {
        array_unshift($tables, $table);

        foreach ($tables as $table) {
            list($tableAlias, $tableName) = $this->dialect()->parseTable($table);

            if ($tableName instanceof SelectQuery) {
                if (!$tableAlias) {
                    throw new SqlException('FROM derived table should have an alias name.');
                }

                $tableKey = $tableAlias;
            } else {
                $tableKey = $tableAlias ?: $tableName;

                $tableName = $this->dialect()->quoteTable($tableName);
            }

            if ($tableAlias) {
                $tableAlias = $this->dialect()->quoteName($tableAlias);
            }

            $this->addFrom($tableKey, $tableName, $tableAlias);
        }

        return $this;
    }
1346037
protected function createAliasedName($value, $dqlAlias)
    {
        if (strpos($value, '.') !== false) {
            return $value;
        }

        if (! empty($this->dqlAlias)) {
            $dqlAlias = $this->dqlAlias;
        }

        return sprintf('%s.%s', $dqlAlias, $value);
    }
977552
public function generateTableName($tableName)
    {
        if (!$this->useTablePrefix) {
            return $tableName;
        }

        $db = $this->getDbConnection();
        if (preg_match("/^{$db->tablePrefix}(.*?)$/", $tableName, $matches)) {
            $tableName = '{{%' . $matches[1] . '}}';
        } elseif (preg_match("/^(.*?){$db->tablePrefix}$/", $tableName, $matches)) {
            $tableName = '{{' . $matches[1] . '%}}';
        }
        return $tableName;
    }
138315
protected function generateClassName($tableName, $short = false)
    {
        $ns = null;
        if (list($prefix, $ns) = $this->tablePrefixMatches($tableName)) {
            $tableName = substr($tableName, strlen($prefix));
        }
        $className = parent::generateClassName($tableName);

        if (null !== $ns && $short === false) {
            $className = '\\' . trim($this->ns . '\\' . $ns, '\\') . '\\' . $className;
        }
        return $className;
    }
1307047
public function transform(QueryBuilder $qb, $dqlAlias)
    {
        if ($this->expression instanceof Filter) {
            $expression = $this->expression->getFilter($qb, $dqlAlias);
        } else {
            $expression = ArgumentToOperandConverter::toField($this->expression);
            $expression = $expression->transform($qb, $dqlAlias);
        }

        return sprintf($this->getAliasFormat(), $expression, $this->alias);
    }
1235003
function newAlias(tableName) {
    // base of alias is first char of table name
    var alias = tableName.charAt(0)
    // get all upper case characters from table name
    var ucChars = tableName.match(/[A-Z]/g)
    // if table name has upper case chars then convert to lower and add
    if (ucChars) {
        alias = alias+ucChars.join('').toLowerCase()
    }
    var i = 0
    // get alias with digit appended
    while (i < 99) {
        var uniqueAlias = alias + i
        // if alias not in use then use it
        if (!this.aliases[uniqueAlias]) {
            // add alias to map of aliases
            this.aliases[uniqueAlias] = tableName
            // first table use is the one used for selecting values
            if (!this.tableAliases[tableName]) {
                this.tableAliases[tableName] = uniqueAlias
            }
            // return alias
            return uniqueAlias
        }
        // try next number
        i++
    }
    // if placeholder could not be found throw error
    throw new Error('max alias exceeded '+tableName)
}
1018134
private TableAlias createTableAlias(String aTable, String aPath, String aUserAlias)
    {
		if (aUserAlias == null)
		{
			return createTableAlias(aTable, aPath);
		}
		else
		{
			return createTableAlias(aTable, aUserAlias + ALIAS_SEPARATOR + aPath);
		}
    }
983203
public function table($table, $alias = null)
    {
        $database = null;

        // Check if the table is an object, this means
        // we have an subselect inside the table
        if (is_object($table) && ($table instanceof \Closure)) 
        {
            // we have to check if an alias isset 
            // otherwise throw an exception to prevent the 
            // "Every derived table must have its own alias" error
            if (is_null($alias))
            {
                throw new Exception('You must define an alias when working with subselects.');
            }

            $table = array($alias => $table);
        } 

        // Check if the $table is an array and the value is an closure
        // that we can pass a new query object as subquery 
        if (is_array($table) && is_object(reset($table)) && (reset($table) instanceof \Closure)) 
        {
            $alias = key($table);
            $table = reset($table);

            // create new query object
            $subquery = new Select;

            // run the closure callback on the sub query
            call_user_func_array($table, array(&$subquery));

            // set the table 
            // IMPORTANT: Only if we have a closure as table
            // we set the alias as key. This might cause some confusion
            // but only this way we can keep the normal ['table' => 'alias'] syntax
            $table = array($alias => $subquery);
        } 

        // other wise normally try to split the table and database name
        elseif (is_string($table) && strpos($table, '.') !== false)
        {
            $selection = explode('.', $table);

            if (count($selection) !== 2)
            {
                throw new Exception( 'Invalid argument given. You can only define one seperator.' );
            }

            list($database, $table) = $selection;
        }

        // the table might include an alias we need to parse that one out 
        if (is_string($table) && strpos($table, ' as ') !== false)
        {
            $tableParts = explode(' as ', $table);
            $table = array($tableParts[0] => $tableParts[1]);
        }

        // assing the result
        $this->database = $database;
        $this->table = $table;

        // return self
        return $this;
    }