1
0
mirror of https://github.com/mbirth/tcl_update_db.git synced 2024-11-09 23:06:45 +00:00

Ignore duplicate entries in db.

This commit is contained in:
Markus Birth 2017-12-11 01:28:52 +01:00
parent 7deab3588b
commit c6cbd890e3
Signed by: mbirth
GPG Key ID: A9928D7A098C3A9A
3 changed files with 17 additions and 5 deletions

View File

@ -19,7 +19,7 @@ class SQLiteWriter
private function insertArray($table, $data)
{
$placeholders = array_fill(0, count($data), '?');
$sql = 'INSERT OR REPLACE INTO "' . $table . '" (' . implode(', ', array_keys($data)) . ') VALUES (' . implode(', ', $placeholders) . ')';
$sql = 'INSERT INTO "' . $table . '" (' . implode(', ', array_keys($data)) . ') VALUES (' . implode(', ', $placeholders) . ')';
$stmt = $this->pdo->prepare($sql);
$ok = $stmt->execute(array_values($data));
return $ok;
@ -27,7 +27,7 @@ class SQLiteWriter
public function addGotu(GotuObject $g)
{
$this->insertArray('updates', array(
$ok = $this->insertArray('updates', array(
'tv' => $g->tv,
'fv' => $g->fv,
'svn' => $g->svn,
@ -45,7 +45,11 @@ class SQLiteWriter
'zh' => $g->description_zh,
))
));
$key = $this->pdo->lastInsertId();
echo "Added entry " . $key . PHP_EOL;
if ($ok) {
$key = $this->pdo->lastInsertId();
echo "Added entry " . $key . PHP_EOL;
} else {
echo "FAILED inserting." . PHP_EOL;
}
}
}

View File

@ -28,5 +28,7 @@ foreach ($file_list as $file) {
echo 'Processing ' . $filename . PHP_EOL;
$g = GotuObject::fromXmlParser($xp);
print_r($g);
$sqlw->addGotu($g);
if ($g->tv) {
$sqlw->addGotu($g);
}
}

View File

@ -55,6 +55,12 @@ CREATE TABLE "updates" (
"type" TEXT, -- FULL or OTA
"note" TEXT -- some note for this file (optional)
);
CREATE UNIQUE INDEX "index_updates" ON "updates" (
"tv",
"fv",
"fwId",
"file_id"
);
-- Maps update files to devices
CREATE TABLE "update_map" (