Revision 159098f7 trunk/Pithos.Core/Agents/StatusAgent.cs

b/trunk/Pithos.Core/Agents/StatusAgent.cs
661 661
                using (var connection = GetConnection())
662 662
                using (var command = new SQLiteCommand(connection))
663 663
                {
664
                    if (StateExists(path, connection))
664
                    //If the ID exists, update the status
665
                    if (StateExistsByID(objectInfo.UUID,connection))
665 666
                        command.CommandText =
666
                            "update FileState set FileStatus= :fileStatus where FilePath = :path  COLLATE NOCASE ";
667
                            "update FileState set FilePath=:path,FileStatus= :fileStatus, Checksum=:checksum, ShortHash=:shortHash,Version=:version,VersionTimeStamp=:versionTimeStamp where ObjectID = :objectID  ";                        
668
                    else if (StateExists(path, connection))
669
                        //If the ID doesn't exist, try to update using the path, and store the ID as well.
670
                        command.CommandText =
671
                            "update FileState set FileStatus= :fileStatus, ObjectID=:objectID, Checksum=:checksum, ShortHash=:shortHash,Version=:version,VersionTimeStamp=:versionTimeStamp where FilePath = :path  COLLATE NOCASE ";
667 672
                    else
668 673
                    {
669 674
                        command.CommandText =
......
702 707

  
703 708
        }
704 709

  
710
        private bool StateExistsByID(string objectId,SQLiteConnection connection)
711
        {
712
            using (var command = new SQLiteCommand("Select count(*) from FileState where ObjectId=:id", connection))
713
            {
714
                command.Parameters.AddWithValue("id", objectId);
715
                var result = command.ExecuteScalar();
716
                return ((long)result >= 1);
717
            }
718

  
719
        }
720

  
705 721
        public void SetFileStatus(string path, FileStatus status)
706 722
        {
707 723
            if (String.IsNullOrWhiteSpace(path))

Also available in: Unified diff