1
0

Tables now showing.

This commit is contained in:
2017-12-16 19:42:24 +01:00
parent 1ea640b5f1
commit 1edabd5b74
3 changed files with 83 additions and 15 deletions

@ -20,7 +20,7 @@ class SQLiteReader
$this->pdo->exec('PRAGMA foreign_keys=on;');
}
public function getAllPrds()
public function getAllRefs()
{
$sql = 'SELECT DISTINCT curef FROM updates ORDER BY curef;';
$sqlresult = $this->pdo->query($sql);
@ -31,7 +31,7 @@ class SQLiteReader
return $result;
}
public function getAllKnownPrds()
public function getAllKnownRefs()
{
$sql = 'SELECT DISTINCT ref FROM devices ORDER BY ref;';
$sqlresult = $this->pdo->query($sql);
@ -42,10 +42,10 @@ class SQLiteReader
return $result;
}
public function getUnknownPrds()
public function getUnknownRefs()
{
$knownPrds = $this->getAllKnownPrds();
$allPrds = $this->getAllPrds();
$knownPrds = $this->getAllKnownRefs();
$allPrds = $this->getAllRefs();
$unknownPrds = array_diff($allPrds, $knownPrds);
return $unknownPrds;
}
@ -99,4 +99,47 @@ class SQLiteReader
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
return $result;
}
public function getAllVersionsForRef($ref = null)
{
$sql = 'SELECT fv, tv FROM updates u LEFT JOIN files f ON u.file_sha1=f.sha1';
$params_arr = array();
if (!is_null($ref)) {
$sql .= ' WHERE curef=?';
$params_arr[] = $ref;
}
$stmt = $this->pdo->prepare($sql);
$ok = $stmt->execute($params_arr);
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$version = array();
foreach ($result as $row) {
if (!is_null($row['fv'])) {
$version[] = $row['fv'];
}
$version[] = $row['tv'];
}
$version = array_unique($version);
sort($version);
return $version;
}
public function getAllVersionsForModel($model)
{
$sql = 'SELECT fv, tv FROM models m LEFT JOIN devices d ON m.modelId=d.modelId LEFT JOIN updates u ON d.ref=u.curef LEFT JOIN files f ON u.file_sha1=f.sha1 WHERE m.name=?';
$stmt = $this->pdo->prepare($sql);
$ok = $stmt->execute(array($model));
$result = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$version = array();
foreach ($result as $row) {
if (!is_null($row['fv'])) {
$version[] = $row['fv'];
}
if (!is_null($row['tv'])) {
$version[] = $row['tv'];
}
}
$version = array_unique($version);
sort($version);
return $version;
}
}