fix CONCAT() for SQLite #24.

This commit is contained in:
Miroslav Šedivý 2021-06-13 12:45:52 +02:00
parent 86b3840278
commit 386707c104
2 changed files with 16 additions and 3 deletions

View file

@ -24,6 +24,17 @@ class DB
return Config::get_safe('db_connection', 'sqlite');
}
// CONCAT() does not exist in SQLite, using || instead
public final static function concat(){
$values = func_get_args();
if(DB::connection() === 'sqlite') {
return implode(" || ", $values);
} else {
return 'CONCAT('.implode(", ", $values).')';
}
}
// Initialise PDO object
private final function __construct(){
switch(DB::connection()) {

View file

@ -429,6 +429,8 @@ class Post
$datetime = "DATE_FORMAT(`posts`.`datetime`,'%d %b %Y %H:%i')";
}
$like_match = "LIKE ".DB::concat("'%'", "?", "'%'");
return DB::get_instance()->query("
SELECT
`id`, `text`, `feeling`, `persons`, `location`, `privacy`, `content_type`, `content`,
@ -439,9 +441,9 @@ class Post
($from ? "`posts`.`datetime` > ? AND " : "").
($to ? "`posts`.`datetime` < ? AND " : "").
($id ? "`id` = ? AND " : "").
($tag ? "`plain_text` LIKE CONCAT('%', ?, '%') AND " : "").
($loc ? "`location` LIKE CONCAT('%', ?, '%') AND " : "").
($person ? "`persons` LIKE CONCAT('%', ?, '%') AND " : "").
($tag ? "`plain_text` $like_match AND " : "").
($loc ? "`location` $like_match AND " : "").
($person ? "`persons` $like_match AND " : "").
"`status` <> 5
ORDER BY `posts`.`datetime` DESC
LIMIT ? OFFSET ?