00001 #include <qstring.h>
00002
00003 #include <iostream>
00004 using namespace std;
00005
00006 #include "dbcheck.h"
00007
00008 #include "mythtv/mythcontext.h"
00009 #include "mythtv/mythdbcon.h"
00010
00011 const QString currentDatabaseVersion = "1000";
00012
00013 static bool UpdateDBVersionNumber(const QString &newnumber)
00014 {
00015
00016 if (!gContext->SaveSettingOnHost("GalleryDBSchemaVer",newnumber,NULL))
00017 {
00018 VERBOSE(VB_IMPORTANT, QString("DB Error (Setting new DB version number): %1\n")
00019 .arg(newnumber));
00020
00021 return false;
00022 }
00023
00024 return true;
00025 }
00026
00027 static void performActualUpdate(const QString updates[], QString version,
00028 QString &dbver)
00029 {
00030 MSqlQuery query(MSqlQuery::InitCon());
00031
00032 VERBOSE(VB_IMPORTANT, QString("Upgrading to MythGallery schema version ") +
00033 version);
00034
00035 int counter = 0;
00036 QString thequery = updates[counter];
00037
00038 while (thequery != "")
00039 {
00040 query.exec(thequery);
00041 counter++;
00042 thequery = updates[counter];
00043 }
00044
00045 UpdateDBVersionNumber(version);
00046 dbver = version;
00047 }
00048
00049 void UpgradeGalleryDatabaseSchema(void)
00050 {
00051 QString dbver = gContext->GetSetting("GalleryDBSchemaVer");
00052
00053 if (dbver == currentDatabaseVersion)
00054 return;
00055
00056 if (dbver == "")
00057 {
00058 VERBOSE(VB_IMPORTANT, "Inserting MythGallery initial database information.");
00059
00060 const QString updates[] = {
00061 "CREATE TABLE IF NOT EXISTS gallerymetadata ("
00062 " image VARCHAR(255) NOT NULL PRIMARY KEY,"
00063 " angle INTEGER NOT NULL"
00064 ");",
00065 "INSERT INTO settings VALUES ('GalleryDBSchemaVer', 1000, NULL);",
00066 ""
00067 };
00068 performActualUpdate(updates, "1000", dbver);
00069 }
00070 }