mirror of
https://github.com/mbirth/tcl_update_db.git
synced 2024-12-26 12:34:07 +00:00
Ignore duplicate entries in db.
This commit is contained in:
parent
7deab3588b
commit
c6cbd890e3
@ -19,7 +19,7 @@ class SQLiteWriter
|
|||||||
private function insertArray($table, $data)
|
private function insertArray($table, $data)
|
||||||
{
|
{
|
||||||
$placeholders = array_fill(0, count($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);
|
$stmt = $this->pdo->prepare($sql);
|
||||||
$ok = $stmt->execute(array_values($data));
|
$ok = $stmt->execute(array_values($data));
|
||||||
return $ok;
|
return $ok;
|
||||||
@ -27,7 +27,7 @@ class SQLiteWriter
|
|||||||
|
|
||||||
public function addGotu(GotuObject $g)
|
public function addGotu(GotuObject $g)
|
||||||
{
|
{
|
||||||
$this->insertArray('updates', array(
|
$ok = $this->insertArray('updates', array(
|
||||||
'tv' => $g->tv,
|
'tv' => $g->tv,
|
||||||
'fv' => $g->fv,
|
'fv' => $g->fv,
|
||||||
'svn' => $g->svn,
|
'svn' => $g->svn,
|
||||||
@ -45,7 +45,11 @@ class SQLiteWriter
|
|||||||
'zh' => $g->description_zh,
|
'zh' => $g->description_zh,
|
||||||
))
|
))
|
||||||
));
|
));
|
||||||
$key = $this->pdo->lastInsertId();
|
if ($ok) {
|
||||||
echo "Added entry " . $key . PHP_EOL;
|
$key = $this->pdo->lastInsertId();
|
||||||
|
echo "Added entry " . $key . PHP_EOL;
|
||||||
|
} else {
|
||||||
|
echo "FAILED inserting." . PHP_EOL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,5 +28,7 @@ foreach ($file_list as $file) {
|
|||||||
echo 'Processing ' . $filename . PHP_EOL;
|
echo 'Processing ' . $filename . PHP_EOL;
|
||||||
$g = GotuObject::fromXmlParser($xp);
|
$g = GotuObject::fromXmlParser($xp);
|
||||||
print_r($g);
|
print_r($g);
|
||||||
$sqlw->addGotu($g);
|
if ($g->tv) {
|
||||||
|
$sqlw->addGotu($g);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,12 @@ CREATE TABLE "updates" (
|
|||||||
"type" TEXT, -- FULL or OTA
|
"type" TEXT, -- FULL or OTA
|
||||||
"note" TEXT -- some note for this file (optional)
|
"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
|
-- Maps update files to devices
|
||||||
CREATE TABLE "update_map" (
|
CREATE TABLE "update_map" (
|
||||||
|
Loading…
Reference in New Issue
Block a user