\r
void MessageInserter::CheckForNeededInsert()\r
{\r
+ bool didinsert=false;\r
// only do 1 insert at a time\r
if(m_inserting.size()==0)\r
{\r
SQLite3DB::Statement st=m_db->Prepare("SELECT MessageUUID FROM tblMessageInserts INNER JOIN tblLocalIdentity ON tblMessageInserts.LocalIdentityID=tblLocalIdentity.LocalIdentityID WHERE tblLocalIdentity.PrivateKey IS NOT NULL AND tblLocalIdentity.PrivateKey <> '' AND tblMessageInserts.Inserted='false';");\r
st.Step();\r
\r
- if(st.RowReturned())\r
+ while(st.RowReturned() && m_inserting.size()==0)\r
{\r
- std::string messageuuid;\r
+ std::string messageuuid="";\r
st.ResultText(0,messageuuid);\r
- StartInsert(messageuuid);\r
+\r
+ // make sure there are no uninserted files attached to this message\r
+ SQLite3DB::Statement st2=m_db->Prepare("SELECT FileInsertID FROM tblFileInserts WHERE Key IS NULL AND MessageUUID=?;");\r
+ st2.Bind(0,messageuuid);\r
+ st2.Step();\r
+\r
+ if(st2.RowReturned()==false)\r
+ {\r
+ StartInsert(messageuuid);\r
+ }\r
+\r
+ st.Step();\r
}\r
}\r
}\r
int localidentityid;\r
int index;\r
std::vector<std::string> idparts;\r
+\r
StringFunctions::Split(message["Identifier"],"|",idparts);\r
StringFunctions::Convert(idparts[3],index);\r
StringFunctions::Convert(idparts[2],localidentityid);\r
st2.Bind(1,xml.GetXML());\r
st2.Bind(2,idparts[1]);\r
st2.Step();\r
+\r
+ //update file insert MessageUUID as well\r
+ st2=m_db->Prepare("UPDATE tblFileInserts SET MessageUUID=? WHERE MessageUUID=?;");\r
+ st2.Bind(0,idparts[4]);\r
+ st2.Bind(1,idparts[1]);\r
+ st2.Step();\r
}\r
\r
RemoveFromInsertList(idparts[1]);\r
}\r
StringFunctions::Convert(index,indexstr);\r
\r
+ xmlfile.ParseXML(xml);\r
+\r
+ // add file attachments to xml - must do this before we change UUID\r
+ st=m_db->Prepare("SELECT Key, Size FROM tblFileInserts WHERE MessageUUID=?;");\r
+ st.Bind(0,xmlfile.GetMessageID());\r
+ st.Step();\r
+ while(st.RowReturned())\r
+ {\r
+ std::string key="";\r
+ int size;\r
+ \r
+ st.ResultText(0,key);\r
+ st.ResultInt(1,size);\r
+\r
+ xmlfile.AddFileAttachment(key,size);\r
+\r
+ st.Step();\r
+ }\r
+\r
// recreate messageuuid in xml - UUID of message will not match entry in MessageInserts table until we successfully insert it\r
// see HandlePutSuccessful\r
- xmlfile.ParseXML(xml);\r
// if we don't already have an @sskpart - add it\r
if(xmlfile.GetMessageID().find("@")==std::string::npos)\r
{\r