diff --git a/lib/TclUpdates/SQLiteWriter.php b/lib/TclUpdates/SQLiteWriter.php index 0852c23..061e160 100755 --- a/lib/TclUpdates/SQLiteWriter.php +++ b/lib/TclUpdates/SQLiteWriter.php @@ -14,6 +14,7 @@ class SQLiteWriter if ($this->pdo === false) { return $sqlerror; } + $this->pdo->exec('PRAGMA foreign_keys=on;'); } private function insertArray($table, $data, $replace = false) @@ -75,6 +76,8 @@ class SQLiteWriter 'sha1' => $file_arr['file_sha1'], 'file_name' => $file_arr['file_name'], 'file_size' => $file_arr['file_size'], + 'fv' => $file_arr['fv'], + 'tv' => $file_arr['tv'], 'type' => $file_arr['type'], 'note' => json_encode($note, JSON_UNESCAPED_UNICODE), 'published_first' => $pubFirst, @@ -90,6 +93,8 @@ class SQLiteWriter 'file_name' => $g->filename, 'file_size' => $g->file_size, 'type' => $g->type, + 'fv' => $g->fv, + 'tv' => $g->tv, 'note' => array( 'en' => $g->description_en, 'ja' => $g->description_ja, @@ -98,8 +103,6 @@ class SQLiteWriter 'pubDate' => $g->time, )); $ok = $this->insertArray('updates', array( - 'tv' => $g->tv, - 'fv' => $g->fv, 'svn' => $g->svn, 'pubDate' => $g->time, 'publisher' => $g->publisher, diff --git a/sql/dbschema.sql b/sql/dbschema.sql index 7615543..ec43990 100644 --- a/sql/dbschema.sql +++ b/sql/dbschema.sql @@ -43,6 +43,8 @@ CREATE TABLE "files" ( "file_name" TEXT, -- filename of file "file_size" INTEGER, -- size "type" TEXT, -- FULL(4) or OTA(2) update + "fv" TEXT, -- from version (only for OTA) + "tv" TEXT, -- target version, e.g. AAQ302 "note" TEXT, -- description of file (optional) "published_first" INTEGER, -- stamp of earliest pubdate "published_last" INTEGER -- stamp of latest pubdate @@ -52,18 +54,14 @@ CREATE TABLE "files" ( -- a separate "files" table might get introduced later CREATE TABLE "updates" ( "updateId" INTEGER PRIMARY KEY AUTOINCREMENT, - "tv" TEXT, -- target version, e.g. AAQ302 - "fv" TEXT, -- from version (only for OTA) "svn" TEXT, -- version info from field "pubDate" INTEGER, -- published date "publisher" TEXT, -- publisher "fwId" TEXT, -- (CHANGES FOR THE SAME FILE_ID!!!) MAYBE MOVE TO update_map "file_id" TEXT, -- of first file - "file_sha1" TEXT -- SHA1 checksum of first file + "file_sha1" TEXT REFERENCES "files" ("sha1") -- SHA1 checksum of first file ); CREATE UNIQUE INDEX "index_updates" ON "updates" ( - "tv", - "fv", "fwId", "file_id" );