From 154637b24439aa17040597769f767b55964b189c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Tue, 16 Sep 2025 18:37:58 +0100 Subject: [PATCH] patch from Licu Rau from Craft/World for PostgreSQL friends (untested :() --- .../Data/PGSQL/PGSQLGenericTableHandler.cs | 6 +-- OpenSim/Data/PGSQL/PGSQLUserAccountData.cs | 39 +++++++++++++------ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs index 7fe70d2c7a..868ad1a9e6 100644 --- a/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs +++ b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs @@ -46,7 +46,7 @@ namespace OpenSim.Data.PGSQL protected string m_ConnectionString; protected PGSQLManager m_database; //used for parameter type translation protected Dictionary m_Fields = - new Dictionary(); + new Dictionary(StringComparer.OrdinalIgnoreCase); protected Dictionary m_FieldTypes = new Dictionary(); @@ -101,7 +101,7 @@ namespace OpenSim.Data.PGSQL private void LoadFieldTypes() { - m_FieldTypes = new Dictionary(); + m_FieldTypes = new Dictionary(StringComparer.OrdinalIgnoreCase); string query = string.Format(@"select column_name,data_type from INFORMATION_SCHEMA.COLUMNS @@ -268,7 +268,7 @@ namespace OpenSim.Data.PGSQL List result = new List(); if (cmd.Connection == null) { - cmd.Connection = new NpgsqlConnection(m_connectionString); + cmd.Connection = new NpgsqlConnection(m_ConnectionString); } if (cmd.Connection.State == ConnectionState.Closed) { diff --git a/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs index 06bad1256b..b477550035 100644 --- a/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs +++ b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs @@ -107,21 +107,20 @@ namespace OpenSim.Data.PGSQL return retUA; } */ - /* public UserAccountData Get(UUID principalID, UUID scopeID) { UserAccountData ret = new UserAccountData(); ret.Data = new Dictionary(); - string sql = string.Format(@"select * from {0} where ""PrincipalID"" = :principalID", m_Realm); + string sql = string.Format(@"select * from {0} where ""PrincipalID"" = :PrincipalID", m_Realm); if (scopeID != UUID.Zero) - sql += @" and ""ScopeID"" = :scopeID"; + sql += @" and ""ScopeID"" = :ScopeID"; using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) { - cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); - cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); + cmd.Parameters.Add(m_database.CreateParameter("PrincipalID", principalID)); + cmd.Parameters.Add(m_database.CreateParameter("ScopeID", scopeID)); conn.Open(); using (NpgsqlDataReader result = cmd.ExecuteReader()) @@ -159,7 +158,6 @@ namespace OpenSim.Data.PGSQL return null; } - public override bool Store(UserAccountData data) { if (data.Data.ContainsKey("PrincipalID")) @@ -269,7 +267,6 @@ namespace OpenSim.Data.PGSQL } return false; } - */ /* public UserAccountData[] Get(string[] keys, string[] vals) { @@ -306,14 +303,14 @@ namespace OpenSim.Data.PGSQL { if (words.Length == 1) { - sql = String.Format(@"select * from {0} where (""ScopeID""=:ScopeID or ""ScopeID""=:UUIDZero) and (""FirstName"" ilike :search or ""LastName"" ilike :search)", m_Realm); - cmd.Parameters.Add(m_database.CreateParameter("scopeID", (UUID)scope_id)); + sql = String.Format(@"select * from {0} where (""ScopeID""=:ScopeID or ""ScopeID""=:UUIDZero) and (LOWER(""FirstName"" COLLATE ""en_US.utf8"") like LOWER(:search) or LOWER(""LastName"" COLLATE ""en_US.utf8"") like LOWER(:search))", m_Realm); + cmd.Parameters.Add(m_database.CreateParameter("ScopeID", (UUID)scope_id)); cmd.Parameters.Add (m_database.CreateParameter("UUIDZero", (UUID)UUID.Zero)); cmd.Parameters.Add(m_database.CreateParameter("search", "%" + words[0] + "%")); } else { - sql = String.Format(@"select * from {0} where (""ScopeID""=:ScopeID or ""ScopeID""=:UUIDZero) and (""FirstName"" ilike :searchFirst or ""LastName"" ilike :searchLast)", m_Realm); + sql = String.Format(@"select * from {0} where (""ScopeID""=:ScopeID or ""ScopeID""=:UUIDZero) and (LOWER(""FirstName"" COLLATE ""en_US.utf8"") like LOWER(:searchFirst) or LOWER(""LastName"" COLLATE ""en_US.utf8"") like LOWER(:searchLast))", m_Realm); cmd.Parameters.Add(m_database.CreateParameter("searchFirst", "%" + words[0] + "%")); cmd.Parameters.Add(m_database.CreateParameter("searchLast", "%" + words[1] + "%")); cmd.Parameters.Add (m_database.CreateParameter("UUIDZero", (UUID)UUID.Zero)); @@ -328,7 +325,27 @@ namespace OpenSim.Data.PGSQL public UserAccountData[] GetUsersWhere(UUID scopeID, string where) { - return null; + using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) + using (NpgsqlCommand cmd = new NpgsqlCommand()) + { + // Fix case sensitivity for PostgreSQL column names + where = where.Replace("PrincipalID", "\"PrincipalID\"") + .Replace("ScopeID", "\"ScopeID\"") + .Replace("FirstName", "\"FirstName\"") + .Replace("LastName", "\"LastName\""); + + if (!scopeID.IsZero()) + { + where = "(\"ScopeID\"=:ScopeID or \"ScopeID\"='00000000-0000-0000-0000-000000000000') and (" + where + ")"; + cmd.Parameters.Add(m_database.CreateParameter("ScopeID", scopeID)); + } + + cmd.CommandText = String.Format("select * from {0} where " + where, m_Realm); + cmd.Connection = conn; + + conn.Open(); + return DoQuery(cmd); + } } } }