summaryrefslogtreecommitdiff
path: root/app/Models
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2023-04-30 23:10:56 +0200
committerGravatar GitHub <noreply@github.com> 2023-04-30 23:10:56 +0200
commitffacdaa57a4725d9aad15c621eda7179e18dcaa4 (patch)
treeb98b66a002e76d46fafb98d40d0724d05e1a06d8 /app/Models
parent9af1c1ca1b58b8ed1e04b325e4ddccf96b104b05 (diff)
Fix TagDAO for SQLite (#5362)
The list of tags was empty when using SQLite. I have just realised that SQLite PDO driver returns int columns as string (at least in my test with PHP 7.4.33) so there was a type bug. We might have other bugs of this type for SQLite...
Diffstat (limited to 'app/Models')
-rw-r--r--app/Models/TagDAO.php9
1 files changed, 6 insertions, 3 deletions
diff --git a/app/Models/TagDAO.php b/app/Models/TagDAO.php
index de480f0ff..a675c7e04 100644
--- a/app/Models/TagDAO.php
+++ b/app/Models/TagDAO.php
@@ -212,11 +212,13 @@ SQL;
public function searchById(int $id): ?FreshRSS_Tag {
$res = $this->fetchAssoc('SELECT * FROM `_tag` WHERE id=:id', [':id' => $id]);
+ /** @var array<array{'id':int,'name':string,'attributes'?:string}>|null $res */
return $res === null ? null : self::daoToTag($res)[0] ?? null;
}
public function searchByName(string $name): ?FreshRSS_Tag {
$res = $this->fetchAssoc('SELECT * FROM `_tag` WHERE name=:name', [':name' => $name]);
+ /** @var array<array{'id':int,'name':string,'attributes'?:string}>|null $res */
return $res === null ? null : self::daoToTag($res)[0] ?? null;
}
@@ -237,7 +239,8 @@ SQL;
$stm = $this->pdo->query($sql);
if ($stm !== false) {
- return self::daoToTag($stm->fetchAll(PDO::FETCH_ASSOC));
+ $res = $stm->fetchAll(PDO::FETCH_ASSOC) ?: [];
+ return self::daoToTag($res);
} else {
$info = $this->pdo->errorInfo();
if ($this->autoUpdateDb($info)) {
@@ -440,13 +443,13 @@ SQL;
}
/**
- * @param iterable<array<string,int|string|null>> $listDAO
+ * @param iterable<array{'id':int,'name':string,'attributes'?:string}> $listDAO
* @return array<FreshRSS_Tag>
*/
private static function daoToTag(iterable $listDAO): array {
$list = [];
foreach ($listDAO as $dao) {
- if (empty($dao['id']) || !is_int($dao['id']) || empty($dao['name']) || !is_string($dao['name'])) {
+ if (empty($dao['id']) || empty($dao['name'])) {
continue;
}
$tag = new FreshRSS_Tag($dao['name']);