version 0.3.27
[fms.git] / src / dbsetup.cpp
index 1b037f7..1316bb2 100644 (file)
@@ -430,6 +430,7 @@ void SetupDB()
 \r
        // MessageInserter will insert a record into this temp table which the MessageListInserter will query for and insert a MessageList when needed\r
        db->Execute("CREATE TEMPORARY TABLE IF NOT EXISTS tmpMessageListInsert(\\r
+                               MessageListInsertID     INTEGER PRIMARY KEY,\\r
                                LocalIdentityID         INTEGER,\\r
                                Date                            DATETIME\\r
                                );");\r
@@ -602,7 +603,24 @@ const bool VerifyDB()
                }\r
                else\r
                {\r
-                       return false;\r
+                       // try to reindex and vacuum database in case of index corruption\r
+                       st=db->Prepare("REINDEX;");\r
+                       st.Step();\r
+                       st=db->Prepare("VACUUM;");\r
+                       st.Step();\r
+\r
+                       // check integrity again\r
+                       st=db->Prepare("PRAGMA integrity_check;");\r
+                       st.Step();\r
+                       st.ResultText(0,res);\r
+                       if(res=="ok")\r
+                       {\r
+                               return true;\r
+                       }\r
+                       else\r
+                       {\r
+                               return false;\r
+                       }\r
                }\r
        }\r
        else\r
@@ -610,3 +628,20 @@ const bool VerifyDB()
                return false;\r
        }\r
 }\r
+\r
+const std::string TestDBIntegrity()\r
+{\r
+       std::string result="";\r
+\r
+       SQLite3DB::DB *db=SQLite3DB::DB::Instance();\r
+       SQLite3DB::Statement st=db->Prepare("PRAGMA integrity_check;");\r
+       st.Step();\r
+       while(st.RowReturned())\r
+       {\r
+               std::string text="";\r
+               st.ResultText(0,text);\r
+               result+=text;\r
+               st.Step();\r
+       }\r
+       return result;\r
+}\r