From 430b74390eca427426173b6b7999702d5dc6fc1d Mon Sep 17 00:00:00 2001 From: Leonardo Robol Date: Wed, 17 Feb 2010 21:26:19 +0100 Subject: [PATCH] Aggiunto supporto a tante parole nel campo della ricerca. --- Dizzy/EventManager.cs | 2 +- Dizzy/FileList.cs | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Dizzy/EventManager.cs b/Dizzy/EventManager.cs index 3d33f89..031c235 100644 --- a/Dizzy/EventManager.cs +++ b/Dizzy/EventManager.cs @@ -87,7 +87,7 @@ namespace Dizzy } public static bool AuthenticationDialog () { - Log.Info ("Uei, sembra che qualcuno mi abbia chiesto di autenticarsi!"); + if (EventManager.authDialog == null) { EventManager.authDialog = new AuthDialog (); diff --git a/Dizzy/FileList.cs b/Dizzy/FileList.cs index 2e4e0e4..48fcc42 100644 --- a/Dizzy/FileList.cs +++ b/Dizzy/FileList.cs @@ -19,12 +19,34 @@ namespace Dizzy public ArrayList Search(string keyword, string type, string user) { + /* Facciamo qualche check per evitare utenti che inseriscono + * cose a caso */ + keyword.Replace("%", "\\%"); + keyword.Replace(";", "\\;"); + + /* keyword è presumibilmente nella forma di più keyword separate da + * spazi, e quindi dobbiamo sottoporla ad un "preprocessing" prima + * di darla in pasto ad una query sql. Per ora assumiamo che l'utente + * voglia l'unione dei risultati con le singole query. */ + string [] keys = keyword.Split(' '); + this.connection.Open (); ArrayList matches = new ArrayList (); // Eseguiamo la query SQLiteCommand sqlCmd = this.connection.CreateCommand (); - sqlCmd.CommandText = "SELECT * from files WHERE name LIKE '%" + keyword + "%'"; + string query = "SELECT * from files WHERE"; + foreach(string k in keys) + { + if (query.EndsWith("'")) + query += " OR name LIKE '%" + k + "%'"; + else + query += " name LIKE '%" + k + "%'"; + } + + query += ";"; + sqlCmd.CommandText = query; + Log.Warning ("Executing query " + sqlCmd.CommandText); SQLiteDataReader reader = sqlCmd.ExecuteReader (); File tmp; -- 2.1.4