Esempio n. 1
0
        public HFileState Execute(ISQLCommandExecutor commandExecutor)
        {
            //TODO: Pretty bad, make these two happen together
            commandExecutor.ExecuteCommand(
                command =>
            {
                command.CommandText
                    = @"INSERT INTO Files (fileName, deleted) 
                        VALUES (@fileName, 0);";
                command.Parameters.AddWithValue("@fileName", _location);

                command.ExecuteNonQuery();
            }
                );

            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                command.CommandText
                    = @"SELECT * 
                        FROM Files 
                        WHERE id = last_insert_rowid();";

                return command
                .ExecuteReader()
                .GetHFiles()
                .First();
            }
                       ));
        }
Esempio n. 2
0
 public void Execute(ISQLCommandExecutor commandExecutor)
 {
     commandExecutor.ExecuteCommand(
         command =>
     {
         command.CommandText = CreateCommand();
         command.Parameters.AddWithValue("@id", _file.Id);
         command.Parameters.AddWithValue("@fileName", _file.Location);
         command.ExecuteNonQuery();
     }
         );
 }
Esempio n. 3
0
        public void Execute(ISQLCommandExecutor commandExecutor)
        {
            commandExecutor.ExecuteCommand(
                command =>
            {
                command.CommandText
                    = @"DELETE FROM Images
                        WHERE deleted = 1;";

                command.ExecuteNonQuery();
            }
                );
        }
Esempio n. 4
0
        public IEnumerable <TagState> Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                command.CommandText
                    = @"SELECT * FROM Tags;";

                return command
                .ExecuteReader()
                .GetTags();
            }
                       ));
        }
Esempio n. 5
0
        public void Execute(ISQLCommandExecutor commandExecutor)
        {
            commandExecutor.ExecuteCommand(
                command =>
            {
                command.CommandText
                    = @"UPDATE Files
                        SET deleted = 1
                        WHERE id = @id;";

                command.Parameters.AddWithValue("@id", _file.Id);
                command.ExecuteNonQuery();
            }
                );
        }
Esempio n. 6
0
        public IEnumerable <TagState> Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                command.CommandText
                    = @"SELECT FileTags.tagId, Tags.name 
                       FROM FileTags INNER JOIN Tags 
                       ON FileTags.tagId = Tags.id
                       WHERE FileTags.fileId = @fileId;";
                command.Parameters.AddWithValue("@fileId", _file.Id);

                return command.ExecuteReader().GetTags();
            }
                       ));
        }
Esempio n. 7
0
        public void Execute(ISQLCommandExecutor commandExecutor)
        {
            commandExecutor.ExecuteCommand(
                command =>
            {
                command.CommandText
                    = @"INSERT OR REPLACE INTO TagValues
                        (id, value)
                        VALUES (@id, @value);";

                command.Parameters.AddWithValue("@id", _tag.Id);
                command.Parameters.AddWithValue("@value", _value);
                command.ExecuteNonQuery();
            }
                );
        }
Esempio n. 8
0
        public List <string> Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                command.CommandText
                    = @"SELECT value 
                        FROM TagValues
                        WHERE id = @id;";

                command.Parameters.AddWithValue("@id", _tag.Id);

                return GetValues(command.ExecuteReader()).ToList();
            }
                       ));
        }
Esempio n. 9
0
        public void Execute(ISQLCommandExecutor commandExecutor)
        {
            commandExecutor.ExecuteCommand(
                command =>
            {
                command.CommandText
                    = @"DELETE FROM FileTags
                        WHERE fileId = @fileId
                        AND tagId = @tagId;";

                command.Parameters.AddWithValue("@fileId", _file.Id);
                command.Parameters.AddWithValue("@tagId", _tag.Id);
                command.ExecuteNonQuery();
            }
                );
        }
Esempio n. 10
0
        public bool Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                command.CommandText
                    = @"INSERT OR IGNORE INTO FileTags
                        (fileId, tagId)
                        VALUES (@fileId, @tagId);";

                command.Parameters.AddWithValue("@fileId", _file.Id);
                command.Parameters.AddWithValue("@tagId", _tag.Id);
                return command.ExecuteNonQuery() == 1;
            }
                       ));
        }
Esempio n. 11
0
        public void Execute(ISQLCommandExecutor commandExecutor)
        {
            commandExecutor.ExecuteCommand(
                command =>
            {
                command.CommandText
                    = @"UPDATE Files
                        SET (fileHash, perceptualHash) = (@fileHash, @perceptualHash)
                        WHERE id = @id;";

                command.Parameters.AddWithValue("@id", _file.Id);
                command.Parameters.AddWithValue("@fileHash", _hash.DataHash);
                command.Parameters.AddWithValue("@perceptualHash", _hash.PerceptualHash);
                command.ExecuteNonQuery();
            }
                );
        }
Esempio n. 12
0
        public List <HFileState> Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                command.CommandText
                    = @"SELECT * 
                        FROM Files 
                        WHERE deleted = 1;";

                return command
                .ExecuteReader()
                .GetHFiles()
                .ToList();
            }
                       ));
        }
Esempio n. 13
0
        public TagState Execute(ISQLCommandExecutor commandExecutor)
        {
            var id = (int)commandExecutor.ExecuteCommand(
                command =>
            {
                command.CommandText
                    = @"INSERT OR REPLACE INTO Tags
                        (name)
                        VALUES (@name)";

                command.Parameters.AddWithValue("@name", _name);
                command.ExecuteNonQuery();

                return(command.Connection.LastInsertRowId);
            }
                );

            return(new(id, _name));
        }
Esempio n. 14
0
        public FileHash?Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command => {
                command.CommandText
                    = @"SELECT fileHash, perceptualHash
                        FROM Files
                        WHERE id = @id;";

                command.Parameters.AddWithValue("@id", _file.Id);

                var reader = command.ExecuteReader();
                // TODO: make extension
                return reader.Read()
                        ? new FileHash(reader.GetString(0), reader.GetStringOrNull(1))
                        : null;
            }
                       ));
        }
Esempio n. 15
0
        public TagState?Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                command.CommandText
                    = @"SELECT Tags.id, Tags.name 
                        FROM Tags LEFT OUTER JOIN TagValues 
                        ON Tags.id = TagValues.id
                        WHERE TagValues.value = @value OR Tags.name = @value;";

                command.Parameters.AddWithValue("@value", _value);

                return command
                .ExecuteReader()
                .GetTags()
                .FirstOrDefault();
            }
                       ));
        }
Esempio n. 16
0
        public List <HFileState> Execute(ISQLCommandExecutor commandExecutor)
        {
            return(commandExecutor.ExecuteCommand(
                       command =>
            {
                var commandText
                    = @"SELECT fileId, fileName, fileHash
                        FROM (" +
                      GetInnerQuery() +
                      @"
                        ) WHERE $WHERECLAUSE
                        $LIMIT;";
                commandText = commandText.Replace("$LIMIT", _query.Maximum != int.MaxValue ? $"LIMIT {_query.Maximum}" : "");
                commandText = commandText.Replace("$WHERECLAUSE", string.Join(" AND ", BuildWhereClauseParts()));

                command.CommandText = commandText;

                return command
                .ExecuteReader()
                .GetHFiles()
                .ToList();
            }
                       ));
        }
Esempio n. 17
0
 public Database(ILogger logger, IDatabaseConnection connection, ISQLCommandExecutor commandExecutor)
 {
     _logger          = logger;
     _commandExecutor = commandExecutor;
 }