version 0.3.26
[fms.git] / src / dbsetup.cpp
index 1b037f7..e6065f7 100644 (file)
@@ -602,7 +602,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 +627,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