Exemplo n.º 1
0
        private IEnumerable <Soulseek.File> QueryTable(string text)
        {
            // sanitize the query string. there's probably more to it than this.
            text = text
                   .Replace("/", " ")
                   .Replace("\\", " ")
                   .Replace(":", " ")
                   .Replace("\"", " ");

            var query = $"SELECT * FROM cache WHERE cache MATCH '\"{text.Replace("'", "''")}\"'";

            SyncRoot.EnterReadLock();

            try
            {
                using (var cmd = new SqliteCommand(query, SQLite))
                {
                    var results = new List <string>();
                    var reader  = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        results.Add(reader.GetString(0));
                    }

                    return(results.Select(r => Files[r.Replace("''", "'")]));
                }
            }
            catch (Exception ex)
            {
                // temporary error trap to refine substitution rules
                Console.WriteLine($"[MALFORMED QUERY]: {query} ({ex.Message})");
                return(Enumerable.Empty <Soulseek.File>());
            }
            finally
            {
                SyncRoot.ExitReadLock();
            }
        }