@@ -578,6 +578,10 @@ public function setAliasedTables(array $aliases)
578578 */
579579 public function addTableAlias (string $ alias )
580580 {
581+ if ($ alias === '' ) {
582+ return $ this ;
583+ }
584+
581585 if (! in_array ($ alias , $ this ->aliasedTables , true )) {
582586 $ this ->aliasedTables [] = $ alias ;
583587 }
@@ -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,14 +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 {
12271236 if ($ item === '' ) {
12281237 return '' ;
12291238 }
12301239
1240+ if ($ item instanceof TableName) {
1241+ return $ this ->escapeTableName ($ item );
1242+ }
1243+
12311244 return $ this ->escapeChar
12321245 . str_replace (
12331246 $ this ->escapeChar ,
@@ -1237,6 +1250,17 @@ public function escapeIdentifier(string $item): string
12371250 . $ this ->escapeChar ;
12381251 }
12391252
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+
12401264 /**
12411265 * Escape the SQL Identifiers
12421266 *
@@ -1550,12 +1574,16 @@ public function tableExists(string $tableName, bool $cached = true): bool
15501574 /**
15511575 * Fetch Field Names
15521576 *
1577+ * @param string|TableName $tableName
1578+ *
15531579 * @return false|list<string>
15541580 *
15551581 * @throws DatabaseException
15561582 */
1557- public function getFieldNames (string $ table )
1583+ public function getFieldNames ($ tableName )
15581584 {
1585+ $ table = ($ tableName instanceof TableName) ? $ tableName ->getTableName () : $ tableName ;
1586+
15591587 // Is there a cached result?
15601588 if (isset ($ this ->dataCache ['field_names ' ][$ table ])) {
15611589 return $ this ->dataCache ['field_names ' ][$ table ];
@@ -1565,7 +1593,7 @@ public function getFieldNames(string $table)
15651593 $ this ->initialize ();
15661594 }
15671595
1568- if (false === ($ sql = $ this ->_listColumns ($ table ))) {
1596+ if (false === ($ sql = $ this ->_listColumns ($ tableName ))) {
15691597 if ($ this ->DBDebug ) {
15701598 throw new DatabaseException ('This feature is not available for the database you are using. ' );
15711599 }
@@ -1781,9 +1809,11 @@ abstract protected function _listTables(bool $constrainByPrefix = false, ?string
17811809 /**
17821810 * Generates a platform-specific query string so that the column names can be fetched.
17831811 *
1812+ * @param string|TableName $table
1813+ *
17841814 * @return false|string
17851815 */
1786- abstract protected function _listColumns (string $ table = '' );
1816+ abstract protected function _listColumns ($ table = '' );
17871817
17881818 /**
17891819 * Platform-specific field data information.
0 commit comments