16f4ec3caSGreg Roach<?php 26f4ec3caSGreg Roach 36f4ec3caSGreg Roach/** 46f4ec3caSGreg Roach * webtrees: online genealogy 56f4ec3caSGreg Roach * Copyright (C) 2023 webtrees development team 66f4ec3caSGreg Roach * This program is free software: you can redistribute it and/or modify 76f4ec3caSGreg Roach * it under the terms of the GNU General Public License as published by 86f4ec3caSGreg Roach * the Free Software Foundation, either version 3 of the License, or 96f4ec3caSGreg Roach * (at your option) any later version. 106f4ec3caSGreg Roach * This program is distributed in the hope that it will be useful, 116f4ec3caSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 126f4ec3caSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 136f4ec3caSGreg Roach * GNU General Public License for more details. 146f4ec3caSGreg Roach * You should have received a copy of the GNU General Public License 156f4ec3caSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 166f4ec3caSGreg Roach */ 176f4ec3caSGreg Roach 186f4ec3caSGreg Roachdeclare(strict_types=1); 196f4ec3caSGreg Roach 206f4ec3caSGreg Roachnamespace Fisharebest\Webtrees; 216f4ec3caSGreg Roach 226f4ec3caSGreg Roachuse Illuminate\Database\Capsule\Manager; 23*6bd19c8cSGreg Roachuse Illuminate\Database\Query\Builder; 246f4ec3caSGreg Roach 256f4ec3caSGreg Roach/** 266f4ec3caSGreg Roach * Database abstraction 276f4ec3caSGreg Roach */ 286f4ec3caSGreg Roachclass DB extends Manager 296f4ec3caSGreg Roach{ 306f4ec3caSGreg Roach /** 316f4ec3caSGreg Roach * @internal 326f4ec3caSGreg Roach */ 336f4ec3caSGreg Roach public static function caseInsensitiveLikeOperator(): string 346f4ec3caSGreg Roach { 356f4ec3caSGreg Roach if (DB::connection()->getDriverName() === 'pgsql') { 366f4ec3caSGreg Roach return 'ILIKE'; 376f4ec3caSGreg Roach } 386f4ec3caSGreg Roach 396f4ec3caSGreg Roach if (DB::connection()->getDriverName() === 'sqlsrv') { 406f4ec3caSGreg Roach return 'COLLATE SQL_UTF8_General_CI_AI LIKE'; 416f4ec3caSGreg Roach } 426f4ec3caSGreg Roach 436f4ec3caSGreg Roach return 'LIKE'; 446f4ec3caSGreg Roach } 45859d33aaSGreg Roach 46859d33aaSGreg Roach /** 47859d33aaSGreg Roach * @internal 48859d33aaSGreg Roach */ 49859d33aaSGreg Roach public static function groupConcat(string $column): string 50859d33aaSGreg Roach { 51859d33aaSGreg Roach switch (DB::connection()->getDriverName()) { 52859d33aaSGreg Roach case 'pgsql': 53859d33aaSGreg Roach case 'sqlsrv': 54859d33aaSGreg Roach return 'STRING_AGG(' . $column . ", ',')"; 55859d33aaSGreg Roach 56859d33aaSGreg Roach case 'mysql': 57859d33aaSGreg Roach case 'sqlite': 58859d33aaSGreg Roach default: 59859d33aaSGreg Roach return 'GROUP_CONCAT(' . $column . ')'; 60859d33aaSGreg Roach } 61859d33aaSGreg Roach } 62*6bd19c8cSGreg Roach 63*6bd19c8cSGreg Roach /** 64*6bd19c8cSGreg Roach * PHPSTAN can't detect the magic methods in the parent class. 65*6bd19c8cSGreg Roach */ 66*6bd19c8cSGreg Roach public static function query(): Builder 67*6bd19c8cSGreg Roach { 68*6bd19c8cSGreg Roach return self::connection()->query(); 69*6bd19c8cSGreg Roach } 706f4ec3caSGreg Roach} 71