From a7fccbcf6fc4a6b42ce6381c65c85b3ca7fdee3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geir=20N=C3=B8klebye?= Date: Sat, 25 Jul 2015 20:35:25 +0200 Subject: [PATCH] Update PGSQL groups handler to accept search queries from the viewer Update PGSQL groups handler to accept search queries from the viewer. Fixed malformed query strings. Signed-off-by: Oren Hurvitz --- OpenSim/Data/PGSQL/PGSQLGroupsData.cs | 26 +++++++++---------- OpenSim/Data/PGSQL/PGSQLPresenceData.cs | 9 ++++--- .../Data/PGSQL/Resources/Presence.migrations | 8 ++++++ 3 files changed, 26 insertions(+), 17 deletions(-) mode change 100644 => 100755 OpenSim/Data/PGSQL/PGSQLGroupsData.cs mode change 100644 => 100755 OpenSim/Data/PGSQL/PGSQLPresenceData.cs mode change 100644 => 100755 OpenSim/Data/PGSQL/Resources/Presence.migrations diff --git a/OpenSim/Data/PGSQL/PGSQLGroupsData.cs b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs old mode 100644 new mode 100755 index 669e3c8174..e257e7c723 --- a/OpenSim/Data/PGSQL/PGSQLGroupsData.cs +++ b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs @@ -31,12 +31,13 @@ using System.Collections.Generic; using System.Reflection; using OpenSim.Framework; using OpenMetaverse; +using log4net; using Npgsql; namespace OpenSim.Data.PGSQL { public class PGSQLGroupsData : IGroupsData - { + { private PGSqlGroupsGroupsHandler m_Groups; private PGSqlGroupsMembershipHandler m_Membership; private PGSqlGroupsRolesHandler m_Roles; @@ -82,14 +83,17 @@ namespace OpenSim.Data.PGSQL public GroupData[] RetrieveGroups(string pattern) { + if (string.IsNullOrEmpty(pattern)) // True for where clause { - pattern = " true ORDER BY lower(\"Name\") LIMIT 100"; + pattern = " 1 ORDER BY lower(\"Name\") LIMIT 100"; + return m_Groups.Get(pattern); } - else - { - pattern = " lower(\"Name\") LIKE lower('%:pattern%') ORDER BY lower(\"Name\") LIMIT 100"; + else + { + pattern = " \"ShowInList\" = 1 AND lower(\"Name\") LIKE lower('%" + pattern + "%') ORDER BY lower(\"Name\") LIMIT 100"; + return m_Groups.Get(pattern, new NpgsqlParameter("pattern", pattern)); } } @@ -428,13 +432,11 @@ namespace OpenSim.Data.PGSQL public void DeleteOld() { - uint now = (uint)Util.UnixTimeSinceEpoch(); using (NpgsqlCommand cmd = new NpgsqlCommand()) { - cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < :tstamp", m_Realm); - cmd.Parameters.AddWithValue("tstamp", now - 14 * 24 * 60 * 60); // > 2 weeks old - + cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < CURRENT_DATE - INTERVAL '2 week'", m_Realm); + ExecuteNonQuery(cmd); } @@ -456,13 +458,11 @@ namespace OpenSim.Data.PGSQL public void DeleteOld() { - uint now = (uint)Util.UnixTimeSinceEpoch(); using (NpgsqlCommand cmd = new NpgsqlCommand()) { - cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < :tstamp", m_Realm); - cmd.Parameters.AddWithValue("tstamp", now - 14 * 24 * 60 * 60); // > 2 weeks old - + cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < CURRENT_DATE - INTERVAL '2 week'", m_Realm); + ExecuteNonQuery(cmd); } diff --git a/OpenSim/Data/PGSQL/PGSQLPresenceData.cs b/OpenSim/Data/PGSQL/PGSQLPresenceData.cs old mode 100644 new mode 100755 index 666de07c0d..0376585863 --- a/OpenSim/Data/PGSQL/PGSQLPresenceData.cs +++ b/OpenSim/Data/PGSQL/PGSQLPresenceData.cs @@ -66,7 +66,7 @@ namespace OpenSim.Data.PGSQL using (NpgsqlCommand cmd = new NpgsqlCommand()) { - cmd.CommandText = String.Format(@"DELETE FROM {0} WHERE ""RegionID""=:RegionID", m_Realm); + cmd.CommandText = String.Format("DELETE FROM {0} WHERE \"RegionID\" = :regionID", m_Realm); cmd.Parameters.Add(m_database.CreateParameter("RegionID", regionID)); cmd.Connection = conn; @@ -80,14 +80,15 @@ namespace OpenSim.Data.PGSQL PresenceData[] pd = Get("SessionID", sessionID.ToString()); if (pd.Length == 0) return false; + + if (regionID == UUID.Zero) + return false; using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) using (NpgsqlCommand cmd = new NpgsqlCommand()) { - cmd.CommandText = String.Format(@"UPDATE {0} SET - ""RegionID"" = :RegionID - WHERE ""SessionID"" = :SessionID", m_Realm); + cmd.CommandText = String.Format("UPDATE {0} SET \"RegionID\" = :regionID, \"LastSeen\" = now() WHERE \"SessionID\" = :sessionID", m_Realm); cmd.Parameters.Add(m_database.CreateParameter("SessionID", sessionID)); cmd.Parameters.Add(m_database.CreateParameter("RegionID", regionID)); diff --git a/OpenSim/Data/PGSQL/Resources/Presence.migrations b/OpenSim/Data/PGSQL/Resources/Presence.migrations old mode 100644 new mode 100755 index 684faa2717..482beef32a --- a/OpenSim/Data/PGSQL/Resources/Presence.migrations +++ b/OpenSim/Data/PGSQL/Resources/Presence.migrations @@ -28,3 +28,11 @@ BEGIN TRANSACTION; ALTER TABLE Presence ADD "LastSeen" Timestamp; COMMIT; + +:VERSION 3 # -------------------------- + +BEGIN; + +CREATE INDEX RegionID ON Presence("RegionID"); + +COMMIT;