From 0332a57bfdef29179b7962a7e06eba6f89e85a9e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 21 Jun 2022 18:11:59 +0200 Subject: [PATCH] Rewrote to suggestions from @MrPetovan (I tried to maintain the old way of ['scheme' => 'table'] with my version). --- src/Database/DBA.php | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/Database/DBA.php b/src/Database/DBA.php index d428f36f5a..3cd14766b4 100644 --- a/src/Database/DBA.php +++ b/src/Database/DBA.php @@ -526,32 +526,25 @@ class DBA */ public static function buildTableString(array $tables): string { - $quotedTables = []; - - foreach ($tables as $schema => $table) { - if (is_numeric($schema)) { - $str = ''; - foreach (explode('.', $table) as $part) { - $str .= self::quoteIdentifier($part) . '.'; - } - $quotedTables[] = rtrim($str, '.'); - } else { - $quotedTables[] = self::quoteIdentifier($schema) . '.' . self::quoteIdentifier($table); - } - } - - return implode(', ', $quotedTables); + // Quote each entry + return implode(',', array_map(['self', 'quoteIdentifier'], $tables)); } /** - * Escape an identifier (table or field name) + * Escape an identifier (table or field name) optional with a schema like (schema.)table * - * @param $identifier - * @return string + * @param $identifier Table, field name + * @return string Quotes table or field name */ public static function quoteIdentifier(string $identifier): string { - return '`' . str_replace('`', '``', $identifier) . '`'; + return implode( + '.', + array_map( + function (string $identifier) { return '`' . str_replace('`', '``', $identifier) . '`'; }, + explode('.', $identifier) + ) + ); } /** -- 2.39.5