mirror of
https://github.com/friendica/friendica
synced 2024-11-10 11:42:54 +00:00
Rewrote to suggestions from @MrPetovan (I tried to maintain the old way of
['scheme' => 'table'] with my version).
This commit is contained in:
parent
3b8d9a7248
commit
0332a57bfd
1 changed files with 12 additions and 19 deletions
|
@ -526,32 +526,25 @@ class DBA
|
||||||
*/
|
*/
|
||||||
public static function buildTableString(array $tables): string
|
public static function buildTableString(array $tables): string
|
||||||
{
|
{
|
||||||
$quotedTables = [];
|
// Quote each entry
|
||||||
|
return implode(',', array_map(['self', 'quoteIdentifier'], $tables));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Escape an identifier (table or field name)
|
* Escape an identifier (table or field name) optional with a schema like (schema.)table
|
||||||
*
|
*
|
||||||
* @param $identifier
|
* @param $identifier Table, field name
|
||||||
* @return string
|
* @return string Quotes table or field name
|
||||||
*/
|
*/
|
||||||
public static function quoteIdentifier(string $identifier): string
|
public static function quoteIdentifier(string $identifier): string
|
||||||
{
|
{
|
||||||
return '`' . str_replace('`', '``', $identifier) . '`';
|
return implode(
|
||||||
|
'.',
|
||||||
|
array_map(
|
||||||
|
function (string $identifier) { return '`' . str_replace('`', '``', $identifier) . '`'; },
|
||||||
|
explode('.', $identifier)
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue