m_db->Execute("DELETE FROM tblIntroductionPuzzleInserts WHERE Day<='"+date.Format("%Y-%m-%d")+"';");\r
m_db->Execute("DELETE FROM tblIntroductionPuzzleRequests WHERE Day<='"+date.Format("%Y-%m-%d")+"';");\r
\r
- m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"PeriodicDBMaintenance::Do1DayMaintenance");\r
-\r
// delete all identities we've never seen and were added more than 20 days ago\r
date.SetToGMTime();\r
date.Add(0,0,0,-20);\r
while(st.RowReturned())\r
{\r
std::string name="";\r
+ std::string namepart="";\r
std::string publickey="";\r
int identityid=0;\r
st.ResultText(0,name);\r
std::vector<std::string> parts;\r
StringFunctions::Split(name,"@",parts);\r
\r
+ // name can have a @ in it - so reattach all parts except the last which is the key\r
+ for(long i=0; i<parts.size()-1; i++)\r
+ {\r
+ if(i!=0)\r
+ {\r
+ namepart+="@";\r
+ }\r
+ namepart+=parts[i];\r
+ }\r
+\r
// find identities with this name\r
SQLite3DB::Statement st2=m_db->Prepare("SELECT IdentityID,PublicKey FROM tblIdentity WHERE Name=?;");\r
- st2.Bind(0,name);\r
+ st2.Bind(0,namepart);\r
st2.Step();\r
while(st2.RowReturned())\r
{\r
// we have the identity - so update the messages table with the identityid\r
st2.ResultInt(0,identityid);\r
\r
- SQLite3DB::Statement st3=m_db->Prepare("UPDATE tblMessage SET IdentityID=? WHERE Name=? AND IdentityID IS NULL;");\r
+ SQLite3DB::Statement st3=m_db->Prepare("UPDATE tblMessage SET IdentityID=? WHERE FromName=? AND IdentityID IS NULL;");\r
st3.Bind(0,identityid);\r
st3.Bind(1,name);\r
st3.Step();\r
st.Bind(0,date.Format("%Y-%m-%d"));\r
st.Step();\r
\r
+ // delete tblIdentityTrust for local identities and identities that have been deleted\r
+ m_db->Execute("DELETE FROM tblIdentityTrust WHERE LocalIdentityID NOT IN (SELECT LocalIdentityID FROM tblLocalIdentity);");\r
+ m_db->Execute("DELETE FROM tblIdentityTrust WHERE IdentityID NOT IN (SELECT IdentityID FROM tblIdentity);");\r
+\r
+ m_log->WriteLog(LogFile::LOGLEVEL_DEBUG,"PeriodicDBMaintenance::Do1DayMaintenance");\r
+\r
}\r
\r
void PeriodicDBMaintenance::Process()\r