SQlite concat select statement
A hack in PHP when using Laravel. It adds the concat()
functionality by having SQLite call back to PHP. For example you add it to your PhpUnit script.
The second line gets the \PDO
handle, if you don't use Laravel, replace it with your way of getting the handle.
/** @var \Illuminate\Database\Connection $connection */
$connection = DB::connection();
$dbHandle = $connection->getPdo();
// Add MySQL concat() support to SQLite
if ('sqlite' === $dbHandle->getAttribute(\PDO::ATTR_DRIVER_NAME)) {
$dbHandle->sqliteCreateFunction(
'concat',
function (...$input) {
return implode('', $input);
}
);
}
Other SQLite libraries in PHP have a similar sqliteCreateFunction()
.
- https://www.php.net/manual/en/function.sqlite-create-function.php
- https://www.php.net/manual/en/pdo.sqlitecreatefunction.php
- https://www.php.net/manual/en/sqlite3.createfunction.php
Concat also the space:
SELECT NAME || ' ' || SURNAME AS USER_NAME FROM USERS