From 05506cff499b999d6c01e0517e658293b4791317 Mon Sep 17 00:00:00 2001 From: Melanie Thielker Date: Mon, 18 Aug 2008 17:22:36 +0000 Subject: Avatar Attachment persistence!! Patch #9168 (Mantis #1171) Plumbs in attachment persistence and adds the tables. Currently MySQL only, no user functionality yet. --- OpenSim/Data/MySQL/MySQLManager.cs | 51 +++++++++++++++++++++++++ OpenSim/Data/MySQL/MySQLUserData.cs | 25 ++++++++++++ OpenSim/Data/MySQL/Resources/005_UserStore.sql | 5 +++ OpenSim/Data/SQLite/Resources/005_UserStore.sql | 5 +++ 4 files changed, 86 insertions(+) create mode 100644 OpenSim/Data/MySQL/Resources/005_UserStore.sql create mode 100644 OpenSim/Data/SQLite/Resources/005_UserStore.sql (limited to 'OpenSim/Data') diff --git a/OpenSim/Data/MySQL/MySQLManager.cs b/OpenSim/Data/MySQL/MySQLManager.cs index 6ad6609..3a62ec2 100644 --- a/OpenSim/Data/MySQL/MySQLManager.cs +++ b/OpenSim/Data/MySQL/MySQLManager.cs @@ -27,6 +27,7 @@ using System; using System.Collections.Generic; +using System.Collections; using System.Data; using System.IO; using System.Reflection; @@ -660,6 +661,26 @@ namespace OpenSim.Data.MySQL } + // Read attachment list from data reader + public Hashtable readAttachments(IDataReader r) + { + Hashtable ret = new Hashtable(); + + while(r.Read()) + { + int attachpoint = Convert.ToInt32(r["attachpoint"]); + if(ret.ContainsKey(attachpoint)) + continue; + Hashtable item = new Hashtable(); + item.Add("item", r["item"].ToString()); + item.Add("asset", r["asset"].ToString()); + + ret.Add(attachpoint, item); + } + + return ret; + } + /// /// Inserts a new row into the log database /// @@ -1176,5 +1197,35 @@ namespace OpenSim.Data.MySQL } + public void writeAttachments(LLUUID agentID, Hashtable data) + { + string sql = "delete from avatarattachments where UUID = ?uuid"; + + MySqlCommand cmd = (MySqlCommand) dbcon.CreateCommand(); + cmd.CommandText = sql; + cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); + + cmd.ExecuteNonQuery(); + + sql = "insert into avatarattachments (UUID, attachpoint, item, asset) values (?uuid, ?attchpoint, ?item, ?asset)"; + + cmd = (MySqlCommand) dbcon.CreateCommand(); + cmd.CommandText = sql; + + foreach(DictionaryEntry e in data) + { + int attachpoint = Convert.ToInt32(e.Key); + + Hashtable item = (Hashtable)e.Value; + + cmd.Parameters.Clear(); + cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); + cmd.Parameters.AddWithValue("?attachpoint", attachpoint); + cmd.Parameters.AddWithValue("?item", item["item"]); + cmd.Parameters.AddWithValue("?asset", item["asset"]); + + cmd.ExecuteNonQuery(); + } + } } } diff --git a/OpenSim/Data/MySQL/MySQLUserData.cs b/OpenSim/Data/MySQL/MySQLUserData.cs index f77d947..627bc0c 100644 --- a/OpenSim/Data/MySQL/MySQLUserData.cs +++ b/OpenSim/Data/MySQL/MySQLUserData.cs @@ -26,6 +26,7 @@ */ using System; +using System.Collections; using System.Collections.Generic; using System.Data; using System.Reflection; @@ -34,6 +35,7 @@ using libsecondlife; using log4net; using OpenSim.Framework; using OpenSim.Data.Base; +using MySql.Data.MySqlClient; namespace OpenSim.Data.MySQL { @@ -737,6 +739,8 @@ namespace OpenSim.Data.MySQL reader.Dispose(); result.Dispose(); + appearance.SetAttachments(GetUserAttachments(user)); + return appearance; } } @@ -762,6 +766,8 @@ namespace OpenSim.Data.MySQL { appearance.Owner = user; database.insertAppearanceRow(appearance); + + UpdateUserAttachments(user, appearance.GetAttachments()); } } catch (Exception e) @@ -818,5 +824,24 @@ namespace OpenSim.Data.MySQL { get {return "0.1";} } + + public Hashtable GetUserAttachments(LLUUID agentID) + { + MySqlCommand cmd = (MySqlCommand) (database.Connection.CreateCommand()); + cmd.CommandText = "select attachpoint, item, asset from avatarattachments where UUID = ?uuid"; + cmd.Parameters.AddWithValue("?uuid", agentID.ToString()); + + IDataReader r = cmd.ExecuteReader(); + + return database.readAttachments(r); + } + + public void UpdateUserAttachments(LLUUID agentID, Hashtable data) + { + if(data == null) + return; + + database.writeAttachments(agentID, data); + } } } diff --git a/OpenSim/Data/MySQL/Resources/005_UserStore.sql b/OpenSim/Data/MySQL/Resources/005_UserStore.sql new file mode 100644 index 0000000..55896bc --- /dev/null +++ b/OpenSim/Data/MySQL/Resources/005_UserStore.sql @@ -0,0 +1,5 @@ +BEGIN; + +CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL, `attachpoint` int(11) NOT NULL, `item` char(36) NOT NULL, `asset` char(36) NOT NULL) ENGINE=InnoDB; + +COMMIT; diff --git a/OpenSim/Data/SQLite/Resources/005_UserStore.sql b/OpenSim/Data/SQLite/Resources/005_UserStore.sql new file mode 100644 index 0000000..e45c09a --- /dev/null +++ b/OpenSim/Data/SQLite/Resources/005_UserStore.sql @@ -0,0 +1,5 @@ +BEGIN; + +CREATE TABLE `avatarattachments` (`UUID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `attachpoint` int(11) NOT NULL DEFAULT 0, `item` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', `asset` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'); + +COMMIT; -- cgit v1.1