@@ -340,7 +340,7 @@ abstract class BaseConnection implements ConnectionInterface
340340 /**
341341 * Array of table aliases.
342342 *
343- * @var array
343+ * @var list<string>
344344 */
345345 protected $ aliasedTables = [];
346346
@@ -576,10 +576,14 @@ public function setAliasedTables(array $aliases)
576576 *
577577 * @return $this
578578 */
579- public function addTableAlias (string $ table )
579+ public function addTableAlias (string $ alias )
580580 {
581- if (! in_array ($ table , $ this ->aliasedTables , true )) {
582- $ this ->aliasedTables [] = $ table ;
581+ if ($ alias === '' ) {
582+ return $ this ;
583+ }
584+
585+ if (! in_array ($ alias , $ this ->aliasedTables , true )) {
586+ $ this ->aliasedTables [] = $ alias ;
583587 }
584588
585589 return $ this ;
@@ -925,7 +929,7 @@ abstract protected function _transRollback(): bool;
925929 /**
926930 * Returns a non-shared new instance of the query builder for this connection.
927931 *
928- * @param array|string $tableName
932+ * @param array|string|TableName $tableName
929933 *
930934 * @return BaseBuilder
931935 *
@@ -1054,10 +1058,10 @@ public function getConnectDuration(int $decimals = 6): string
10541058 * insert the table prefix (if it exists) in the proper position, and escape only
10551059 * the correct identifiers.
10561060 *
1057- * @param array|int|string $item
1058- * @param bool $prefixSingle Prefix a table name with no segments?
1059- * @param bool $protectIdentifiers Protect table or column names?
1060- * @param bool $fieldExists Supplied $item contains a column name?
1061+ * @param array|int|string|TableName $item
1062+ * @param bool $prefixSingle Prefix a table name with no segments?
1063+ * @param bool $protectIdentifiers Protect table or column names?
1064+ * @param bool $fieldExists Supplied $item contains a column name?
10611065 *
10621066 * @return array|string
10631067 * @phpstan-return ($item is array ? array : string)
@@ -1078,6 +1082,11 @@ public function protectIdentifiers($item, bool $prefixSingle = false, ?bool $pro
10781082 return $ escapedArray ;
10791083 }
10801084
1085+ if ($ item instanceof TableName) {
1086+ /** @psalm-suppress NoValue I don't know why ERROR. */
1087+ return $ this ->escapeTableName ($ item );
1088+ }
1089+
10811090 // If you pass `['column1', 'column2']`, `$item` will be int because the array keys are int.
10821091 $ item = (string ) $ item ;
10831092
@@ -1220,10 +1229,18 @@ private function protectDotItem(string $item, string $alias, bool $protectIdenti
12201229 *
12211230 * This function escapes single identifier.
12221231 *
1223- * @param non-empty-string $item
1232+ * @param non-empty-string|TableName $item
12241233 */
1225- public function escapeIdentifier (string $ item ): string
1234+ public function escapeIdentifier ($ item ): string
12261235 {
1236+ if ($ item === '' ) {
1237+ return '' ;
1238+ }
1239+
1240+ if ($ item instanceof TableName) {
1241+ return $ this ->escapeTableName ($ item );
1242+ }
1243+
12271244 return $ this ->escapeChar
12281245 . str_replace (
12291246 $ this ->escapeChar ,
@@ -1233,6 +1250,17 @@ public function escapeIdentifier(string $item): string
12331250 . $ this ->escapeChar ;
12341251 }
12351252
1253+ /**
1254+ * Returns escaped table name with alias.
1255+ */
1256+ private function escapeTableName (TableName $ tableName ): string
1257+ {
1258+ $ alias = $ tableName ->getAlias ();
1259+
1260+ return $ this ->escapeIdentifier ($ tableName ->getActualTableName ())
1261+ . (($ alias !== '' ) ? ' ' . $ this ->escapeIdentifier ($ alias ) : '' );
1262+ }
1263+
12361264 /**
12371265 * Escape the SQL Identifiers
12381266 *
@@ -1546,12 +1574,16 @@ public function tableExists(string $tableName, bool $cached = true): bool
15461574 /**
15471575 * Fetch Field Names
15481576 *
1577+ * @param string|TableName $tableName
1578+ *
15491579 * @return false|list<string>
15501580 *
15511581 * @throws DatabaseException
15521582 */
1553- public function getFieldNames (string $ table )
1583+ public function getFieldNames ($ tableName )
15541584 {
1585+ $ table = ($ tableName instanceof TableName) ? $ tableName ->getTableName () : $ tableName ;
1586+
15551587 // Is there a cached result?
15561588 if (isset ($ this ->dataCache ['field_names ' ][$ table ])) {
15571589 return $ this ->dataCache ['field_names ' ][$ table ];
@@ -1561,7 +1593,7 @@ public function getFieldNames(string $table)
15611593 $ this ->initialize ();
15621594 }
15631595
1564- if (false === ($ sql = $ this ->_listColumns ($ table ))) {
1596+ if (false === ($ sql = $ this ->_listColumns ($ tableName ))) {
15651597 if ($ this ->DBDebug ) {
15661598 throw new DatabaseException ('This feature is not available for the database you are using. ' );
15671599 }
@@ -1777,9 +1809,11 @@ abstract protected function _listTables(bool $constrainByPrefix = false, ?string
17771809 /**
17781810 * Generates a platform-specific query string so that the column names can be fetched.
17791811 *
1812+ * @param string|TableName $table
1813+ *
17801814 * @return false|string
17811815 */
1782- abstract protected function _listColumns (string $ table = '' );
1816+ abstract protected function _listColumns ($ table = '' );
17831817
17841818 /**
17851819 * Platform-specific field data information.
0 commit comments