diff options
author | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
---|---|---|
committer | David Walter Seikel | 2016-11-03 21:44:39 +1000 |
commit | 134f86e8d5c414409631b25b8c6f0ee45fbd8631 (patch) | |
tree | 216b89d3fb89acfb81be1e440c25c41ab09fa96d /OpenSim/Data/PGSQL | |
parent | More changing to production grid. Double oops. (diff) | |
download | opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.zip opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.gz opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.bz2 opensim-SC-134f86e8d5c414409631b25b8c6f0ee45fbd8631.tar.xz |
Initial update to OpenSim 0.8.2.1 source code.
Diffstat (limited to 'OpenSim/Data/PGSQL')
41 files changed, 12420 insertions, 0 deletions
diff --git a/OpenSim/Data/PGSQL/PGSQLAgentPreferencesData.cs b/OpenSim/Data/PGSQL/PGSQLAgentPreferencesData.cs new file mode 100644 index 0000000..20612fe --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLAgentPreferencesData.cs | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using Npgsql; | ||
35 | |||
36 | namespace OpenSim.Data.PGSQL | ||
37 | { | ||
38 | public class PGSQLAgentPreferencesData : PGSQLGenericTableHandler<AgentPreferencesData>, IAgentPreferencesData | ||
39 | { | ||
40 | public PGSQLAgentPreferencesData(string connectionString, string realm) | ||
41 | : base(connectionString, realm, "AgentPrefs") | ||
42 | { | ||
43 | } | ||
44 | |||
45 | public AgentPreferencesData GetPrefs(UUID agentID) | ||
46 | { | ||
47 | // Until someone sends in a table that works | ||
48 | return null; | ||
49 | //AgentPreferencesData[] ret = Get("PrincipalID", agentID.ToString()); | ||
50 | |||
51 | //if (ret.Length == 0) | ||
52 | // return null; | ||
53 | |||
54 | //return ret[0]; | ||
55 | } | ||
56 | |||
57 | public override bool Store(AgentPreferencesData row) | ||
58 | { | ||
59 | // Until someone sends in a table that works | ||
60 | return false; | ||
61 | } | ||
62 | |||
63 | } | ||
64 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLAssetData.cs b/OpenSim/Data/PGSQL/PGSQLAssetData.cs new file mode 100644 index 0000000..5d8b0a2 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLAssetData.cs | |||
@@ -0,0 +1,316 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Data; | ||
30 | using System.Reflection; | ||
31 | using System.Collections.Generic; | ||
32 | using OpenMetaverse; | ||
33 | using log4net; | ||
34 | using OpenSim.Framework; | ||
35 | using Npgsql; | ||
36 | using NpgsqlTypes; | ||
37 | |||
38 | namespace OpenSim.Data.PGSQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A PGSQL Interface for the Asset server | ||
42 | /// </summary> | ||
43 | public class PGSQLAssetData : AssetDataBase | ||
44 | { | ||
45 | private const string _migrationStore = "AssetStore"; | ||
46 | |||
47 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | private long m_ticksToEpoch; | ||
49 | /// <summary> | ||
50 | /// Database manager | ||
51 | /// </summary> | ||
52 | private PGSQLManager m_database; | ||
53 | private string m_connectionString; | ||
54 | |||
55 | protected virtual Assembly Assembly | ||
56 | { | ||
57 | get { return GetType().Assembly; } | ||
58 | } | ||
59 | |||
60 | #region IPlugin Members | ||
61 | |||
62 | override public void Dispose() { } | ||
63 | |||
64 | /// <summary> | ||
65 | /// <para>Initialises asset interface</para> | ||
66 | /// </summary> | ||
67 | // [Obsolete("Cannot be default-initialized!")] | ||
68 | override public void Initialise() | ||
69 | { | ||
70 | m_log.Info("[PGSQLAssetData]: " + Name + " cannot be default-initialized!"); | ||
71 | throw new PluginNotInitialisedException(Name); | ||
72 | } | ||
73 | |||
74 | /// <summary> | ||
75 | /// Initialises asset interface | ||
76 | /// </summary> | ||
77 | /// <para> | ||
78 | /// a string instead of file, if someone writes the support | ||
79 | /// </para> | ||
80 | /// <param name="connectionString">connect string</param> | ||
81 | override public void Initialise(string connectionString) | ||
82 | { | ||
83 | m_ticksToEpoch = new System.DateTime(1970, 1, 1).Ticks; | ||
84 | |||
85 | m_database = new PGSQLManager(connectionString); | ||
86 | m_connectionString = connectionString; | ||
87 | |||
88 | //New migration to check for DB changes | ||
89 | m_database.CheckMigration(_migrationStore); | ||
90 | } | ||
91 | |||
92 | /// <summary> | ||
93 | /// Database provider version. | ||
94 | /// </summary> | ||
95 | override public string Version | ||
96 | { | ||
97 | get { return m_database.getVersion(); } | ||
98 | } | ||
99 | |||
100 | /// <summary> | ||
101 | /// The name of this DB provider. | ||
102 | /// </summary> | ||
103 | override public string Name | ||
104 | { | ||
105 | get { return "PGSQL Asset storage engine"; } | ||
106 | } | ||
107 | |||
108 | #endregion | ||
109 | |||
110 | #region IAssetDataPlugin Members | ||
111 | |||
112 | /// <summary> | ||
113 | /// Fetch Asset from m_database | ||
114 | /// </summary> | ||
115 | /// <param name="assetID">the asset UUID</param> | ||
116 | /// <returns></returns> | ||
117 | override public AssetBase GetAsset(UUID assetID) | ||
118 | { | ||
119 | string sql = "SELECT * FROM assets WHERE id = :id"; | ||
120 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
121 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
122 | { | ||
123 | cmd.Parameters.Add(m_database.CreateParameter("id", assetID)); | ||
124 | conn.Open(); | ||
125 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
126 | { | ||
127 | if (reader.Read()) | ||
128 | { | ||
129 | AssetBase asset = new AssetBase( | ||
130 | DBGuid.FromDB(reader["id"]), | ||
131 | (string)reader["name"], | ||
132 | Convert.ToSByte(reader["assetType"]), | ||
133 | reader["creatorid"].ToString() | ||
134 | ); | ||
135 | // Region Main | ||
136 | asset.Description = (string)reader["description"]; | ||
137 | asset.Local = Convert.ToBoolean(reader["local"]); | ||
138 | asset.Temporary = Convert.ToBoolean(reader["temporary"]); | ||
139 | asset.Flags = (AssetFlags)(Convert.ToInt32(reader["asset_flags"])); | ||
140 | asset.Data = (byte[])reader["data"]; | ||
141 | return asset; | ||
142 | } | ||
143 | return null; // throw new Exception("No rows to return"); | ||
144 | } | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /// <summary> | ||
149 | /// Create asset in m_database | ||
150 | /// </summary> | ||
151 | /// <param name="asset">the asset</param> | ||
152 | override public void StoreAsset(AssetBase asset) | ||
153 | { | ||
154 | |||
155 | string sql = | ||
156 | @"UPDATE assets set name = :name, description = :description, " + "\"assetType\" " + @" = :assetType, | ||
157 | local = :local, temporary = :temporary, creatorid = :creatorid, data = :data | ||
158 | WHERE id=:id; | ||
159 | |||
160 | INSERT INTO assets | ||
161 | (id, name, description, " + "\"assetType\" " + @", local, | ||
162 | temporary, create_time, access_time, creatorid, asset_flags, data) | ||
163 | Select :id, :name, :description, :assetType, :local, | ||
164 | :temporary, :create_time, :access_time, :creatorid, :asset_flags, :data | ||
165 | Where not EXISTS(SELECT * FROM assets WHERE id=:id) | ||
166 | "; | ||
167 | |||
168 | string assetName = asset.Name; | ||
169 | if (asset.Name.Length > AssetBase.MAX_ASSET_NAME) | ||
170 | { | ||
171 | assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); | ||
172 | m_log.WarnFormat( | ||
173 | "[ASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
174 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); | ||
175 | } | ||
176 | |||
177 | string assetDescription = asset.Description; | ||
178 | if (asset.Description.Length > AssetBase.MAX_ASSET_DESC) | ||
179 | { | ||
180 | assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC); | ||
181 | m_log.WarnFormat( | ||
182 | "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
183 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); | ||
184 | } | ||
185 | |||
186 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
187 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) | ||
188 | { | ||
189 | int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); | ||
190 | command.Parameters.Add(m_database.CreateParameter("id", asset.FullID)); | ||
191 | command.Parameters.Add(m_database.CreateParameter("name", assetName)); | ||
192 | command.Parameters.Add(m_database.CreateParameter("description", assetDescription)); | ||
193 | command.Parameters.Add(m_database.CreateParameter("assetType", asset.Type)); | ||
194 | command.Parameters.Add(m_database.CreateParameter("local", asset.Local)); | ||
195 | command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary)); | ||
196 | command.Parameters.Add(m_database.CreateParameter("access_time", now)); | ||
197 | command.Parameters.Add(m_database.CreateParameter("create_time", now)); | ||
198 | command.Parameters.Add(m_database.CreateParameter("asset_flags", (int)asset.Flags)); | ||
199 | command.Parameters.Add(m_database.CreateParameter("creatorid", asset.Metadata.CreatorID)); | ||
200 | command.Parameters.Add(m_database.CreateParameter("data", asset.Data)); | ||
201 | conn.Open(); | ||
202 | try | ||
203 | { | ||
204 | command.ExecuteNonQuery(); | ||
205 | } | ||
206 | catch(Exception e) | ||
207 | { | ||
208 | m_log.Error("[ASSET DB]: Error storing item :" + e.Message + " sql "+sql); | ||
209 | } | ||
210 | } | ||
211 | } | ||
212 | |||
213 | |||
214 | // Commented out since currently unused - this probably should be called in GetAsset() | ||
215 | // private void UpdateAccessTime(AssetBase asset) | ||
216 | // { | ||
217 | // using (AutoClosingSqlCommand cmd = m_database.Query("UPDATE assets SET access_time = :access_time WHERE id=:id")) | ||
218 | // { | ||
219 | // int now = (int)((System.DateTime.Now.Ticks - m_ticksToEpoch) / 10000000); | ||
220 | // cmd.Parameters.AddWithValue(":id", asset.FullID.ToString()); | ||
221 | // cmd.Parameters.AddWithValue(":access_time", now); | ||
222 | // try | ||
223 | // { | ||
224 | // cmd.ExecuteNonQuery(); | ||
225 | // } | ||
226 | // catch (Exception e) | ||
227 | // { | ||
228 | // m_log.Error(e.ToString()); | ||
229 | // } | ||
230 | // } | ||
231 | // } | ||
232 | |||
233 | /// <summary> | ||
234 | /// Check if the assets exist in the database. | ||
235 | /// </summary> | ||
236 | /// <param name="uuids">The assets' IDs</param> | ||
237 | /// <returns>For each asset: true if it exists, false otherwise</returns> | ||
238 | public override bool[] AssetsExist(UUID[] uuids) | ||
239 | { | ||
240 | if (uuids.Length == 0) | ||
241 | return new bool[0]; | ||
242 | |||
243 | HashSet<UUID> exist = new HashSet<UUID>(); | ||
244 | |||
245 | string ids = "'" + string.Join("','", uuids) + "'"; | ||
246 | string sql = string.Format("SELECT id FROM assets WHERE id IN ({0})", ids); | ||
247 | |||
248 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
249 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
250 | { | ||
251 | conn.Open(); | ||
252 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
253 | { | ||
254 | while (reader.Read()) | ||
255 | { | ||
256 | UUID id = DBGuid.FromDB(reader["id"]); | ||
257 | exist.Add(id); | ||
258 | } | ||
259 | } | ||
260 | } | ||
261 | |||
262 | bool[] results = new bool[uuids.Length]; | ||
263 | for (int i = 0; i < uuids.Length; i++) | ||
264 | results[i] = exist.Contains(uuids[i]); | ||
265 | return results; | ||
266 | } | ||
267 | |||
268 | /// <summary> | ||
269 | /// Returns a list of AssetMetadata objects. The list is a subset of | ||
270 | /// the entire data set offset by <paramref name="start" /> containing | ||
271 | /// <paramref name="count" /> elements. | ||
272 | /// </summary> | ||
273 | /// <param name="start">The number of results to discard from the total data set.</param> | ||
274 | /// <param name="count">The number of rows the returned list should contain.</param> | ||
275 | /// <returns>A list of AssetMetadata objects.</returns> | ||
276 | public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) | ||
277 | { | ||
278 | List<AssetMetadata> retList = new List<AssetMetadata>(count); | ||
279 | string sql = @" SELECT id, name, description, " + "\"assetType\"" + @", temporary, creatorid | ||
280 | FROM assets | ||
281 | order by id | ||
282 | limit :stop | ||
283 | offset :start;"; | ||
284 | |||
285 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
286 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
287 | { | ||
288 | cmd.Parameters.Add(m_database.CreateParameter("start", start)); | ||
289 | cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1)); | ||
290 | conn.Open(); | ||
291 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
292 | { | ||
293 | while (reader.Read()) | ||
294 | { | ||
295 | AssetMetadata metadata = new AssetMetadata(); | ||
296 | metadata.FullID = DBGuid.FromDB(reader["id"]); | ||
297 | metadata.Name = (string)reader["name"]; | ||
298 | metadata.Description = (string)reader["description"]; | ||
299 | metadata.Type = Convert.ToSByte(reader["assetType"]); | ||
300 | metadata.Temporary = Convert.ToBoolean(reader["temporary"]); | ||
301 | metadata.CreatorID = (string)reader["creatorid"]; | ||
302 | retList.Add(metadata); | ||
303 | } | ||
304 | } | ||
305 | } | ||
306 | |||
307 | return retList; | ||
308 | } | ||
309 | |||
310 | public override bool Delete(string id) | ||
311 | { | ||
312 | return false; | ||
313 | } | ||
314 | #endregion | ||
315 | } | ||
316 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLAuthenticationData.cs b/OpenSim/Data/PGSQL/PGSQLAuthenticationData.cs new file mode 100644 index 0000000..d174112 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLAuthenticationData.cs | |||
@@ -0,0 +1,254 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ''AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using OpenMetaverse; | ||
32 | using OpenSim.Framework; | ||
33 | using System.Reflection; | ||
34 | using System.Text; | ||
35 | using System.Data; | ||
36 | using Npgsql; | ||
37 | using NpgsqlTypes; | ||
38 | |||
39 | namespace OpenSim.Data.PGSQL | ||
40 | { | ||
41 | public class PGSQLAuthenticationData : IAuthenticationData | ||
42 | { | ||
43 | private string m_Realm; | ||
44 | private List<string> m_ColumnNames = null; | ||
45 | private int m_LastExpire = 0; | ||
46 | private string m_ConnectionString; | ||
47 | private PGSQLManager m_database; | ||
48 | |||
49 | protected virtual Assembly Assembly | ||
50 | { | ||
51 | get { return GetType().Assembly; } | ||
52 | } | ||
53 | |||
54 | public PGSQLAuthenticationData(string connectionString, string realm) | ||
55 | { | ||
56 | m_Realm = realm; | ||
57 | m_ConnectionString = connectionString; | ||
58 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
59 | { | ||
60 | conn.Open(); | ||
61 | Migration m = new Migration(conn, GetType().Assembly, "AuthStore"); | ||
62 | m_database = new PGSQLManager(m_ConnectionString); | ||
63 | m.Update(); | ||
64 | } | ||
65 | } | ||
66 | |||
67 | public AuthenticationData Get(UUID principalID) | ||
68 | { | ||
69 | AuthenticationData ret = new AuthenticationData(); | ||
70 | ret.Data = new Dictionary<string, object>(); | ||
71 | |||
72 | string sql = string.Format("select * from {0} where uuid = :principalID", m_Realm); | ||
73 | |||
74 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
75 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
76 | { | ||
77 | cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); | ||
78 | conn.Open(); | ||
79 | using (NpgsqlDataReader result = cmd.ExecuteReader()) | ||
80 | { | ||
81 | if (result.Read()) | ||
82 | { | ||
83 | ret.PrincipalID = principalID; | ||
84 | |||
85 | if (m_ColumnNames == null) | ||
86 | { | ||
87 | m_ColumnNames = new List<string>(); | ||
88 | |||
89 | DataTable schemaTable = result.GetSchemaTable(); | ||
90 | foreach (DataRow row in schemaTable.Rows) | ||
91 | m_ColumnNames.Add(row["ColumnName"].ToString()); | ||
92 | } | ||
93 | |||
94 | foreach (string s in m_ColumnNames) | ||
95 | { | ||
96 | if (s == "UUID"||s == "uuid") | ||
97 | continue; | ||
98 | |||
99 | ret.Data[s] = result[s].ToString(); | ||
100 | } | ||
101 | return ret; | ||
102 | } | ||
103 | } | ||
104 | } | ||
105 | return null; | ||
106 | } | ||
107 | |||
108 | public bool Store(AuthenticationData data) | ||
109 | { | ||
110 | if (data.Data.ContainsKey("UUID")) | ||
111 | data.Data.Remove("UUID"); | ||
112 | if (data.Data.ContainsKey("uuid")) | ||
113 | data.Data.Remove("uuid"); | ||
114 | |||
115 | /* | ||
116 | Dictionary<string, object> oAuth = new Dictionary<string, object>(); | ||
117 | |||
118 | foreach (KeyValuePair<string, object> oDado in data.Data) | ||
119 | { | ||
120 | if (oDado.Key != oDado.Key.ToLower()) | ||
121 | { | ||
122 | oAuth.Add(oDado.Key.ToLower(), oDado.Value); | ||
123 | } | ||
124 | } | ||
125 | foreach (KeyValuePair<string, object> oDado in data.Data) | ||
126 | { | ||
127 | if (!oAuth.ContainsKey(oDado.Key.ToLower())) { | ||
128 | oAuth.Add(oDado.Key.ToLower(), oDado.Value); | ||
129 | } | ||
130 | } | ||
131 | */ | ||
132 | string[] fields = new List<string>(data.Data.Keys).ToArray(); | ||
133 | StringBuilder updateBuilder = new StringBuilder(); | ||
134 | |||
135 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
136 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
137 | { | ||
138 | updateBuilder.AppendFormat("update {0} set ", m_Realm); | ||
139 | |||
140 | bool first = true; | ||
141 | foreach (string field in fields) | ||
142 | { | ||
143 | if (!first) | ||
144 | updateBuilder.Append(", "); | ||
145 | updateBuilder.AppendFormat("\"{0}\" = :{0}",field); | ||
146 | |||
147 | first = false; | ||
148 | |||
149 | cmd.Parameters.Add(m_database.CreateParameter("" + field, data.Data[field])); | ||
150 | } | ||
151 | |||
152 | updateBuilder.Append(" where uuid = :principalID"); | ||
153 | |||
154 | cmd.CommandText = updateBuilder.ToString(); | ||
155 | cmd.Connection = conn; | ||
156 | cmd.Parameters.Add(m_database.CreateParameter("principalID", data.PrincipalID)); | ||
157 | |||
158 | conn.Open(); | ||
159 | if (cmd.ExecuteNonQuery() < 1) | ||
160 | { | ||
161 | StringBuilder insertBuilder = new StringBuilder(); | ||
162 | |||
163 | insertBuilder.AppendFormat("insert into {0} (uuid, \"", m_Realm); | ||
164 | insertBuilder.Append(String.Join("\", \"", fields)); | ||
165 | insertBuilder.Append("\") values (:principalID, :"); | ||
166 | insertBuilder.Append(String.Join(", :", fields)); | ||
167 | insertBuilder.Append(")"); | ||
168 | |||
169 | cmd.CommandText = insertBuilder.ToString(); | ||
170 | |||
171 | if (cmd.ExecuteNonQuery() < 1) | ||
172 | { | ||
173 | return false; | ||
174 | } | ||
175 | } | ||
176 | } | ||
177 | return true; | ||
178 | } | ||
179 | |||
180 | public bool SetDataItem(UUID principalID, string item, string value) | ||
181 | { | ||
182 | string sql = string.Format("update {0} set {1} = :{1} where uuid = :UUID", m_Realm, item); | ||
183 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
184 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
185 | { | ||
186 | cmd.Parameters.Add(m_database.CreateParameter("" + item, value)); | ||
187 | conn.Open(); | ||
188 | if (cmd.ExecuteNonQuery() > 0) | ||
189 | return true; | ||
190 | } | ||
191 | return false; | ||
192 | } | ||
193 | |||
194 | public bool SetToken(UUID principalID, string token, int lifetime) | ||
195 | { | ||
196 | if (System.Environment.TickCount - m_LastExpire > 30000) | ||
197 | DoExpire(); | ||
198 | |||
199 | string sql = "insert into tokens (uuid, token, validity) values (:principalID, :token, :lifetime)"; | ||
200 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
201 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
202 | { | ||
203 | cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); | ||
204 | cmd.Parameters.Add(m_database.CreateParameter("token", token)); | ||
205 | cmd.Parameters.Add(m_database.CreateParameter("lifetime", DateTime.Now.AddMinutes(lifetime))); | ||
206 | conn.Open(); | ||
207 | |||
208 | if (cmd.ExecuteNonQuery() > 0) | ||
209 | { | ||
210 | return true; | ||
211 | } | ||
212 | } | ||
213 | return false; | ||
214 | } | ||
215 | |||
216 | public bool CheckToken(UUID principalID, string token, int lifetime) | ||
217 | { | ||
218 | if (System.Environment.TickCount - m_LastExpire > 30000) | ||
219 | DoExpire(); | ||
220 | |||
221 | DateTime validDate = DateTime.Now.AddMinutes(lifetime); | ||
222 | string sql = "update tokens set validity = :validDate where uuid = :principalID and token = :token and validity > (CURRENT_DATE + CURRENT_TIME)"; | ||
223 | |||
224 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
225 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
226 | { | ||
227 | cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); | ||
228 | cmd.Parameters.Add(m_database.CreateParameter("token", token)); | ||
229 | cmd.Parameters.Add(m_database.CreateParameter("validDate", validDate)); | ||
230 | conn.Open(); | ||
231 | |||
232 | if (cmd.ExecuteNonQuery() > 0) | ||
233 | { | ||
234 | return true; | ||
235 | } | ||
236 | } | ||
237 | return false; | ||
238 | } | ||
239 | |||
240 | private void DoExpire() | ||
241 | { | ||
242 | DateTime currentDateTime = DateTime.Now; | ||
243 | string sql = "delete from tokens where validity < :currentDateTime"; | ||
244 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
245 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
246 | { | ||
247 | conn.Open(); | ||
248 | cmd.Parameters.Add(m_database.CreateParameter("currentDateTime", currentDateTime)); | ||
249 | cmd.ExecuteNonQuery(); | ||
250 | } | ||
251 | m_LastExpire = System.Environment.TickCount; | ||
252 | } | ||
253 | } | ||
254 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLAvatarData.cs b/OpenSim/Data/PGSQL/PGSQLAvatarData.cs new file mode 100644 index 0000000..d9c4905 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLAvatarData.cs | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using System.Threading; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using Npgsql; | ||
36 | using NpgsqlTypes; | ||
37 | |||
38 | |||
39 | namespace OpenSim.Data.PGSQL | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// A PGSQL Interface for Avatar Storage | ||
43 | /// </summary> | ||
44 | public class PGSQLAvatarData : PGSQLGenericTableHandler<AvatarBaseData>, | ||
45 | IAvatarData | ||
46 | { | ||
47 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
48 | |||
49 | public PGSQLAvatarData(string connectionString, string realm) : | ||
50 | base(connectionString, realm, "Avatar") | ||
51 | { | ||
52 | } | ||
53 | |||
54 | public bool Delete(UUID principalID, string name) | ||
55 | { | ||
56 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
57 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
58 | { | ||
59 | |||
60 | cmd.CommandText = String.Format("DELETE FROM {0} where \"PrincipalID\" = :PrincipalID and \"Name\" = :Name", m_Realm); | ||
61 | cmd.Parameters.Add(m_database.CreateParameter("PrincipalID", principalID)); | ||
62 | cmd.Parameters.Add(m_database.CreateParameter("Name", name)); | ||
63 | cmd.Connection = conn; | ||
64 | conn.Open(); | ||
65 | if (cmd.ExecuteNonQuery() > 0) | ||
66 | return true; | ||
67 | |||
68 | return false; | ||
69 | } | ||
70 | } | ||
71 | } | ||
72 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLEstateData.cs b/OpenSim/Data/PGSQL/PGSQLEstateData.cs new file mode 100644 index 0000000..b5ca235 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLEstateData.cs | |||
@@ -0,0 +1,602 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Reflection; | ||
31 | using log4net; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using OpenSim.Region.Framework.Interfaces; | ||
35 | using System.Data; | ||
36 | using Npgsql; | ||
37 | using NpgsqlTypes; | ||
38 | |||
39 | namespace OpenSim.Data.PGSQL | ||
40 | { | ||
41 | public class PGSQLEstateStore : IEstateDataStore | ||
42 | { | ||
43 | private const string _migrationStore = "EstateStore"; | ||
44 | |||
45 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private PGSQLManager _Database; | ||
48 | private string m_connectionString; | ||
49 | private FieldInfo[] _Fields; | ||
50 | private Dictionary<string, FieldInfo> _FieldMap = new Dictionary<string, FieldInfo>(); | ||
51 | |||
52 | #region Public methods | ||
53 | |||
54 | public PGSQLEstateStore() | ||
55 | { | ||
56 | } | ||
57 | |||
58 | public PGSQLEstateStore(string connectionString) | ||
59 | { | ||
60 | Initialise(connectionString); | ||
61 | } | ||
62 | |||
63 | protected virtual Assembly Assembly | ||
64 | { | ||
65 | get { return GetType().Assembly; } | ||
66 | } | ||
67 | |||
68 | /// <summary> | ||
69 | /// Initialises the estatedata class. | ||
70 | /// </summary> | ||
71 | /// <param name="connectionString">connectionString.</param> | ||
72 | public void Initialise(string connectionString) | ||
73 | { | ||
74 | if (!string.IsNullOrEmpty(connectionString)) | ||
75 | { | ||
76 | m_connectionString = connectionString; | ||
77 | _Database = new PGSQLManager(connectionString); | ||
78 | } | ||
79 | |||
80 | //Migration settings | ||
81 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
82 | { | ||
83 | conn.Open(); | ||
84 | Migration m = new Migration(conn, GetType().Assembly, "EstateStore"); | ||
85 | m.Update(); | ||
86 | } | ||
87 | |||
88 | //Interesting way to get parameters! Maybe implement that also with other types | ||
89 | Type t = typeof(EstateSettings); | ||
90 | _Fields = t.GetFields(BindingFlags.NonPublic | | ||
91 | BindingFlags.Instance | | ||
92 | BindingFlags.DeclaredOnly); | ||
93 | |||
94 | foreach (FieldInfo f in _Fields) | ||
95 | { | ||
96 | if (f.Name.Substring(0, 2) == "m_") | ||
97 | _FieldMap[f.Name.Substring(2)] = f; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | /// <summary> | ||
102 | /// Loads the estate settings. | ||
103 | /// </summary> | ||
104 | /// <param name="regionID">region ID.</param> | ||
105 | /// <returns></returns> | ||
106 | public EstateSettings LoadEstateSettings(UUID regionID, bool create) | ||
107 | { | ||
108 | EstateSettings es = new EstateSettings(); | ||
109 | |||
110 | string sql = "select estate_settings.\"" + String.Join("\",estate_settings.\"", FieldList) + | ||
111 | "\" from estate_map left join estate_settings on estate_map.\"EstateID\" = estate_settings.\"EstateID\" " + | ||
112 | " where estate_settings.\"EstateID\" is not null and \"RegionID\" = :RegionID"; | ||
113 | |||
114 | bool insertEstate = false; | ||
115 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
116 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
117 | { | ||
118 | cmd.Parameters.Add(_Database.CreateParameter("RegionID", regionID)); | ||
119 | conn.Open(); | ||
120 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
121 | { | ||
122 | if (reader.Read()) | ||
123 | { | ||
124 | foreach (string name in FieldList) | ||
125 | { | ||
126 | FieldInfo f = _FieldMap[name]; | ||
127 | object v = reader[name]; | ||
128 | if (f.FieldType == typeof(bool)) | ||
129 | { | ||
130 | f.SetValue(es, v); | ||
131 | } | ||
132 | else if (f.FieldType == typeof(UUID)) | ||
133 | { | ||
134 | UUID estUUID = UUID.Zero; | ||
135 | |||
136 | UUID.TryParse(v.ToString(), out estUUID); | ||
137 | |||
138 | f.SetValue(es, estUUID); | ||
139 | } | ||
140 | else if (f.FieldType == typeof(string)) | ||
141 | { | ||
142 | f.SetValue(es, v.ToString()); | ||
143 | } | ||
144 | else if (f.FieldType == typeof(UInt32)) | ||
145 | { | ||
146 | f.SetValue(es, Convert.ToUInt32(v)); | ||
147 | } | ||
148 | else if (f.FieldType == typeof(Single)) | ||
149 | { | ||
150 | f.SetValue(es, Convert.ToSingle(v)); | ||
151 | } | ||
152 | else | ||
153 | f.SetValue(es, v); | ||
154 | } | ||
155 | } | ||
156 | else | ||
157 | { | ||
158 | insertEstate = true; | ||
159 | } | ||
160 | } | ||
161 | } | ||
162 | |||
163 | if (insertEstate && create) | ||
164 | { | ||
165 | DoCreate(es); | ||
166 | LinkRegion(regionID, (int)es.EstateID); | ||
167 | } | ||
168 | |||
169 | LoadBanList(es); | ||
170 | |||
171 | es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); | ||
172 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); | ||
173 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | ||
174 | |||
175 | //Set event | ||
176 | es.OnSave += StoreEstateSettings; | ||
177 | return es; | ||
178 | } | ||
179 | |||
180 | public EstateSettings CreateNewEstate() | ||
181 | { | ||
182 | EstateSettings es = new EstateSettings(); | ||
183 | es.OnSave += StoreEstateSettings; | ||
184 | |||
185 | DoCreate(es); | ||
186 | |||
187 | LoadBanList(es); | ||
188 | |||
189 | es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); | ||
190 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); | ||
191 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | ||
192 | |||
193 | return es; | ||
194 | } | ||
195 | |||
196 | private void DoCreate(EstateSettings es) | ||
197 | { | ||
198 | List<string> names = new List<string>(FieldList); | ||
199 | |||
200 | names.Remove("EstateID"); | ||
201 | |||
202 | string sql = string.Format("insert into estate_settings (\"{0}\") values ( :{1} )", String.Join("\",\"", names.ToArray()), String.Join(", :", names.ToArray())); | ||
203 | |||
204 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
205 | using (NpgsqlCommand insertCommand = new NpgsqlCommand(sql, conn)) | ||
206 | { | ||
207 | insertCommand.CommandText = sql; | ||
208 | |||
209 | foreach (string name in names) | ||
210 | { | ||
211 | insertCommand.Parameters.Add(_Database.CreateParameter("" + name, _FieldMap[name].GetValue(es))); | ||
212 | } | ||
213 | //NpgsqlParameter idParameter = new NpgsqlParameter("ID", SqlDbType.Int); | ||
214 | //idParameter.Direction = ParameterDirection.Output; | ||
215 | //insertCommand.Parameters.Add(idParameter); | ||
216 | conn.Open(); | ||
217 | |||
218 | es.EstateID = 100; | ||
219 | |||
220 | if (insertCommand.ExecuteNonQuery() > 0) | ||
221 | { | ||
222 | insertCommand.CommandText = "Select cast(lastval() as int) as ID ;"; | ||
223 | |||
224 | using (NpgsqlDataReader result = insertCommand.ExecuteReader()) | ||
225 | { | ||
226 | if (result.Read()) | ||
227 | { | ||
228 | es.EstateID = (uint)result.GetInt32(0); | ||
229 | } | ||
230 | } | ||
231 | } | ||
232 | |||
233 | } | ||
234 | |||
235 | //TODO check if this is needed?? | ||
236 | es.Save(); | ||
237 | } | ||
238 | |||
239 | /// <summary> | ||
240 | /// Stores the estate settings. | ||
241 | /// </summary> | ||
242 | /// <param name="es">estate settings</param> | ||
243 | public void StoreEstateSettings(EstateSettings es) | ||
244 | { | ||
245 | List<string> names = new List<string>(FieldList); | ||
246 | |||
247 | names.Remove("EstateID"); | ||
248 | |||
249 | string sql = string.Format("UPDATE estate_settings SET "); | ||
250 | foreach (string name in names) | ||
251 | { | ||
252 | sql += "\"" + name + "\" = :" + name + ", "; | ||
253 | } | ||
254 | sql = sql.Remove(sql.LastIndexOf(",")); | ||
255 | sql += " WHERE \"EstateID\" = :EstateID"; | ||
256 | |||
257 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
258 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
259 | { | ||
260 | foreach (string name in names) | ||
261 | { | ||
262 | cmd.Parameters.Add(_Database.CreateParameter("" + name, _FieldMap[name].GetValue(es))); | ||
263 | } | ||
264 | |||
265 | cmd.Parameters.Add(_Database.CreateParameter("EstateID", es.EstateID)); | ||
266 | conn.Open(); | ||
267 | cmd.ExecuteNonQuery(); | ||
268 | } | ||
269 | |||
270 | SaveBanList(es); | ||
271 | SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers); | ||
272 | SaveUUIDList(es.EstateID, "estate_users", es.EstateAccess); | ||
273 | SaveUUIDList(es.EstateID, "estate_groups", es.EstateGroups); | ||
274 | } | ||
275 | |||
276 | #endregion | ||
277 | |||
278 | #region Private methods | ||
279 | |||
280 | private string[] FieldList | ||
281 | { | ||
282 | get { return new List<string>(_FieldMap.Keys).ToArray(); } | ||
283 | } | ||
284 | |||
285 | private void LoadBanList(EstateSettings es) | ||
286 | { | ||
287 | es.ClearBans(); | ||
288 | |||
289 | string sql = "select \"bannedUUID\" from estateban where \"EstateID\" = :EstateID"; | ||
290 | |||
291 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
292 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
293 | { | ||
294 | NpgsqlParameter idParameter = new NpgsqlParameter("EstateID", DbType.Int32); | ||
295 | idParameter.Value = es.EstateID; | ||
296 | cmd.Parameters.Add(idParameter); | ||
297 | conn.Open(); | ||
298 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
299 | { | ||
300 | while (reader.Read()) | ||
301 | { | ||
302 | EstateBan eb = new EstateBan(); | ||
303 | |||
304 | eb.BannedUserID = new UUID((Guid)reader["bannedUUID"]); //uuid; | ||
305 | eb.BannedHostAddress = "0.0.0.0"; | ||
306 | eb.BannedHostIPMask = "0.0.0.0"; | ||
307 | es.AddBan(eb); | ||
308 | } | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | |||
313 | private UUID[] LoadUUIDList(uint estateID, string table) | ||
314 | { | ||
315 | List<UUID> uuids = new List<UUID>(); | ||
316 | |||
317 | string sql = string.Format("select uuid from {0} where \"EstateID\" = :EstateID", table); | ||
318 | |||
319 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
320 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
321 | { | ||
322 | cmd.Parameters.Add(_Database.CreateParameter("EstateID", estateID)); | ||
323 | conn.Open(); | ||
324 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
325 | { | ||
326 | while (reader.Read()) | ||
327 | { | ||
328 | uuids.Add(new UUID((Guid)reader["uuid"])); //uuid); | ||
329 | } | ||
330 | } | ||
331 | } | ||
332 | |||
333 | return uuids.ToArray(); | ||
334 | } | ||
335 | |||
336 | private void SaveBanList(EstateSettings es) | ||
337 | { | ||
338 | //Delete first | ||
339 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
340 | { | ||
341 | conn.Open(); | ||
342 | using (NpgsqlCommand cmd = conn.CreateCommand()) | ||
343 | { | ||
344 | cmd.CommandText = "delete from estateban where \"EstateID\" = :EstateID"; | ||
345 | cmd.Parameters.AddWithValue("EstateID", (int)es.EstateID); | ||
346 | cmd.ExecuteNonQuery(); | ||
347 | |||
348 | //Insert after | ||
349 | cmd.CommandText = "insert into estateban (\"EstateID\", \"bannedUUID\",\"bannedIp\", \"bannedIpHostMask\", \"bannedNameMask\") values ( :EstateID, :bannedUUID, '','','' )"; | ||
350 | cmd.Parameters.AddWithValue("bannedUUID", Guid.Empty); | ||
351 | foreach (EstateBan b in es.EstateBans) | ||
352 | { | ||
353 | cmd.Parameters["bannedUUID"].Value = b.BannedUserID.Guid; | ||
354 | cmd.ExecuteNonQuery(); | ||
355 | } | ||
356 | } | ||
357 | } | ||
358 | } | ||
359 | |||
360 | private void SaveUUIDList(uint estateID, string table, UUID[] data) | ||
361 | { | ||
362 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
363 | { | ||
364 | conn.Open(); | ||
365 | using (NpgsqlCommand cmd = conn.CreateCommand()) | ||
366 | { | ||
367 | cmd.Parameters.AddWithValue("EstateID", (int)estateID); | ||
368 | cmd.CommandText = string.Format("delete from {0} where \"EstateID\" = :EstateID", table); | ||
369 | cmd.ExecuteNonQuery(); | ||
370 | |||
371 | cmd.CommandText = string.Format("insert into {0} (\"EstateID\", uuid) values ( :EstateID, :uuid )", table); | ||
372 | cmd.Parameters.AddWithValue("uuid", Guid.Empty); | ||
373 | foreach (UUID uuid in data) | ||
374 | { | ||
375 | cmd.Parameters["uuid"].Value = uuid.Guid; //.ToString(); //TODO check if this works | ||
376 | cmd.ExecuteNonQuery(); | ||
377 | } | ||
378 | } | ||
379 | } | ||
380 | } | ||
381 | |||
382 | public EstateSettings LoadEstateSettings(int estateID) | ||
383 | { | ||
384 | EstateSettings es = new EstateSettings(); | ||
385 | string sql = "select estate_settings.\"" + String.Join("\",estate_settings.\"", FieldList) + "\" from estate_settings where \"EstateID\" = :EstateID"; | ||
386 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
387 | { | ||
388 | conn.Open(); | ||
389 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
390 | { | ||
391 | cmd.Parameters.AddWithValue("EstateID", (int)estateID); | ||
392 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
393 | { | ||
394 | if (reader.Read()) | ||
395 | { | ||
396 | foreach (string name in FieldList) | ||
397 | { | ||
398 | FieldInfo f = _FieldMap[name]; | ||
399 | object v = reader[name]; | ||
400 | if (f.FieldType == typeof(bool)) | ||
401 | { | ||
402 | f.SetValue(es, Convert.ToInt32(v) != 0); | ||
403 | } | ||
404 | else if (f.FieldType == typeof(UUID)) | ||
405 | { | ||
406 | f.SetValue(es, new UUID((Guid)v)); // uuid); | ||
407 | } | ||
408 | else if (f.FieldType == typeof(string)) | ||
409 | { | ||
410 | f.SetValue(es, v.ToString()); | ||
411 | } | ||
412 | else if (f.FieldType == typeof(UInt32)) | ||
413 | { | ||
414 | f.SetValue(es, Convert.ToUInt32(v)); | ||
415 | } | ||
416 | else if (f.FieldType == typeof(Single)) | ||
417 | { | ||
418 | f.SetValue(es, Convert.ToSingle(v)); | ||
419 | } | ||
420 | else | ||
421 | f.SetValue(es, v); | ||
422 | } | ||
423 | } | ||
424 | |||
425 | } | ||
426 | } | ||
427 | } | ||
428 | LoadBanList(es); | ||
429 | |||
430 | es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); | ||
431 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); | ||
432 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | ||
433 | |||
434 | //Set event | ||
435 | es.OnSave += StoreEstateSettings; | ||
436 | return es; | ||
437 | |||
438 | } | ||
439 | |||
440 | public List<EstateSettings> LoadEstateSettingsAll() | ||
441 | { | ||
442 | List<EstateSettings> allEstateSettings = new List<EstateSettings>(); | ||
443 | |||
444 | List<int> allEstateIds = GetEstatesAll(); | ||
445 | |||
446 | foreach (int estateId in allEstateIds) | ||
447 | allEstateSettings.Add(LoadEstateSettings(estateId)); | ||
448 | |||
449 | return allEstateSettings; | ||
450 | } | ||
451 | |||
452 | public List<int> GetEstates(string search) | ||
453 | { | ||
454 | List<int> result = new List<int>(); | ||
455 | string sql = "select \"EstateID\" from estate_settings where lower(\"EstateName\") = lower(:EstateName)"; | ||
456 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
457 | { | ||
458 | conn.Open(); | ||
459 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
460 | { | ||
461 | cmd.Parameters.AddWithValue("EstateName", search); | ||
462 | |||
463 | using (IDataReader reader = cmd.ExecuteReader()) | ||
464 | { | ||
465 | while (reader.Read()) | ||
466 | { | ||
467 | result.Add(Convert.ToInt32(reader["EstateID"])); | ||
468 | } | ||
469 | reader.Close(); | ||
470 | } | ||
471 | } | ||
472 | } | ||
473 | |||
474 | return result; | ||
475 | } | ||
476 | |||
477 | public List<int> GetEstatesAll() | ||
478 | { | ||
479 | List<int> result = new List<int>(); | ||
480 | string sql = "select \"EstateID\" from estate_settings"; | ||
481 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
482 | { | ||
483 | conn.Open(); | ||
484 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
485 | { | ||
486 | using (IDataReader reader = cmd.ExecuteReader()) | ||
487 | { | ||
488 | while (reader.Read()) | ||
489 | { | ||
490 | result.Add(Convert.ToInt32(reader["EstateID"])); | ||
491 | } | ||
492 | reader.Close(); | ||
493 | } | ||
494 | } | ||
495 | } | ||
496 | |||
497 | return result; | ||
498 | } | ||
499 | |||
500 | public List<int> GetEstatesByOwner(UUID ownerID) | ||
501 | { | ||
502 | List<int> result = new List<int>(); | ||
503 | string sql = "select \"EstateID\" from estate_settings where \"EstateOwner\" = :EstateOwner"; | ||
504 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
505 | { | ||
506 | conn.Open(); | ||
507 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
508 | { | ||
509 | cmd.Parameters.AddWithValue("EstateOwner", ownerID); | ||
510 | |||
511 | using (IDataReader reader = cmd.ExecuteReader()) | ||
512 | { | ||
513 | while (reader.Read()) | ||
514 | { | ||
515 | result.Add(Convert.ToInt32(reader["EstateID"])); | ||
516 | } | ||
517 | reader.Close(); | ||
518 | } | ||
519 | } | ||
520 | } | ||
521 | |||
522 | return result; | ||
523 | } | ||
524 | |||
525 | public bool LinkRegion(UUID regionID, int estateID) | ||
526 | { | ||
527 | string deleteSQL = "delete from estate_map where \"RegionID\" = :RegionID"; | ||
528 | string insertSQL = "insert into estate_map values (:RegionID, :EstateID)"; | ||
529 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
530 | { | ||
531 | conn.Open(); | ||
532 | |||
533 | NpgsqlTransaction transaction = conn.BeginTransaction(); | ||
534 | |||
535 | try | ||
536 | { | ||
537 | using (NpgsqlCommand cmd = new NpgsqlCommand(deleteSQL, conn)) | ||
538 | { | ||
539 | cmd.Transaction = transaction; | ||
540 | cmd.Parameters.AddWithValue("RegionID", regionID.Guid); | ||
541 | |||
542 | cmd.ExecuteNonQuery(); | ||
543 | } | ||
544 | |||
545 | using (NpgsqlCommand cmd = new NpgsqlCommand(insertSQL, conn)) | ||
546 | { | ||
547 | cmd.Transaction = transaction; | ||
548 | cmd.Parameters.AddWithValue("RegionID", regionID.Guid); | ||
549 | cmd.Parameters.AddWithValue("EstateID", estateID); | ||
550 | |||
551 | int ret = cmd.ExecuteNonQuery(); | ||
552 | |||
553 | if (ret != 0) | ||
554 | transaction.Commit(); | ||
555 | else | ||
556 | transaction.Rollback(); | ||
557 | |||
558 | return (ret != 0); | ||
559 | } | ||
560 | } | ||
561 | catch (Exception ex) | ||
562 | { | ||
563 | m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message); | ||
564 | transaction.Rollback(); | ||
565 | } | ||
566 | } | ||
567 | return false; | ||
568 | } | ||
569 | |||
570 | public List<UUID> GetRegions(int estateID) | ||
571 | { | ||
572 | List<UUID> result = new List<UUID>(); | ||
573 | string sql = "select \"RegionID\" from estate_map where \"EstateID\" = :EstateID"; | ||
574 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
575 | { | ||
576 | conn.Open(); | ||
577 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
578 | { | ||
579 | cmd.Parameters.AddWithValue("EstateID", estateID); | ||
580 | |||
581 | using (IDataReader reader = cmd.ExecuteReader()) | ||
582 | { | ||
583 | while (reader.Read()) | ||
584 | { | ||
585 | result.Add(DBGuid.FromDB(reader["RegionID"])); | ||
586 | } | ||
587 | reader.Close(); | ||
588 | } | ||
589 | } | ||
590 | } | ||
591 | |||
592 | return result; | ||
593 | } | ||
594 | |||
595 | public bool DeleteEstate(int estateID) | ||
596 | { | ||
597 | // TODO: Implementation! | ||
598 | return false; | ||
599 | } | ||
600 | #endregion | ||
601 | } | ||
602 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLFramework.cs b/OpenSim/Data/PGSQL/PGSQLFramework.cs new file mode 100644 index 0000000..1028e4e --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLFramework.cs | |||
@@ -0,0 +1,111 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using System.Reflection; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using Npgsql; | ||
36 | |||
37 | namespace OpenSim.Data.PGSQL | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A database interface class to a user profile storage system | ||
41 | /// </summary> | ||
42 | public class PGSqlFramework | ||
43 | { | ||
44 | private static readonly log4net.ILog m_log = | ||
45 | log4net.LogManager.GetLogger( | ||
46 | System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | protected string m_connectionString; | ||
49 | protected object m_dbLock = new object(); | ||
50 | |||
51 | protected PGSqlFramework(string connectionString) | ||
52 | { | ||
53 | m_connectionString = connectionString; | ||
54 | InitializeMonoSecurity(); | ||
55 | } | ||
56 | |||
57 | public void InitializeMonoSecurity() | ||
58 | { | ||
59 | if (!Util.IsPlatformMono) | ||
60 | { | ||
61 | |||
62 | if (AppDomain.CurrentDomain.GetData("MonoSecurityPostgresAdded") == null) | ||
63 | { | ||
64 | AppDomain.CurrentDomain.SetData("MonoSecurityPostgresAdded", "true"); | ||
65 | |||
66 | AppDomain currentDomain = AppDomain.CurrentDomain; | ||
67 | currentDomain.AssemblyResolve += new ResolveEventHandler(ResolveEventHandlerMonoSec); | ||
68 | } | ||
69 | } | ||
70 | } | ||
71 | |||
72 | private System.Reflection.Assembly ResolveEventHandlerMonoSec(object sender, ResolveEventArgs args) | ||
73 | { | ||
74 | Assembly MyAssembly = null; | ||
75 | |||
76 | if (args.Name.Substring(0, args.Name.IndexOf(",")) == "Mono.Security") | ||
77 | { | ||
78 | MyAssembly = Assembly.LoadFrom("lib/NET/Mono.Security.dll"); | ||
79 | } | ||
80 | |||
81 | //Return the loaded assembly. | ||
82 | return MyAssembly; | ||
83 | } | ||
84 | ////////////////////////////////////////////////////////////// | ||
85 | // | ||
86 | // All non queries are funneled through one connection | ||
87 | // to increase performance a little | ||
88 | // | ||
89 | protected int ExecuteNonQuery(NpgsqlCommand cmd) | ||
90 | { | ||
91 | lock (m_dbLock) | ||
92 | { | ||
93 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
94 | { | ||
95 | dbcon.Open(); | ||
96 | cmd.Connection = dbcon; | ||
97 | |||
98 | try | ||
99 | { | ||
100 | return cmd.ExecuteNonQuery(); | ||
101 | } | ||
102 | catch (Exception e) | ||
103 | { | ||
104 | m_log.Error(e.Message, e); | ||
105 | return 0; | ||
106 | } | ||
107 | } | ||
108 | } | ||
109 | } | ||
110 | } | ||
111 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLFriendsData.cs b/OpenSim/Data/PGSQL/PGSQLFriendsData.cs new file mode 100644 index 0000000..a841353 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLFriendsData.cs | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ''AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using System.Reflection; | ||
35 | using System.Text; | ||
36 | using Npgsql; | ||
37 | |||
38 | namespace OpenSim.Data.PGSQL | ||
39 | { | ||
40 | public class PGSQLFriendsData : PGSQLGenericTableHandler<FriendsData>, IFriendsData | ||
41 | { | ||
42 | public PGSQLFriendsData(string connectionString, string realm) | ||
43 | : base(connectionString, realm, "FriendsStore") | ||
44 | { | ||
45 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
46 | { | ||
47 | conn.Open(); | ||
48 | Migration m = new Migration(conn, GetType().Assembly, "FriendsStore"); | ||
49 | m.Update(); | ||
50 | } | ||
51 | } | ||
52 | |||
53 | |||
54 | public override bool Delete(string principalID, string friend) | ||
55 | { | ||
56 | UUID princUUID = UUID.Zero; | ||
57 | |||
58 | bool ret = UUID.TryParse(principalID, out princUUID); | ||
59 | |||
60 | if (ret) | ||
61 | return Delete(princUUID, friend); | ||
62 | else | ||
63 | return false; | ||
64 | } | ||
65 | |||
66 | public bool Delete(UUID principalID, string friend) | ||
67 | { | ||
68 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
69 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
70 | { | ||
71 | cmd.CommandText = String.Format("delete from {0} where \"PrincipalID\" = :PrincipalID and \"Friend\" = :Friend", m_Realm); | ||
72 | cmd.Parameters.Add(m_database.CreateParameter("PrincipalID", principalID.ToString())); | ||
73 | cmd.Parameters.Add(m_database.CreateParameter("Friend", friend)); | ||
74 | cmd.Connection = conn; | ||
75 | conn.Open(); | ||
76 | cmd.ExecuteNonQuery(); | ||
77 | |||
78 | return true; | ||
79 | } | ||
80 | } | ||
81 | |||
82 | public FriendsData[] GetFriends(string principalID) | ||
83 | { | ||
84 | UUID princUUID = UUID.Zero; | ||
85 | |||
86 | bool ret = UUID.TryParse(principalID, out princUUID); | ||
87 | |||
88 | if (ret) | ||
89 | return GetFriends(princUUID); | ||
90 | else | ||
91 | return new FriendsData[0]; | ||
92 | } | ||
93 | |||
94 | public FriendsData[] GetFriends(UUID principalID) | ||
95 | { | ||
96 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
97 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
98 | { | ||
99 | |||
100 | cmd.CommandText = String.Format("select a.*,case when b.\"Flags\" is null then '-1' else b.\"Flags\" end as \"TheirFlags\" from {0} as a " + | ||
101 | " left join {0} as b on a.\"PrincipalID\" = b.\"Friend\" and a.\"Friend\" = b.\"PrincipalID\" " + | ||
102 | " where a.\"PrincipalID\" = :PrincipalID", m_Realm); | ||
103 | cmd.Parameters.Add(m_database.CreateParameter("PrincipalID", principalID.ToString())); | ||
104 | cmd.Connection = conn; | ||
105 | conn.Open(); | ||
106 | return DoQuery(cmd); | ||
107 | } | ||
108 | } | ||
109 | |||
110 | public FriendsData[] GetFriends(Guid principalID) | ||
111 | { | ||
112 | return GetFriends(principalID); | ||
113 | } | ||
114 | |||
115 | } | ||
116 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs new file mode 100644 index 0000000..826c6fc --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLGenericTableHandler.cs | |||
@@ -0,0 +1,537 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using OpenSim.Region.Framework.Interfaces; | ||
36 | using System.Text; | ||
37 | using Npgsql; | ||
38 | |||
39 | namespace OpenSim.Data.PGSQL | ||
40 | { | ||
41 | public class PGSQLGenericTableHandler<T> : PGSqlFramework where T : class, new() | ||
42 | { | ||
43 | private static readonly ILog m_log = | ||
44 | LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
45 | |||
46 | protected string m_ConnectionString; | ||
47 | protected PGSQLManager m_database; //used for parameter type translation | ||
48 | protected Dictionary<string, FieldInfo> m_Fields = | ||
49 | new Dictionary<string, FieldInfo>(); | ||
50 | |||
51 | protected Dictionary<string, string> m_FieldTypes = new Dictionary<string, string>(); | ||
52 | |||
53 | protected List<string> m_ColumnNames = null; | ||
54 | protected string m_Realm; | ||
55 | protected FieldInfo m_DataField = null; | ||
56 | |||
57 | protected virtual Assembly Assembly | ||
58 | { | ||
59 | get { return GetType().Assembly; } | ||
60 | } | ||
61 | |||
62 | public PGSQLGenericTableHandler(string connectionString, | ||
63 | string realm, string storeName) | ||
64 | : base(connectionString) | ||
65 | { | ||
66 | m_Realm = realm; | ||
67 | |||
68 | m_ConnectionString = connectionString; | ||
69 | |||
70 | if (storeName != String.Empty) | ||
71 | { | ||
72 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
73 | { | ||
74 | conn.Open(); | ||
75 | Migration m = new Migration(conn, GetType().Assembly, storeName); | ||
76 | m.Update(); | ||
77 | } | ||
78 | |||
79 | } | ||
80 | m_database = new PGSQLManager(m_ConnectionString); | ||
81 | |||
82 | Type t = typeof(T); | ||
83 | FieldInfo[] fields = t.GetFields(BindingFlags.Public | | ||
84 | BindingFlags.Instance | | ||
85 | BindingFlags.DeclaredOnly); | ||
86 | |||
87 | LoadFieldTypes(); | ||
88 | |||
89 | if (fields.Length == 0) | ||
90 | return; | ||
91 | |||
92 | foreach (FieldInfo f in fields) | ||
93 | { | ||
94 | if (f.Name != "Data") | ||
95 | m_Fields[f.Name] = f; | ||
96 | else | ||
97 | m_DataField = f; | ||
98 | } | ||
99 | |||
100 | } | ||
101 | |||
102 | private void LoadFieldTypes() | ||
103 | { | ||
104 | m_FieldTypes = new Dictionary<string, string>(); | ||
105 | |||
106 | string query = string.Format(@"select column_name,data_type | ||
107 | from INFORMATION_SCHEMA.COLUMNS | ||
108 | where table_name = lower('{0}'); | ||
109 | |||
110 | ", m_Realm); | ||
111 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
112 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn)) | ||
113 | { | ||
114 | conn.Open(); | ||
115 | using (NpgsqlDataReader rdr = cmd.ExecuteReader()) | ||
116 | { | ||
117 | while (rdr.Read()) | ||
118 | { | ||
119 | // query produces 0 to many rows of single column, so always add the first item in each row | ||
120 | m_FieldTypes.Add((string)rdr[0], (string)rdr[1]); | ||
121 | } | ||
122 | } | ||
123 | } | ||
124 | } | ||
125 | |||
126 | private void CheckColumnNames(NpgsqlDataReader reader) | ||
127 | { | ||
128 | if (m_ColumnNames != null) | ||
129 | return; | ||
130 | |||
131 | m_ColumnNames = new List<string>(); | ||
132 | |||
133 | DataTable schemaTable = reader.GetSchemaTable(); | ||
134 | |||
135 | foreach (DataRow row in schemaTable.Rows) | ||
136 | { | ||
137 | if (row["ColumnName"] != null && | ||
138 | (!m_Fields.ContainsKey(row["ColumnName"].ToString()))) | ||
139 | m_ColumnNames.Add(row["ColumnName"].ToString()); | ||
140 | |||
141 | } | ||
142 | } | ||
143 | |||
144 | // TODO GET CONSTRAINTS FROM POSTGRESQL | ||
145 | private List<string> GetConstraints() | ||
146 | { | ||
147 | List<string> constraints = new List<string>(); | ||
148 | string query = string.Format(@"SELECT kcu.column_name | ||
149 | FROM information_schema.table_constraints tc | ||
150 | LEFT JOIN information_schema.key_column_usage kcu | ||
151 | ON tc.constraint_catalog = kcu.constraint_catalog | ||
152 | AND tc.constraint_schema = kcu.constraint_schema | ||
153 | AND tc.constraint_name = kcu.constraint_name | ||
154 | |||
155 | LEFT JOIN information_schema.referential_constraints rc | ||
156 | ON tc.constraint_catalog = rc.constraint_catalog | ||
157 | AND tc.constraint_schema = rc.constraint_schema | ||
158 | AND tc.constraint_name = rc.constraint_name | ||
159 | |||
160 | LEFT JOIN information_schema.constraint_column_usage ccu | ||
161 | ON rc.unique_constraint_catalog = ccu.constraint_catalog | ||
162 | AND rc.unique_constraint_schema = ccu.constraint_schema | ||
163 | AND rc.unique_constraint_name = ccu.constraint_name | ||
164 | |||
165 | where tc.table_name = lower('{0}') | ||
166 | and lower(tc.constraint_type) in ('primary key') | ||
167 | and kcu.column_name is not null | ||
168 | ;", m_Realm); | ||
169 | |||
170 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
171 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn)) | ||
172 | { | ||
173 | conn.Open(); | ||
174 | using (NpgsqlDataReader rdr = cmd.ExecuteReader()) | ||
175 | { | ||
176 | while (rdr.Read()) | ||
177 | { | ||
178 | // query produces 0 to many rows of single column, so always add the first item in each row | ||
179 | constraints.Add((string)rdr[0]); | ||
180 | } | ||
181 | } | ||
182 | return constraints; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | public virtual T[] Get(string field, string key) | ||
187 | { | ||
188 | return Get(new string[] { field }, new string[] { key }); | ||
189 | } | ||
190 | |||
191 | public virtual T[] Get(string[] fields, string[] keys) | ||
192 | { | ||
193 | if (fields.Length != keys.Length) | ||
194 | return new T[0]; | ||
195 | |||
196 | List<string> terms = new List<string>(); | ||
197 | |||
198 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
199 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
200 | { | ||
201 | |||
202 | for (int i = 0; i < fields.Length; i++) | ||
203 | { | ||
204 | if ( m_FieldTypes.ContainsKey(fields[i]) ) | ||
205 | cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i], m_FieldTypes[fields[i]])); | ||
206 | else | ||
207 | cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i])); | ||
208 | |||
209 | terms.Add(" \"" + fields[i] + "\" = :" + fields[i]); | ||
210 | } | ||
211 | |||
212 | string where = String.Join(" AND ", terms.ToArray()); | ||
213 | |||
214 | string query = String.Format("SELECT * FROM {0} WHERE {1}", | ||
215 | m_Realm, where); | ||
216 | |||
217 | cmd.Connection = conn; | ||
218 | cmd.CommandText = query; | ||
219 | conn.Open(); | ||
220 | return DoQuery(cmd); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | protected T[] DoQuery(NpgsqlCommand cmd) | ||
225 | { | ||
226 | List<T> result = new List<T>(); | ||
227 | if (cmd.Connection == null) | ||
228 | { | ||
229 | cmd.Connection = new NpgsqlConnection(m_connectionString); | ||
230 | } | ||
231 | if (cmd.Connection.State == ConnectionState.Closed) | ||
232 | { | ||
233 | cmd.Connection.Open(); | ||
234 | } | ||
235 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
236 | { | ||
237 | if (reader == null) | ||
238 | return new T[0]; | ||
239 | |||
240 | CheckColumnNames(reader); | ||
241 | |||
242 | while (reader.Read()) | ||
243 | { | ||
244 | T row = new T(); | ||
245 | |||
246 | foreach (string name in m_Fields.Keys) | ||
247 | { | ||
248 | if (m_Fields[name].GetValue(row) is bool) | ||
249 | { | ||
250 | int v = Convert.ToInt32(reader[name]); | ||
251 | m_Fields[name].SetValue(row, v != 0 ? true : false); | ||
252 | } | ||
253 | else if (m_Fields[name].GetValue(row) is UUID) | ||
254 | { | ||
255 | UUID uuid = UUID.Zero; | ||
256 | |||
257 | UUID.TryParse(reader[name].ToString(), out uuid); | ||
258 | m_Fields[name].SetValue(row, uuid); | ||
259 | } | ||
260 | else if (m_Fields[name].GetValue(row) is int) | ||
261 | { | ||
262 | int v = Convert.ToInt32(reader[name]); | ||
263 | m_Fields[name].SetValue(row, v); | ||
264 | } | ||
265 | else | ||
266 | { | ||
267 | m_Fields[name].SetValue(row, reader[name]); | ||
268 | } | ||
269 | } | ||
270 | |||
271 | if (m_DataField != null) | ||
272 | { | ||
273 | Dictionary<string, string> data = | ||
274 | new Dictionary<string, string>(); | ||
275 | |||
276 | foreach (string col in m_ColumnNames) | ||
277 | { | ||
278 | data[col] = reader[col].ToString(); | ||
279 | |||
280 | if (data[col] == null) | ||
281 | data[col] = String.Empty; | ||
282 | } | ||
283 | |||
284 | m_DataField.SetValue(row, data); | ||
285 | } | ||
286 | |||
287 | result.Add(row); | ||
288 | } | ||
289 | return result.ToArray(); | ||
290 | } | ||
291 | } | ||
292 | |||
293 | public virtual T[] Get(string where) | ||
294 | { | ||
295 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
296 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
297 | { | ||
298 | |||
299 | string query = String.Format("SELECT * FROM {0} WHERE {1}", | ||
300 | m_Realm, where); | ||
301 | cmd.Connection = conn; | ||
302 | cmd.CommandText = query; | ||
303 | //m_log.WarnFormat("[PGSQLGenericTable]: SELECT {0} WHERE {1}", m_Realm, where); | ||
304 | |||
305 | conn.Open(); | ||
306 | return DoQuery(cmd); | ||
307 | } | ||
308 | } | ||
309 | |||
310 | public virtual T[] Get(string where, NpgsqlParameter parameter) | ||
311 | { | ||
312 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
313 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
314 | { | ||
315 | |||
316 | string query = String.Format("SELECT * FROM {0} WHERE {1}", | ||
317 | m_Realm, where); | ||
318 | cmd.Connection = conn; | ||
319 | cmd.CommandText = query; | ||
320 | //m_log.WarnFormat("[PGSQLGenericTable]: SELECT {0} WHERE {1}", m_Realm, where); | ||
321 | |||
322 | cmd.Parameters.Add(parameter); | ||
323 | |||
324 | conn.Open(); | ||
325 | return DoQuery(cmd); | ||
326 | } | ||
327 | } | ||
328 | |||
329 | public virtual bool Store(T row) | ||
330 | { | ||
331 | List<string> constraintFields = GetConstraints(); | ||
332 | List<KeyValuePair<string, string>> constraints = new List<KeyValuePair<string, string>>(); | ||
333 | |||
334 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
335 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
336 | { | ||
337 | |||
338 | StringBuilder query = new StringBuilder(); | ||
339 | List<String> names = new List<String>(); | ||
340 | List<String> values = new List<String>(); | ||
341 | |||
342 | foreach (FieldInfo fi in m_Fields.Values) | ||
343 | { | ||
344 | names.Add(fi.Name); | ||
345 | values.Add(":" + fi.Name); | ||
346 | // Temporarily return more information about what field is unexpectedly null for | ||
347 | // http://opensimulator.org/mantis/view.php?id=5403. This might be due to a bug in the | ||
348 | // InventoryTransferModule or we may be required to substitute a DBNull here. | ||
349 | if (fi.GetValue(row) == null) | ||
350 | throw new NullReferenceException( | ||
351 | string.Format( | ||
352 | "[PGSQL GENERIC TABLE HANDLER]: Trying to store field {0} for {1} which is unexpectedly null", | ||
353 | fi.Name, row)); | ||
354 | |||
355 | if (constraintFields.Count > 0 && constraintFields.Contains(fi.Name)) | ||
356 | { | ||
357 | constraints.Add(new KeyValuePair<string, string>(fi.Name, fi.GetValue(row).ToString() )); | ||
358 | } | ||
359 | if (m_FieldTypes.ContainsKey(fi.Name)) | ||
360 | cmd.Parameters.Add(m_database.CreateParameter(fi.Name, fi.GetValue(row), m_FieldTypes[fi.Name])); | ||
361 | else | ||
362 | cmd.Parameters.Add(m_database.CreateParameter(fi.Name, fi.GetValue(row))); | ||
363 | } | ||
364 | |||
365 | if (m_DataField != null) | ||
366 | { | ||
367 | Dictionary<string, string> data = | ||
368 | (Dictionary<string, string>)m_DataField.GetValue(row); | ||
369 | |||
370 | foreach (KeyValuePair<string, string> kvp in data) | ||
371 | { | ||
372 | if (constraintFields.Count > 0 && constraintFields.Contains(kvp.Key)) | ||
373 | { | ||
374 | constraints.Add(new KeyValuePair<string, string>(kvp.Key, kvp.Key)); | ||
375 | } | ||
376 | names.Add(kvp.Key); | ||
377 | values.Add(":" + kvp.Key); | ||
378 | |||
379 | if (m_FieldTypes.ContainsKey(kvp.Key)) | ||
380 | cmd.Parameters.Add(m_database.CreateParameter("" + kvp.Key, kvp.Value, m_FieldTypes[kvp.Key])); | ||
381 | else | ||
382 | cmd.Parameters.Add(m_database.CreateParameter("" + kvp.Key, kvp.Value)); | ||
383 | } | ||
384 | |||
385 | } | ||
386 | |||
387 | query.AppendFormat("UPDATE {0} SET ", m_Realm); | ||
388 | int i = 0; | ||
389 | for (i = 0; i < names.Count - 1; i++) | ||
390 | { | ||
391 | query.AppendFormat("\"{0}\" = {1}, ", names[i], values[i]); | ||
392 | } | ||
393 | query.AppendFormat("\"{0}\" = {1} ", names[i], values[i]); | ||
394 | if (constraints.Count > 0) | ||
395 | { | ||
396 | List<string> terms = new List<string>(); | ||
397 | for (int j = 0; j < constraints.Count; j++) | ||
398 | { | ||
399 | terms.Add(String.Format(" \"{0}\" = :{0}", constraints[j].Key)); | ||
400 | } | ||
401 | string where = String.Join(" AND ", terms.ToArray()); | ||
402 | query.AppendFormat(" WHERE {0} ", where); | ||
403 | |||
404 | } | ||
405 | cmd.Connection = conn; | ||
406 | cmd.CommandText = query.ToString(); | ||
407 | |||
408 | conn.Open(); | ||
409 | if (cmd.ExecuteNonQuery() > 0) | ||
410 | { | ||
411 | //m_log.WarnFormat("[PGSQLGenericTable]: Updating {0}", m_Realm); | ||
412 | return true; | ||
413 | } | ||
414 | else | ||
415 | { | ||
416 | // assume record has not yet been inserted | ||
417 | |||
418 | query = new StringBuilder(); | ||
419 | query.AppendFormat("INSERT INTO {0} (\"", m_Realm); | ||
420 | query.Append(String.Join("\",\"", names.ToArray())); | ||
421 | query.Append("\") values (" + String.Join(",", values.ToArray()) + ")"); | ||
422 | cmd.Connection = conn; | ||
423 | cmd.CommandText = query.ToString(); | ||
424 | |||
425 | // m_log.WarnFormat("[PGSQLGenericTable]: Inserting into {0} sql {1}", m_Realm, cmd.CommandText); | ||
426 | |||
427 | if (conn.State != ConnectionState.Open) | ||
428 | conn.Open(); | ||
429 | if (cmd.ExecuteNonQuery() > 0) | ||
430 | return true; | ||
431 | } | ||
432 | |||
433 | return false; | ||
434 | } | ||
435 | } | ||
436 | |||
437 | public virtual bool Delete(string field, string key) | ||
438 | { | ||
439 | return Delete(new string[] { field }, new string[] { key }); | ||
440 | } | ||
441 | |||
442 | public virtual bool Delete(string[] fields, string[] keys) | ||
443 | { | ||
444 | if (fields.Length != keys.Length) | ||
445 | return false; | ||
446 | |||
447 | List<string> terms = new List<string>(); | ||
448 | |||
449 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
450 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
451 | { | ||
452 | for (int i = 0; i < fields.Length; i++) | ||
453 | { | ||
454 | if (m_FieldTypes.ContainsKey(fields[i])) | ||
455 | cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i], m_FieldTypes[fields[i]])); | ||
456 | else | ||
457 | cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i])); | ||
458 | |||
459 | terms.Add(" \"" + fields[i] + "\" = :" + fields[i]); | ||
460 | } | ||
461 | |||
462 | string where = String.Join(" AND ", terms.ToArray()); | ||
463 | |||
464 | string query = String.Format("DELETE FROM {0} WHERE {1}", m_Realm, where); | ||
465 | |||
466 | cmd.Connection = conn; | ||
467 | cmd.CommandText = query; | ||
468 | conn.Open(); | ||
469 | |||
470 | if (cmd.ExecuteNonQuery() > 0) | ||
471 | { | ||
472 | //m_log.Warn("[PGSQLGenericTable]: " + deleteCommand); | ||
473 | return true; | ||
474 | } | ||
475 | return false; | ||
476 | } | ||
477 | } | ||
478 | public long GetCount(string field, string key) | ||
479 | { | ||
480 | return GetCount(new string[] { field }, new string[] { key }); | ||
481 | } | ||
482 | |||
483 | public long GetCount(string[] fields, string[] keys) | ||
484 | { | ||
485 | if (fields.Length != keys.Length) | ||
486 | return 0; | ||
487 | |||
488 | List<string> terms = new List<string>(); | ||
489 | |||
490 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
491 | { | ||
492 | for (int i = 0; i < fields.Length; i++) | ||
493 | { | ||
494 | cmd.Parameters.AddWithValue(fields[i], keys[i]); | ||
495 | terms.Add("\"" + fields[i] + "\" = :" + fields[i]); | ||
496 | } | ||
497 | |||
498 | string where = String.Join(" and ", terms.ToArray()); | ||
499 | |||
500 | string query = String.Format("select count(*) from {0} where {1}", | ||
501 | m_Realm, where); | ||
502 | |||
503 | cmd.CommandText = query; | ||
504 | |||
505 | Object result = DoQueryScalar(cmd); | ||
506 | |||
507 | return Convert.ToInt64(result); | ||
508 | } | ||
509 | } | ||
510 | |||
511 | public long GetCount(string where) | ||
512 | { | ||
513 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
514 | { | ||
515 | string query = String.Format("select count(*) from {0} where {1}", | ||
516 | m_Realm, where); | ||
517 | |||
518 | cmd.CommandText = query; | ||
519 | |||
520 | object result = DoQueryScalar(cmd); | ||
521 | |||
522 | return Convert.ToInt64(result); | ||
523 | } | ||
524 | } | ||
525 | |||
526 | public object DoQueryScalar(NpgsqlCommand cmd) | ||
527 | { | ||
528 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_ConnectionString)) | ||
529 | { | ||
530 | dbcon.Open(); | ||
531 | cmd.Connection = dbcon; | ||
532 | |||
533 | return cmd.ExecuteScalar(); | ||
534 | } | ||
535 | } | ||
536 | } | ||
537 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLGridUserData.cs b/OpenSim/Data/PGSQL/PGSQLGridUserData.cs new file mode 100644 index 0000000..89319f3 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLGridUserData.cs | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | |||
37 | namespace OpenSim.Data.PGSQL | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A PGSQL Interface for Avatar Storage | ||
41 | /// </summary> | ||
42 | public class PGSQLGridUserData : PGSQLGenericTableHandler<GridUserData>, | ||
43 | IGridUserData | ||
44 | { | ||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | public PGSQLGridUserData(string connectionString, string realm) : | ||
48 | base(connectionString, realm, "GridUserStore") | ||
49 | { | ||
50 | } | ||
51 | |||
52 | public new GridUserData Get(string userID) | ||
53 | { | ||
54 | GridUserData[] ret = Get("UserID", userID); | ||
55 | |||
56 | if (ret.Length == 0) | ||
57 | return null; | ||
58 | |||
59 | return ret[0]; | ||
60 | } | ||
61 | |||
62 | public GridUserData[] GetAll(string userID) | ||
63 | { | ||
64 | return base.Get(String.Format("\"UserID\" LIKE '{0}%'", userID)); | ||
65 | } | ||
66 | |||
67 | } | ||
68 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLGroupsData.cs b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs new file mode 100755 index 0000000..e257e7c --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLGroupsData.cs | |||
@@ -0,0 +1,485 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using log4net; | ||
35 | using Npgsql; | ||
36 | |||
37 | namespace OpenSim.Data.PGSQL | ||
38 | { | ||
39 | public class PGSQLGroupsData : IGroupsData | ||
40 | { | ||
41 | private PGSqlGroupsGroupsHandler m_Groups; | ||
42 | private PGSqlGroupsMembershipHandler m_Membership; | ||
43 | private PGSqlGroupsRolesHandler m_Roles; | ||
44 | private PGSqlGroupsRoleMembershipHandler m_RoleMembership; | ||
45 | private PGSqlGroupsInvitesHandler m_Invites; | ||
46 | private PGSqlGroupsNoticesHandler m_Notices; | ||
47 | private PGSqlGroupsPrincipalsHandler m_Principals; | ||
48 | |||
49 | public PGSQLGroupsData(string connectionString, string realm) | ||
50 | { | ||
51 | m_Groups = new PGSqlGroupsGroupsHandler(connectionString, realm + "_groups", realm + "_Store"); | ||
52 | m_Membership = new PGSqlGroupsMembershipHandler(connectionString, realm + "_membership"); | ||
53 | m_Roles = new PGSqlGroupsRolesHandler(connectionString, realm + "_roles"); | ||
54 | m_RoleMembership = new PGSqlGroupsRoleMembershipHandler(connectionString, realm + "_rolemembership"); | ||
55 | m_Invites = new PGSqlGroupsInvitesHandler(connectionString, realm + "_invites"); | ||
56 | m_Notices = new PGSqlGroupsNoticesHandler(connectionString, realm + "_notices"); | ||
57 | m_Principals = new PGSqlGroupsPrincipalsHandler(connectionString, realm + "_principals"); | ||
58 | } | ||
59 | |||
60 | #region groups table | ||
61 | public bool StoreGroup(GroupData data) | ||
62 | { | ||
63 | return m_Groups.Store(data); | ||
64 | } | ||
65 | |||
66 | public GroupData RetrieveGroup(UUID groupID) | ||
67 | { | ||
68 | GroupData[] groups = m_Groups.Get("GroupID", groupID.ToString()); | ||
69 | if (groups.Length > 0) | ||
70 | return groups[0]; | ||
71 | |||
72 | return null; | ||
73 | } | ||
74 | |||
75 | public GroupData RetrieveGroup(string name) | ||
76 | { | ||
77 | GroupData[] groups = m_Groups.Get("Name", name); | ||
78 | if (groups.Length > 0) | ||
79 | return groups[0]; | ||
80 | |||
81 | return null; | ||
82 | } | ||
83 | |||
84 | public GroupData[] RetrieveGroups(string pattern) | ||
85 | { | ||
86 | |||
87 | if (string.IsNullOrEmpty(pattern)) // True for where clause | ||
88 | { | ||
89 | pattern = " 1 ORDER BY lower(\"Name\") LIMIT 100"; | ||
90 | |||
91 | return m_Groups.Get(pattern); | ||
92 | } | ||
93 | else | ||
94 | { | ||
95 | pattern = " \"ShowInList\" = 1 AND lower(\"Name\") LIKE lower('%" + pattern + "%') ORDER BY lower(\"Name\") LIMIT 100"; | ||
96 | |||
97 | return m_Groups.Get(pattern, new NpgsqlParameter("pattern", pattern)); | ||
98 | } | ||
99 | } | ||
100 | |||
101 | public bool DeleteGroup(UUID groupID) | ||
102 | { | ||
103 | return m_Groups.Delete("GroupID", groupID.ToString()); | ||
104 | } | ||
105 | |||
106 | public int GroupsCount() | ||
107 | { | ||
108 | return (int)m_Groups.GetCount(" \"Location\" = \"\""); | ||
109 | } | ||
110 | |||
111 | #endregion | ||
112 | |||
113 | #region membership table | ||
114 | public MembershipData[] RetrieveMembers(UUID groupID) | ||
115 | { | ||
116 | return m_Membership.Get("GroupID", groupID.ToString()); | ||
117 | } | ||
118 | |||
119 | public MembershipData RetrieveMember(UUID groupID, string pricipalID) | ||
120 | { | ||
121 | MembershipData[] m = m_Membership.Get(new string[] { "GroupID", "PrincipalID" }, | ||
122 | new string[] { groupID.ToString(), pricipalID }); | ||
123 | if (m != null && m.Length > 0) | ||
124 | return m[0]; | ||
125 | |||
126 | return null; | ||
127 | } | ||
128 | |||
129 | public MembershipData[] RetrieveMemberships(string pricipalID) | ||
130 | { | ||
131 | return m_Membership.Get("PrincipalID", pricipalID.ToString()); | ||
132 | } | ||
133 | |||
134 | public bool StoreMember(MembershipData data) | ||
135 | { | ||
136 | return m_Membership.Store(data); | ||
137 | } | ||
138 | |||
139 | public bool DeleteMember(UUID groupID, string pricipalID) | ||
140 | { | ||
141 | return m_Membership.Delete(new string[] { "GroupID", "PrincipalID" }, | ||
142 | new string[] { groupID.ToString(), pricipalID }); | ||
143 | } | ||
144 | |||
145 | public int MemberCount(UUID groupID) | ||
146 | { | ||
147 | return (int)m_Membership.GetCount("GroupID", groupID.ToString()); | ||
148 | } | ||
149 | #endregion | ||
150 | |||
151 | #region roles table | ||
152 | public bool StoreRole(RoleData data) | ||
153 | { | ||
154 | return m_Roles.Store(data); | ||
155 | } | ||
156 | |||
157 | public RoleData RetrieveRole(UUID groupID, UUID roleID) | ||
158 | { | ||
159 | RoleData[] data = m_Roles.Get(new string[] { "GroupID", "RoleID" }, | ||
160 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
161 | |||
162 | if (data != null && data.Length > 0) | ||
163 | return data[0]; | ||
164 | |||
165 | return null; | ||
166 | } | ||
167 | |||
168 | public RoleData[] RetrieveRoles(UUID groupID) | ||
169 | { | ||
170 | //return m_Roles.RetrieveRoles(groupID); | ||
171 | return m_Roles.Get("GroupID", groupID.ToString()); | ||
172 | } | ||
173 | |||
174 | public bool DeleteRole(UUID groupID, UUID roleID) | ||
175 | { | ||
176 | return m_Roles.Delete(new string[] { "GroupID", "RoleID" }, | ||
177 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
178 | } | ||
179 | |||
180 | public int RoleCount(UUID groupID) | ||
181 | { | ||
182 | return (int)m_Roles.GetCount("GroupID", groupID.ToString()); | ||
183 | } | ||
184 | |||
185 | |||
186 | #endregion | ||
187 | |||
188 | #region rolememberhip table | ||
189 | public RoleMembershipData[] RetrieveRolesMembers(UUID groupID) | ||
190 | { | ||
191 | RoleMembershipData[] data = m_RoleMembership.Get("GroupID", groupID.ToString()); | ||
192 | |||
193 | return data; | ||
194 | } | ||
195 | |||
196 | public RoleMembershipData[] RetrieveRoleMembers(UUID groupID, UUID roleID) | ||
197 | { | ||
198 | RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "RoleID" }, | ||
199 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
200 | |||
201 | return data; | ||
202 | } | ||
203 | |||
204 | public RoleMembershipData[] RetrieveMemberRoles(UUID groupID, string principalID) | ||
205 | { | ||
206 | RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "PrincipalID" }, | ||
207 | new string[] { groupID.ToString(), principalID.ToString() }); | ||
208 | |||
209 | return data; | ||
210 | } | ||
211 | |||
212 | public RoleMembershipData RetrieveRoleMember(UUID groupID, UUID roleID, string principalID) | ||
213 | { | ||
214 | RoleMembershipData[] data = m_RoleMembership.Get(new string[] { "GroupID", "RoleID", "PrincipalID" }, | ||
215 | new string[] { groupID.ToString(), roleID.ToString(), principalID.ToString() }); | ||
216 | |||
217 | if (data != null && data.Length > 0) | ||
218 | return data[0]; | ||
219 | |||
220 | return null; | ||
221 | } | ||
222 | |||
223 | public int RoleMemberCount(UUID groupID, UUID roleID) | ||
224 | { | ||
225 | return (int)m_RoleMembership.GetCount(new string[] { "GroupID", "RoleID" }, | ||
226 | new string[] { groupID.ToString(), roleID.ToString() }); | ||
227 | } | ||
228 | |||
229 | public bool StoreRoleMember(RoleMembershipData data) | ||
230 | { | ||
231 | return m_RoleMembership.Store(data); | ||
232 | } | ||
233 | |||
234 | public bool DeleteRoleMember(RoleMembershipData data) | ||
235 | { | ||
236 | return m_RoleMembership.Delete(new string[] { "GroupID", "RoleID", "PrincipalID"}, | ||
237 | new string[] { data.GroupID.ToString(), data.RoleID.ToString(), data.PrincipalID }); | ||
238 | } | ||
239 | |||
240 | public bool DeleteMemberAllRoles(UUID groupID, string principalID) | ||
241 | { | ||
242 | return m_RoleMembership.Delete(new string[] { "GroupID", "PrincipalID" }, | ||
243 | new string[] { groupID.ToString(), principalID }); | ||
244 | } | ||
245 | |||
246 | #endregion | ||
247 | |||
248 | #region principals table | ||
249 | public bool StorePrincipal(PrincipalData data) | ||
250 | { | ||
251 | return m_Principals.Store(data); | ||
252 | } | ||
253 | |||
254 | public PrincipalData RetrievePrincipal(string principalID) | ||
255 | { | ||
256 | PrincipalData[] p = m_Principals.Get("PrincipalID", principalID); | ||
257 | if (p != null && p.Length > 0) | ||
258 | return p[0]; | ||
259 | |||
260 | return null; | ||
261 | } | ||
262 | |||
263 | public bool DeletePrincipal(string principalID) | ||
264 | { | ||
265 | return m_Principals.Delete("PrincipalID", principalID); | ||
266 | } | ||
267 | #endregion | ||
268 | |||
269 | #region invites table | ||
270 | |||
271 | public bool StoreInvitation(InvitationData data) | ||
272 | { | ||
273 | return m_Invites.Store(data); | ||
274 | } | ||
275 | |||
276 | public InvitationData RetrieveInvitation(UUID inviteID) | ||
277 | { | ||
278 | InvitationData[] invites = m_Invites.Get("InviteID", inviteID.ToString()); | ||
279 | |||
280 | if (invites != null && invites.Length > 0) | ||
281 | return invites[0]; | ||
282 | |||
283 | return null; | ||
284 | } | ||
285 | |||
286 | public InvitationData RetrieveInvitation(UUID groupID, string principalID) | ||
287 | { | ||
288 | InvitationData[] invites = m_Invites.Get(new string[] { "GroupID", "PrincipalID" }, | ||
289 | new string[] { groupID.ToString(), principalID }); | ||
290 | |||
291 | if (invites != null && invites.Length > 0) | ||
292 | return invites[0]; | ||
293 | |||
294 | return null; | ||
295 | } | ||
296 | |||
297 | public bool DeleteInvite(UUID inviteID) | ||
298 | { | ||
299 | return m_Invites.Delete("InviteID", inviteID.ToString()); | ||
300 | } | ||
301 | |||
302 | public void DeleteOldInvites() | ||
303 | { | ||
304 | m_Invites.DeleteOld(); | ||
305 | } | ||
306 | |||
307 | #endregion | ||
308 | |||
309 | #region notices table | ||
310 | |||
311 | public bool StoreNotice(NoticeData data) | ||
312 | { | ||
313 | return m_Notices.Store(data); | ||
314 | } | ||
315 | |||
316 | public NoticeData RetrieveNotice(UUID noticeID) | ||
317 | { | ||
318 | NoticeData[] notices = m_Notices.Get("NoticeID", noticeID.ToString()); | ||
319 | |||
320 | if (notices != null && notices.Length > 0) | ||
321 | return notices[0]; | ||
322 | |||
323 | return null; | ||
324 | } | ||
325 | |||
326 | public NoticeData[] RetrieveNotices(UUID groupID) | ||
327 | { | ||
328 | NoticeData[] notices = m_Notices.Get("GroupID", groupID.ToString()); | ||
329 | |||
330 | return notices; | ||
331 | } | ||
332 | |||
333 | public bool DeleteNotice(UUID noticeID) | ||
334 | { | ||
335 | return m_Notices.Delete("NoticeID", noticeID.ToString()); | ||
336 | } | ||
337 | |||
338 | public void DeleteOldNotices() | ||
339 | { | ||
340 | m_Notices.DeleteOld(); | ||
341 | } | ||
342 | |||
343 | #endregion | ||
344 | |||
345 | #region combinations | ||
346 | public MembershipData RetrievePrincipalGroupMembership(string principalID, UUID groupID) | ||
347 | { | ||
348 | // TODO | ||
349 | return null; | ||
350 | } | ||
351 | public MembershipData[] RetrievePrincipalGroupMemberships(string principalID) | ||
352 | { | ||
353 | // TODO | ||
354 | return null; | ||
355 | } | ||
356 | |||
357 | #endregion | ||
358 | } | ||
359 | |||
360 | public class PGSqlGroupsGroupsHandler : PGSQLGenericTableHandler<GroupData> | ||
361 | { | ||
362 | protected override Assembly Assembly | ||
363 | { | ||
364 | // WARNING! Moving migrations to this assembly!!! | ||
365 | get { return GetType().Assembly; } | ||
366 | } | ||
367 | |||
368 | public PGSqlGroupsGroupsHandler(string connectionString, string realm, string store) | ||
369 | : base(connectionString, realm, store) | ||
370 | { | ||
371 | } | ||
372 | |||
373 | } | ||
374 | |||
375 | public class PGSqlGroupsMembershipHandler : PGSQLGenericTableHandler<MembershipData> | ||
376 | { | ||
377 | protected override Assembly Assembly | ||
378 | { | ||
379 | // WARNING! Moving migrations to this assembly!!! | ||
380 | get { return GetType().Assembly; } | ||
381 | } | ||
382 | |||
383 | public PGSqlGroupsMembershipHandler(string connectionString, string realm) | ||
384 | : base(connectionString, realm, string.Empty) | ||
385 | { | ||
386 | } | ||
387 | |||
388 | } | ||
389 | |||
390 | public class PGSqlGroupsRolesHandler : PGSQLGenericTableHandler<RoleData> | ||
391 | { | ||
392 | protected override Assembly Assembly | ||
393 | { | ||
394 | // WARNING! Moving migrations to this assembly!!! | ||
395 | get { return GetType().Assembly; } | ||
396 | } | ||
397 | |||
398 | public PGSqlGroupsRolesHandler(string connectionString, string realm) | ||
399 | : base(connectionString, realm, string.Empty) | ||
400 | { | ||
401 | } | ||
402 | |||
403 | } | ||
404 | |||
405 | public class PGSqlGroupsRoleMembershipHandler : PGSQLGenericTableHandler<RoleMembershipData> | ||
406 | { | ||
407 | protected override Assembly Assembly | ||
408 | { | ||
409 | // WARNING! Moving migrations to this assembly!!! | ||
410 | get { return GetType().Assembly; } | ||
411 | } | ||
412 | |||
413 | public PGSqlGroupsRoleMembershipHandler(string connectionString, string realm) | ||
414 | : base(connectionString, realm, string.Empty) | ||
415 | { | ||
416 | } | ||
417 | |||
418 | } | ||
419 | |||
420 | public class PGSqlGroupsInvitesHandler : PGSQLGenericTableHandler<InvitationData> | ||
421 | { | ||
422 | protected override Assembly Assembly | ||
423 | { | ||
424 | // WARNING! Moving migrations to this assembly!!! | ||
425 | get { return GetType().Assembly; } | ||
426 | } | ||
427 | |||
428 | public PGSqlGroupsInvitesHandler(string connectionString, string realm) | ||
429 | : base(connectionString, realm, string.Empty) | ||
430 | { | ||
431 | } | ||
432 | |||
433 | public void DeleteOld() | ||
434 | { | ||
435 | |||
436 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
437 | { | ||
438 | cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < CURRENT_DATE - INTERVAL '2 week'", m_Realm); | ||
439 | |||
440 | ExecuteNonQuery(cmd); | ||
441 | } | ||
442 | |||
443 | } | ||
444 | } | ||
445 | |||
446 | public class PGSqlGroupsNoticesHandler : PGSQLGenericTableHandler<NoticeData> | ||
447 | { | ||
448 | protected override Assembly Assembly | ||
449 | { | ||
450 | // WARNING! Moving migrations to this assembly!!! | ||
451 | get { return GetType().Assembly; } | ||
452 | } | ||
453 | |||
454 | public PGSqlGroupsNoticesHandler(string connectionString, string realm) | ||
455 | : base(connectionString, realm, string.Empty) | ||
456 | { | ||
457 | } | ||
458 | |||
459 | public void DeleteOld() | ||
460 | { | ||
461 | |||
462 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
463 | { | ||
464 | cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < CURRENT_DATE - INTERVAL '2 week'", m_Realm); | ||
465 | |||
466 | ExecuteNonQuery(cmd); | ||
467 | } | ||
468 | |||
469 | } | ||
470 | } | ||
471 | |||
472 | public class PGSqlGroupsPrincipalsHandler : PGSQLGenericTableHandler<PrincipalData> | ||
473 | { | ||
474 | protected override Assembly Assembly | ||
475 | { | ||
476 | // WARNING! Moving migrations to this assembly!!! | ||
477 | get { return GetType().Assembly; } | ||
478 | } | ||
479 | |||
480 | public PGSqlGroupsPrincipalsHandler(string connectionString, string realm) | ||
481 | : base(connectionString, realm, string.Empty) | ||
482 | { | ||
483 | } | ||
484 | } | ||
485 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLHGTravelData.cs b/OpenSim/Data/PGSQL/PGSQLHGTravelData.cs new file mode 100644 index 0000000..c71b15f --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLHGTravelData.cs | |||
@@ -0,0 +1,80 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using Npgsql; | ||
37 | |||
38 | namespace OpenSim.Data.PGSQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A PGSQL Interface for user grid data | ||
42 | /// </summary> | ||
43 | public class PGSQLHGTravelData : PGSQLGenericTableHandler<HGTravelingData>, IHGTravelingData | ||
44 | { | ||
45 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | public PGSQLHGTravelData(string connectionString, string realm) : base(connectionString, realm, "HGTravelStore") { } | ||
48 | |||
49 | public HGTravelingData Get(UUID sessionID) | ||
50 | { | ||
51 | HGTravelingData[] ret = Get("SessionID", sessionID.ToString()); | ||
52 | |||
53 | if (ret.Length == 0) | ||
54 | return null; | ||
55 | |||
56 | return ret[0]; | ||
57 | } | ||
58 | |||
59 | public HGTravelingData[] GetSessions(UUID userID) | ||
60 | { | ||
61 | return base.Get("UserID", userID.ToString()); | ||
62 | } | ||
63 | |||
64 | public bool Delete(UUID sessionID) | ||
65 | { | ||
66 | return Delete("SessionID", sessionID.ToString()); | ||
67 | } | ||
68 | |||
69 | public void DeleteOld() | ||
70 | { | ||
71 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
72 | { | ||
73 | cmd.CommandText = String.Format(@"delete from {0} where ""TMStamp"" < CURRENT_DATE - INTERVAL '2 day'", m_Realm); | ||
74 | |||
75 | ExecuteNonQuery(cmd); | ||
76 | } | ||
77 | |||
78 | } | ||
79 | } | ||
80 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLInventoryData.cs b/OpenSim/Data/PGSQL/PGSQLInventoryData.cs new file mode 100644 index 0000000..c999433 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLInventoryData.cs | |||
@@ -0,0 +1,831 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using log4net; | ||
33 | using OpenMetaverse; | ||
34 | using OpenSim.Framework; | ||
35 | using Npgsql; | ||
36 | |||
37 | namespace OpenSim.Data.PGSQL | ||
38 | { | ||
39 | /// <summary> | ||
40 | /// A PGSQL interface for the inventory server | ||
41 | /// </summary> | ||
42 | public class PGSQLInventoryData : IInventoryDataPlugin | ||
43 | { | ||
44 | private const string _migrationStore = "InventoryStore"; | ||
45 | |||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | /// <summary> | ||
49 | /// The database manager | ||
50 | /// </summary> | ||
51 | private PGSQLManager database; | ||
52 | private string m_connectionString; | ||
53 | |||
54 | #region IPlugin members | ||
55 | |||
56 | [Obsolete("Cannot be default-initialized!")] | ||
57 | public void Initialise() | ||
58 | { | ||
59 | m_log.Info("[PGSQLInventoryData]: " + Name + " cannot be default-initialized!"); | ||
60 | throw new PluginNotInitialisedException(Name); | ||
61 | } | ||
62 | |||
63 | /// <summary> | ||
64 | /// Loads and initialises the PGSQL inventory storage interface | ||
65 | /// </summary> | ||
66 | /// <param name="connectionString">connect string</param> | ||
67 | /// <remarks>use PGSQL_connection.ini</remarks> | ||
68 | public void Initialise(string connectionString) | ||
69 | { | ||
70 | m_connectionString = connectionString; | ||
71 | database = new PGSQLManager(connectionString); | ||
72 | |||
73 | //New migrations check of store | ||
74 | database.CheckMigration(_migrationStore); | ||
75 | } | ||
76 | |||
77 | /// <summary> | ||
78 | /// The name of this DB provider | ||
79 | /// </summary> | ||
80 | /// <returns>A string containing the name of the DB provider</returns> | ||
81 | public string Name | ||
82 | { | ||
83 | get { return "PGSQL Inventory Data Interface"; } | ||
84 | } | ||
85 | |||
86 | /// <summary> | ||
87 | /// Closes this DB provider | ||
88 | /// </summary> | ||
89 | public void Dispose() | ||
90 | { | ||
91 | database = null; | ||
92 | } | ||
93 | |||
94 | /// <summary> | ||
95 | /// Returns the version of this DB provider | ||
96 | /// </summary> | ||
97 | /// <returns>A string containing the DB provider</returns> | ||
98 | public string Version | ||
99 | { | ||
100 | get { return database.getVersion(); } | ||
101 | } | ||
102 | |||
103 | #endregion | ||
104 | |||
105 | #region Folder methods | ||
106 | |||
107 | /// <summary> | ||
108 | /// Returns a list of the root folders within a users inventory | ||
109 | /// </summary> | ||
110 | /// <param name="user">The user whos inventory is to be searched</param> | ||
111 | /// <returns>A list of folder objects</returns> | ||
112 | public List<InventoryFolderBase> getUserRootFolders(UUID user) | ||
113 | { | ||
114 | if (user == UUID.Zero) | ||
115 | return new List<InventoryFolderBase>(); | ||
116 | |||
117 | return getInventoryFolders(UUID.Zero, user); | ||
118 | } | ||
119 | |||
120 | /// <summary> | ||
121 | /// see InventoryItemBase.getUserRootFolder | ||
122 | /// </summary> | ||
123 | /// <param name="user">the User UUID</param> | ||
124 | /// <returns></returns> | ||
125 | public InventoryFolderBase getUserRootFolder(UUID user) | ||
126 | { | ||
127 | List<InventoryFolderBase> items = getUserRootFolders(user); | ||
128 | |||
129 | InventoryFolderBase rootFolder = null; | ||
130 | |||
131 | // There should only ever be one root folder for a user. However, if there's more | ||
132 | // than one we'll simply use the first one rather than failing. It would be even | ||
133 | // nicer to print some message to this effect, but this feels like it's too low a | ||
134 | // to put such a message out, and it's too minor right now to spare the time to | ||
135 | // suitably refactor. | ||
136 | if (items.Count > 0) | ||
137 | { | ||
138 | rootFolder = items[0]; | ||
139 | } | ||
140 | |||
141 | return rootFolder; | ||
142 | } | ||
143 | |||
144 | /// <summary> | ||
145 | /// Returns a list of folders in a users inventory contained within the specified folder | ||
146 | /// </summary> | ||
147 | /// <param name="parentID">The folder to search</param> | ||
148 | /// <returns>A list of inventory folders</returns> | ||
149 | public List<InventoryFolderBase> getInventoryFolders(UUID parentID) | ||
150 | { | ||
151 | return getInventoryFolders(parentID, UUID.Zero); | ||
152 | } | ||
153 | |||
154 | /// <summary> | ||
155 | /// Returns a specified inventory folder | ||
156 | /// </summary> | ||
157 | /// <param name="folderID">The folder to return</param> | ||
158 | /// <returns>A folder class</returns> | ||
159 | public InventoryFolderBase getInventoryFolder(UUID folderID) | ||
160 | { | ||
161 | string sql = "SELECT * FROM inventoryfolders WHERE \"folderID\" = :folderID"; | ||
162 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
163 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
164 | { | ||
165 | cmd.Parameters.Add(database.CreateParameter("folderID", folderID)); | ||
166 | conn.Open(); | ||
167 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
168 | { | ||
169 | if (reader.Read()) | ||
170 | { | ||
171 | return readInventoryFolder(reader); | ||
172 | } | ||
173 | } | ||
174 | } | ||
175 | m_log.InfoFormat("[INVENTORY DB] : Found no inventory folder with ID : {0}", folderID); | ||
176 | return null; | ||
177 | } | ||
178 | |||
179 | /// <summary> | ||
180 | /// Returns all child folders in the hierarchy from the parent folder and down. | ||
181 | /// Does not return the parent folder itself. | ||
182 | /// </summary> | ||
183 | /// <param name="parentID">The folder to get subfolders for</param> | ||
184 | /// <returns>A list of inventory folders</returns> | ||
185 | public List<InventoryFolderBase> getFolderHierarchy(UUID parentID) | ||
186 | { | ||
187 | //Note maybe change this to use a Dataset that loading in all folders of a user and then go throw it that way. | ||
188 | //Note this is changed so it opens only one connection to the database and not everytime it wants to get data. | ||
189 | |||
190 | /* NOTE: the implementation below is very inefficient (makes a separate request to get subfolders for | ||
191 | * every found folder, recursively). Inventory code for other DBs has been already rewritten to get ALL | ||
192 | * inventory for a specific user at once. | ||
193 | * | ||
194 | * Meanwhile, one little thing is corrected: getFolderHierarchy(UUID.Zero) doesn't make sense and should never | ||
195 | * be used, so check for that and return an empty list. | ||
196 | */ | ||
197 | |||
198 | List<InventoryFolderBase> folders = new List<InventoryFolderBase>(); | ||
199 | |||
200 | if (parentID == UUID.Zero) | ||
201 | return folders; | ||
202 | |||
203 | string sql = "SELECT * FROM inventoryfolders WHERE \"parentFolderID\" = :parentID"; | ||
204 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
205 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
206 | { | ||
207 | cmd.Parameters.Add(database.CreateParameter("parentID", parentID)); | ||
208 | conn.Open(); | ||
209 | folders.AddRange(getInventoryFolders(cmd)); | ||
210 | |||
211 | List<InventoryFolderBase> tempFolders = new List<InventoryFolderBase>(); | ||
212 | |||
213 | foreach (InventoryFolderBase folderBase in folders) | ||
214 | { | ||
215 | tempFolders.AddRange(getFolderHierarchy(folderBase.ID, cmd)); | ||
216 | } | ||
217 | if (tempFolders.Count > 0) | ||
218 | { | ||
219 | folders.AddRange(tempFolders); | ||
220 | } | ||
221 | } | ||
222 | return folders; | ||
223 | } | ||
224 | |||
225 | /// <summary> | ||
226 | /// Creates a new inventory folder | ||
227 | /// </summary> | ||
228 | /// <param name="folder">Folder to create</param> | ||
229 | public void addInventoryFolder(InventoryFolderBase folder) | ||
230 | { | ||
231 | string sql = "INSERT INTO inventoryfolders (\"folderID\", \"agentID\", \"parentFolderID\", \"folderName\", type, version) " + | ||
232 | " VALUES (:folderID, :agentID, :parentFolderID, :folderName, :type, :version);"; | ||
233 | |||
234 | string folderName = folder.Name; | ||
235 | if (folderName.Length > 64) | ||
236 | { | ||
237 | folderName = folderName.Substring(0, 64); | ||
238 | m_log.Warn("[INVENTORY DB]: Name field truncated from " + folder.Name.Length.ToString() + " to " + folderName.Length + " characters on add"); | ||
239 | } | ||
240 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
241 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
242 | { | ||
243 | cmd.Parameters.Add(database.CreateParameter("folderID", folder.ID)); | ||
244 | cmd.Parameters.Add(database.CreateParameter("agentID", folder.Owner)); | ||
245 | cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID)); | ||
246 | cmd.Parameters.Add(database.CreateParameter("folderName", folderName)); | ||
247 | cmd.Parameters.Add(database.CreateParameter("type", folder.Type)); | ||
248 | cmd.Parameters.Add(database.CreateParameter("version", folder.Version)); | ||
249 | conn.Open(); | ||
250 | try | ||
251 | { | ||
252 | cmd.ExecuteNonQuery(); | ||
253 | } | ||
254 | catch (Exception e) | ||
255 | { | ||
256 | m_log.ErrorFormat("[INVENTORY DB]: Error : {0}", e.Message); | ||
257 | } | ||
258 | } | ||
259 | } | ||
260 | |||
261 | /// <summary> | ||
262 | /// Updates an inventory folder | ||
263 | /// </summary> | ||
264 | /// <param name="folder">Folder to update</param> | ||
265 | public void updateInventoryFolder(InventoryFolderBase folder) | ||
266 | { | ||
267 | string sql = @"UPDATE inventoryfolders SET ""agentID"" = :agentID, | ||
268 | ""parentFolderID"" = :parentFolderID, | ||
269 | ""folderName"" = :folderName, | ||
270 | type = :type, | ||
271 | version = :version | ||
272 | WHERE folderID = :folderID"; | ||
273 | |||
274 | string folderName = folder.Name; | ||
275 | if (folderName.Length > 64) | ||
276 | { | ||
277 | folderName = folderName.Substring(0, 64); | ||
278 | m_log.Warn("[INVENTORY DB]: Name field truncated from " + folder.Name.Length.ToString() + " to " + folderName.Length + " characters on update"); | ||
279 | } | ||
280 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
281 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
282 | { | ||
283 | cmd.Parameters.Add(database.CreateParameter("folderID", folder.ID)); | ||
284 | cmd.Parameters.Add(database.CreateParameter("agentID", folder.Owner)); | ||
285 | cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID)); | ||
286 | cmd.Parameters.Add(database.CreateParameter("folderName", folderName)); | ||
287 | cmd.Parameters.Add(database.CreateParameter("type", folder.Type)); | ||
288 | cmd.Parameters.Add(database.CreateParameter("version", folder.Version)); | ||
289 | conn.Open(); | ||
290 | try | ||
291 | { | ||
292 | cmd.ExecuteNonQuery(); | ||
293 | } | ||
294 | catch (Exception e) | ||
295 | { | ||
296 | m_log.ErrorFormat("[INVENTORY DB]: Error : {0}", e.Message); | ||
297 | } | ||
298 | } | ||
299 | } | ||
300 | |||
301 | /// <summary> | ||
302 | /// Updates an inventory folder | ||
303 | /// </summary> | ||
304 | /// <param name="folder">Folder to update</param> | ||
305 | public void moveInventoryFolder(InventoryFolderBase folder) | ||
306 | { | ||
307 | string sql = @"UPDATE inventoryfolders SET ""parentFolderID"" = :parentFolderID WHERE ""folderID"" = :folderID"; | ||
308 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
309 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
310 | { | ||
311 | cmd.Parameters.Add(database.CreateParameter("parentFolderID", folder.ParentID)); | ||
312 | cmd.Parameters.Add(database.CreateParameter("folderID", folder.ID)); | ||
313 | conn.Open(); | ||
314 | try | ||
315 | { | ||
316 | cmd.ExecuteNonQuery(); | ||
317 | } | ||
318 | catch (Exception e) | ||
319 | { | ||
320 | m_log.ErrorFormat("[INVENTORY DB]: Error : {0}", e.Message); | ||
321 | } | ||
322 | } | ||
323 | } | ||
324 | |||
325 | /// <summary> | ||
326 | /// Delete an inventory folder | ||
327 | /// </summary> | ||
328 | /// <param name="folderID">Id of folder to delete</param> | ||
329 | public void deleteInventoryFolder(UUID folderID) | ||
330 | { | ||
331 | string sql = @"SELECT * FROM inventoryfolders WHERE ""parentFolderID"" = :parentID"; | ||
332 | |||
333 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
334 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
335 | { | ||
336 | List<InventoryFolderBase> subFolders; | ||
337 | cmd.Parameters.Add(database.CreateParameter("parentID", UUID.Zero)); | ||
338 | conn.Open(); | ||
339 | subFolders = getFolderHierarchy(folderID, cmd); | ||
340 | |||
341 | |||
342 | //Delete all sub-folders | ||
343 | foreach (InventoryFolderBase f in subFolders) | ||
344 | { | ||
345 | DeleteOneFolder(f.ID, conn); | ||
346 | DeleteItemsInFolder(f.ID, conn); | ||
347 | } | ||
348 | |||
349 | //Delete the actual row | ||
350 | DeleteOneFolder(folderID, conn); | ||
351 | DeleteItemsInFolder(folderID, conn); | ||
352 | } | ||
353 | } | ||
354 | |||
355 | #endregion | ||
356 | |||
357 | #region Item Methods | ||
358 | |||
359 | /// <summary> | ||
360 | /// Returns a list of items in a specified folder | ||
361 | /// </summary> | ||
362 | /// <param name="folderID">The folder to search</param> | ||
363 | /// <returns>A list containing inventory items</returns> | ||
364 | public List<InventoryItemBase> getInventoryInFolder(UUID folderID) | ||
365 | { | ||
366 | string sql = @"SELECT * FROM inventoryitems WHERE ""parentFolderID"" = :parentFolderID"; | ||
367 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
368 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
369 | { | ||
370 | cmd.Parameters.Add(database.CreateParameter("parentFolderID", folderID)); | ||
371 | conn.Open(); | ||
372 | List<InventoryItemBase> items = new List<InventoryItemBase>(); | ||
373 | |||
374 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
375 | { | ||
376 | while (reader.Read()) | ||
377 | { | ||
378 | items.Add(readInventoryItem(reader)); | ||
379 | } | ||
380 | } | ||
381 | return items; | ||
382 | } | ||
383 | } | ||
384 | |||
385 | /// <summary> | ||
386 | /// Returns a specified inventory item | ||
387 | /// </summary> | ||
388 | /// <param name="itemID">The item ID</param> | ||
389 | /// <returns>An inventory item</returns> | ||
390 | public InventoryItemBase getInventoryItem(UUID itemID) | ||
391 | { | ||
392 | string sql = @"SELECT * FROM inventoryitems WHERE ""inventoryID"" = :inventoryID"; | ||
393 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
394 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
395 | { | ||
396 | cmd.Parameters.Add(database.CreateParameter("inventoryID", itemID)); | ||
397 | conn.Open(); | ||
398 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
399 | { | ||
400 | if (reader.Read()) | ||
401 | { | ||
402 | return readInventoryItem(reader); | ||
403 | } | ||
404 | } | ||
405 | } | ||
406 | |||
407 | m_log.InfoFormat("[INVENTORY DB]: Found no inventory item with ID : {0}", itemID); | ||
408 | return null; | ||
409 | } | ||
410 | |||
411 | /// <summary> | ||
412 | /// Adds a specified item to the database | ||
413 | /// </summary> | ||
414 | /// <param name="item">The inventory item</param> | ||
415 | public void addInventoryItem(InventoryItemBase item) | ||
416 | { | ||
417 | if (getInventoryItem(item.ID) != null) | ||
418 | { | ||
419 | updateInventoryItem(item); | ||
420 | return; | ||
421 | } | ||
422 | |||
423 | string sql = @"INSERT INTO inventoryitems | ||
424 | (""inventoryID"", ""assetID"", ""assetType"", ""parentFolderID"", ""avatarID"", ""inventoryName"", | ||
425 | ""inventoryDescription"", ""inventoryNextPermissions"", ""inventoryCurrentPermissions"", | ||
426 | ""invType"", ""creatorID"", ""inventoryBasePermissions"", ""inventoryEveryOnePermissions"", ""inventoryGroupPermissions"", | ||
427 | ""salePrice"", ""SaleType"", ""creationDate"", ""groupID"", ""groupOwned"", flags) | ||
428 | VALUES | ||
429 | (:inventoryID, :assetID, :assetType, :parentFolderID, :avatarID, :inventoryName, :inventoryDescription, | ||
430 | :inventoryNextPermissions, :inventoryCurrentPermissions, :invType, :creatorID, | ||
431 | :inventoryBasePermissions, :inventoryEveryOnePermissions, :inventoryGroupPermissions, :SalePrice, :SaleType, | ||
432 | :creationDate, :groupID, :groupOwned, :flags)"; | ||
433 | |||
434 | string itemName = item.Name; | ||
435 | if (item.Name.Length > 64) | ||
436 | { | ||
437 | itemName = item.Name.Substring(0, 64); | ||
438 | m_log.Warn("[INVENTORY DB]: Name field truncated from " + item.Name.Length.ToString() + " to " + itemName.Length.ToString() + " characters"); | ||
439 | } | ||
440 | |||
441 | string itemDesc = item.Description; | ||
442 | if (item.Description.Length > 128) | ||
443 | { | ||
444 | itemDesc = item.Description.Substring(0, 128); | ||
445 | m_log.Warn("[INVENTORY DB]: Description field truncated from " + item.Description.Length.ToString() + " to " + itemDesc.Length.ToString() + " characters"); | ||
446 | } | ||
447 | |||
448 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
449 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) | ||
450 | { | ||
451 | command.Parameters.Add(database.CreateParameter("inventoryID", item.ID)); | ||
452 | command.Parameters.Add(database.CreateParameter("assetID", item.AssetID)); | ||
453 | command.Parameters.Add(database.CreateParameter("assetType", item.AssetType)); | ||
454 | command.Parameters.Add(database.CreateParameter("parentFolderID", item.Folder)); | ||
455 | command.Parameters.Add(database.CreateParameter("avatarID", item.Owner)); | ||
456 | command.Parameters.Add(database.CreateParameter("inventoryName", itemName)); | ||
457 | command.Parameters.Add(database.CreateParameter("inventoryDescription", itemDesc)); | ||
458 | command.Parameters.Add(database.CreateParameter("inventoryNextPermissions", item.NextPermissions)); | ||
459 | command.Parameters.Add(database.CreateParameter("inventoryCurrentPermissions", item.CurrentPermissions)); | ||
460 | command.Parameters.Add(database.CreateParameter("invType", item.InvType)); | ||
461 | command.Parameters.Add(database.CreateParameter("creatorID", item.CreatorId)); | ||
462 | command.Parameters.Add(database.CreateParameter("inventoryBasePermissions", item.BasePermissions)); | ||
463 | command.Parameters.Add(database.CreateParameter("inventoryEveryOnePermissions", item.EveryOnePermissions)); | ||
464 | command.Parameters.Add(database.CreateParameter("inventoryGroupPermissions", item.GroupPermissions)); | ||
465 | command.Parameters.Add(database.CreateParameter("SalePrice", item.SalePrice)); | ||
466 | command.Parameters.Add(database.CreateParameter("SaleType", item.SaleType)); | ||
467 | command.Parameters.Add(database.CreateParameter("creationDate", item.CreationDate)); | ||
468 | command.Parameters.Add(database.CreateParameter("groupID", item.GroupID)); | ||
469 | command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned)); | ||
470 | command.Parameters.Add(database.CreateParameter("flags", item.Flags)); | ||
471 | conn.Open(); | ||
472 | try | ||
473 | { | ||
474 | command.ExecuteNonQuery(); | ||
475 | } | ||
476 | catch (Exception e) | ||
477 | { | ||
478 | m_log.Error("[INVENTORY DB]: Error inserting item :" + e.Message); | ||
479 | } | ||
480 | } | ||
481 | |||
482 | sql = @"UPDATE inventoryfolders SET version = version + 1 WHERE ""folderID"" = @folderID"; | ||
483 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
484 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) | ||
485 | { | ||
486 | command.Parameters.Add(database.CreateParameter("folderID", item.Folder.ToString())); | ||
487 | conn.Open(); | ||
488 | try | ||
489 | { | ||
490 | command.ExecuteNonQuery(); | ||
491 | } | ||
492 | catch (Exception e) | ||
493 | { | ||
494 | m_log.Error("[INVENTORY DB] Error updating inventory folder for new item :" + e.Message); | ||
495 | } | ||
496 | } | ||
497 | } | ||
498 | |||
499 | /// <summary> | ||
500 | /// Updates the specified inventory item | ||
501 | /// </summary> | ||
502 | /// <param name="item">Inventory item to update</param> | ||
503 | public void updateInventoryItem(InventoryItemBase item) | ||
504 | { | ||
505 | string sql = @"UPDATE inventoryitems SET ""assetID"" = :assetID, | ||
506 | ""assetType"" = :assetType, | ||
507 | ""parentFolderID"" = :parentFolderID, | ||
508 | ""avatarID"" = :avatarID, | ||
509 | ""inventoryName"" = :inventoryName, | ||
510 | ""inventoryDescription"" = :inventoryDescription, | ||
511 | ""inventoryNextPermissions"" = :inventoryNextPermissions, | ||
512 | ""inventoryCurrentPermissions"" = :inventoryCurrentPermissions, | ||
513 | ""invType"" = :invType, | ||
514 | ""creatorID"" = :creatorID, | ||
515 | ""inventoryBasePermissions"" = :inventoryBasePermissions, | ||
516 | ""inventoryEveryOnePermissions"" = :inventoryEveryOnePermissions, | ||
517 | ""inventoryGroupPermissions"" = :inventoryGroupPermissions, | ||
518 | ""salePrice"" = :SalePrice, | ||
519 | ""saleType"" = :SaleType, | ||
520 | ""creationDate"" = :creationDate, | ||
521 | ""groupID"" = :groupID, | ||
522 | ""groupOwned"" = :groupOwned, | ||
523 | flags = :flags | ||
524 | WHERE ""inventoryID"" = :inventoryID"; | ||
525 | |||
526 | string itemName = item.Name; | ||
527 | if (item.Name.Length > 64) | ||
528 | { | ||
529 | itemName = item.Name.Substring(0, 64); | ||
530 | m_log.Warn("[INVENTORY DB]: Name field truncated from " + item.Name.Length.ToString() + " to " + itemName.Length.ToString() + " characters on update"); | ||
531 | } | ||
532 | |||
533 | string itemDesc = item.Description; | ||
534 | if (item.Description.Length > 128) | ||
535 | { | ||
536 | itemDesc = item.Description.Substring(0, 128); | ||
537 | m_log.Warn("[INVENTORY DB]: Description field truncated from " + item.Description.Length.ToString() + " to " + itemDesc.Length.ToString() + " characters on update"); | ||
538 | } | ||
539 | |||
540 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
541 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) | ||
542 | { | ||
543 | command.Parameters.Add(database.CreateParameter("inventoryID", item.ID)); | ||
544 | command.Parameters.Add(database.CreateParameter("assetID", item.AssetID)); | ||
545 | command.Parameters.Add(database.CreateParameter("assetType", item.AssetType)); | ||
546 | command.Parameters.Add(database.CreateParameter("parentFolderID", item.Folder)); | ||
547 | command.Parameters.Add(database.CreateParameter("avatarID", item.Owner)); | ||
548 | command.Parameters.Add(database.CreateParameter("inventoryName", itemName)); | ||
549 | command.Parameters.Add(database.CreateParameter("inventoryDescription", itemDesc)); | ||
550 | command.Parameters.Add(database.CreateParameter("inventoryNextPermissions", item.NextPermissions)); | ||
551 | command.Parameters.Add(database.CreateParameter("inventoryCurrentPermissions", item.CurrentPermissions)); | ||
552 | command.Parameters.Add(database.CreateParameter("invType", item.InvType)); | ||
553 | command.Parameters.Add(database.CreateParameter("creatorID", item.CreatorId)); | ||
554 | command.Parameters.Add(database.CreateParameter("inventoryBasePermissions", item.BasePermissions)); | ||
555 | command.Parameters.Add(database.CreateParameter("inventoryEveryOnePermissions", item.EveryOnePermissions)); | ||
556 | command.Parameters.Add(database.CreateParameter("inventoryGroupPermissions", item.GroupPermissions)); | ||
557 | command.Parameters.Add(database.CreateParameter("SalePrice", item.SalePrice)); | ||
558 | command.Parameters.Add(database.CreateParameter("SaleType", item.SaleType)); | ||
559 | command.Parameters.Add(database.CreateParameter("creationDate", item.CreationDate)); | ||
560 | command.Parameters.Add(database.CreateParameter("groupID", item.GroupID)); | ||
561 | command.Parameters.Add(database.CreateParameter("groupOwned", item.GroupOwned)); | ||
562 | command.Parameters.Add(database.CreateParameter("flags", item.Flags)); | ||
563 | conn.Open(); | ||
564 | try | ||
565 | { | ||
566 | command.ExecuteNonQuery(); | ||
567 | } | ||
568 | catch (Exception e) | ||
569 | { | ||
570 | m_log.Error("[INVENTORY DB]: Error updating item :" + e.Message); | ||
571 | } | ||
572 | } | ||
573 | } | ||
574 | |||
575 | // See IInventoryDataPlugin | ||
576 | |||
577 | /// <summary> | ||
578 | /// Delete an item in inventory database | ||
579 | /// </summary> | ||
580 | /// <param name="itemID">the item UUID</param> | ||
581 | public void deleteInventoryItem(UUID itemID) | ||
582 | { | ||
583 | string sql = @"DELETE FROM inventoryitems WHERE ""inventoryID""=:inventoryID"; | ||
584 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
585 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
586 | { | ||
587 | cmd.Parameters.Add(database.CreateParameter("inventoryID", itemID)); | ||
588 | try | ||
589 | { | ||
590 | conn.Open(); | ||
591 | cmd.ExecuteNonQuery(); | ||
592 | } | ||
593 | catch (Exception e) | ||
594 | { | ||
595 | m_log.Error("[INVENTORY DB]: Error deleting item :" + e.Message); | ||
596 | } | ||
597 | } | ||
598 | } | ||
599 | |||
600 | public InventoryItemBase queryInventoryItem(UUID itemID) | ||
601 | { | ||
602 | return getInventoryItem(itemID); | ||
603 | } | ||
604 | |||
605 | public InventoryFolderBase queryInventoryFolder(UUID folderID) | ||
606 | { | ||
607 | return getInventoryFolder(folderID); | ||
608 | } | ||
609 | |||
610 | /// <summary> | ||
611 | /// Returns all activated gesture-items in the inventory of the specified avatar. | ||
612 | /// </summary> | ||
613 | /// <param name="avatarID">The <see cref="UUID"/> of the avatar</param> | ||
614 | /// <returns> | ||
615 | /// The list of gestures (<see cref="InventoryItemBase"/>s) | ||
616 | /// </returns> | ||
617 | public List<InventoryItemBase> fetchActiveGestures(UUID avatarID) | ||
618 | { | ||
619 | string sql = @"SELECT * FROM inventoryitems WHERE ""avatarID"" = :uuid AND ""assetType"" = :assetType and flags = 1"; | ||
620 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
621 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
622 | { | ||
623 | cmd.Parameters.Add(database.CreateParameter("uuid", avatarID)); | ||
624 | cmd.Parameters.Add(database.CreateParameter("assetType", (int)AssetType.Gesture)); | ||
625 | conn.Open(); | ||
626 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
627 | { | ||
628 | List<InventoryItemBase> gestureList = new List<InventoryItemBase>(); | ||
629 | while (reader.Read()) | ||
630 | { | ||
631 | gestureList.Add(readInventoryItem(reader)); | ||
632 | } | ||
633 | return gestureList; | ||
634 | } | ||
635 | } | ||
636 | } | ||
637 | |||
638 | #endregion | ||
639 | |||
640 | #region Private methods | ||
641 | |||
642 | /// <summary> | ||
643 | /// Delete an item in inventory database | ||
644 | /// </summary> | ||
645 | /// <param name="folderID">the item ID</param> | ||
646 | /// <param name="connection">connection to the database</param> | ||
647 | private void DeleteItemsInFolder(UUID folderID, NpgsqlConnection connection) | ||
648 | { | ||
649 | using (NpgsqlCommand command = new NpgsqlCommand(@"DELETE FROM inventoryitems WHERE ""folderID""=:folderID", connection)) | ||
650 | { | ||
651 | command.Parameters.Add(database.CreateParameter("folderID", folderID)); | ||
652 | |||
653 | try | ||
654 | { | ||
655 | command.ExecuteNonQuery(); | ||
656 | } | ||
657 | catch (Exception e) | ||
658 | { | ||
659 | m_log.Error("[INVENTORY DB] Error deleting item :" + e.Message); | ||
660 | } | ||
661 | } | ||
662 | } | ||
663 | |||
664 | /// <summary> | ||
665 | /// Gets the folder hierarchy in a loop. | ||
666 | /// </summary> | ||
667 | /// <param name="parentID">parent ID.</param> | ||
668 | /// <param name="command">SQL command/connection to database</param> | ||
669 | /// <returns></returns> | ||
670 | private static List<InventoryFolderBase> getFolderHierarchy(UUID parentID, NpgsqlCommand command) | ||
671 | { | ||
672 | command.Parameters["parentID"].Value = parentID.Guid; //.ToString(); | ||
673 | |||
674 | List<InventoryFolderBase> folders = getInventoryFolders(command); | ||
675 | |||
676 | if (folders.Count > 0) | ||
677 | { | ||
678 | List<InventoryFolderBase> tempFolders = new List<InventoryFolderBase>(); | ||
679 | |||
680 | foreach (InventoryFolderBase folderBase in folders) | ||
681 | { | ||
682 | tempFolders.AddRange(getFolderHierarchy(folderBase.ID, command)); | ||
683 | } | ||
684 | |||
685 | if (tempFolders.Count > 0) | ||
686 | { | ||
687 | folders.AddRange(tempFolders); | ||
688 | } | ||
689 | } | ||
690 | return folders; | ||
691 | } | ||
692 | |||
693 | /// <summary> | ||
694 | /// Gets the inventory folders. | ||
695 | /// </summary> | ||
696 | /// <param name="parentID">parentID, use UUID.Zero to get root</param> | ||
697 | /// <param name="user">user id, use UUID.Zero, if you want all folders from a parentID.</param> | ||
698 | /// <returns></returns> | ||
699 | private List<InventoryFolderBase> getInventoryFolders(UUID parentID, UUID user) | ||
700 | { | ||
701 | string sql = @"SELECT * FROM inventoryfolders WHERE ""parentFolderID"" = :parentID AND ""agentID"" = :uuid"; | ||
702 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
703 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) | ||
704 | { | ||
705 | if (user == UUID.Zero) | ||
706 | { | ||
707 | command.Parameters.Add(database.CreateParameter("uuid", "%")); | ||
708 | } | ||
709 | else | ||
710 | { | ||
711 | command.Parameters.Add(database.CreateParameter("uuid", user)); | ||
712 | } | ||
713 | command.Parameters.Add(database.CreateParameter("parentID", parentID)); | ||
714 | conn.Open(); | ||
715 | return getInventoryFolders(command); | ||
716 | } | ||
717 | } | ||
718 | |||
719 | /// <summary> | ||
720 | /// Gets the inventory folders. | ||
721 | /// </summary> | ||
722 | /// <param name="command">SQLcommand.</param> | ||
723 | /// <returns></returns> | ||
724 | private static List<InventoryFolderBase> getInventoryFolders(NpgsqlCommand command) | ||
725 | { | ||
726 | using (NpgsqlDataReader reader = command.ExecuteReader()) | ||
727 | { | ||
728 | |||
729 | List<InventoryFolderBase> items = new List<InventoryFolderBase>(); | ||
730 | while (reader.Read()) | ||
731 | { | ||
732 | items.Add(readInventoryFolder(reader)); | ||
733 | } | ||
734 | return items; | ||
735 | } | ||
736 | } | ||
737 | |||
738 | /// <summary> | ||
739 | /// Reads a list of inventory folders returned by a query. | ||
740 | /// </summary> | ||
741 | /// <param name="reader">A PGSQL Data Reader</param> | ||
742 | /// <returns>A List containing inventory folders</returns> | ||
743 | protected static InventoryFolderBase readInventoryFolder(NpgsqlDataReader reader) | ||
744 | { | ||
745 | try | ||
746 | { | ||
747 | InventoryFolderBase folder = new InventoryFolderBase(); | ||
748 | folder.Owner = DBGuid.FromDB(reader["agentID"]); | ||
749 | folder.ParentID = DBGuid.FromDB(reader["parentFolderID"]); | ||
750 | folder.ID = DBGuid.FromDB(reader["folderID"]); | ||
751 | folder.Name = (string)reader["folderName"]; | ||
752 | folder.Type = (short)reader["type"]; | ||
753 | folder.Version = Convert.ToUInt16(reader["version"]); | ||
754 | |||
755 | return folder; | ||
756 | } | ||
757 | catch (Exception e) | ||
758 | { | ||
759 | m_log.Error("[INVENTORY DB] Error reading inventory folder :" + e.Message); | ||
760 | } | ||
761 | |||
762 | return null; | ||
763 | } | ||
764 | |||
765 | /// <summary> | ||
766 | /// Reads a one item from an SQL result | ||
767 | /// </summary> | ||
768 | /// <param name="reader">The SQL Result</param> | ||
769 | /// <returns>the item read</returns> | ||
770 | private static InventoryItemBase readInventoryItem(IDataRecord reader) | ||
771 | { | ||
772 | try | ||
773 | { | ||
774 | InventoryItemBase item = new InventoryItemBase(); | ||
775 | |||
776 | item.ID = DBGuid.FromDB(reader["inventoryID"]); | ||
777 | item.AssetID = DBGuid.FromDB(reader["assetID"]); | ||
778 | item.AssetType = Convert.ToInt32(reader["assetType"].ToString()); | ||
779 | item.Folder = DBGuid.FromDB(reader["parentFolderID"]); | ||
780 | item.Owner = DBGuid.FromDB(reader["avatarID"]); | ||
781 | item.Name = reader["inventoryName"].ToString(); | ||
782 | item.Description = reader["inventoryDescription"].ToString(); | ||
783 | item.NextPermissions = Convert.ToUInt32(reader["inventoryNextPermissions"]); | ||
784 | item.CurrentPermissions = Convert.ToUInt32(reader["inventoryCurrentPermissions"]); | ||
785 | item.InvType = Convert.ToInt32(reader["invType"].ToString()); | ||
786 | item.CreatorId = reader["creatorID"].ToString(); | ||
787 | item.BasePermissions = Convert.ToUInt32(reader["inventoryBasePermissions"]); | ||
788 | item.EveryOnePermissions = Convert.ToUInt32(reader["inventoryEveryOnePermissions"]); | ||
789 | item.GroupPermissions = Convert.ToUInt32(reader["inventoryGroupPermissions"]); | ||
790 | item.SalePrice = Convert.ToInt32(reader["salePrice"]); | ||
791 | item.SaleType = Convert.ToByte(reader["saleType"]); | ||
792 | item.CreationDate = Convert.ToInt32(reader["creationDate"]); | ||
793 | item.GroupID = DBGuid.FromDB(reader["groupID"]); | ||
794 | item.GroupOwned = Convert.ToBoolean(reader["groupOwned"]); | ||
795 | item.Flags = Convert.ToUInt32(reader["flags"]); | ||
796 | |||
797 | return item; | ||
798 | } | ||
799 | catch (NpgsqlException e) | ||
800 | { | ||
801 | m_log.Error("[INVENTORY DB]: Error reading inventory item :" + e.Message); | ||
802 | } | ||
803 | |||
804 | return null; | ||
805 | } | ||
806 | |||
807 | /// <summary> | ||
808 | /// Delete a folder in inventory databasae | ||
809 | /// </summary> | ||
810 | /// <param name="folderID">the folder UUID</param> | ||
811 | /// <param name="connection">connection to database</param> | ||
812 | private void DeleteOneFolder(UUID folderID, NpgsqlConnection connection) | ||
813 | { | ||
814 | try | ||
815 | { | ||
816 | using (NpgsqlCommand command = new NpgsqlCommand(@"DELETE FROM inventoryfolders WHERE ""folderID""=:folderID and type=-1", connection)) | ||
817 | { | ||
818 | command.Parameters.Add(database.CreateParameter("folderID", folderID)); | ||
819 | |||
820 | command.ExecuteNonQuery(); | ||
821 | } | ||
822 | } | ||
823 | catch (NpgsqlException e) | ||
824 | { | ||
825 | m_log.Error("[INVENTORY DB]: Error deleting folder :" + e.Message); | ||
826 | } | ||
827 | } | ||
828 | |||
829 | #endregion | ||
830 | } | ||
831 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLManager.cs b/OpenSim/Data/PGSQL/PGSQLManager.cs new file mode 100644 index 0000000..46f835a --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLManager.cs | |||
@@ -0,0 +1,354 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.IO; | ||
32 | using System.Reflection; | ||
33 | using OpenSim.Framework; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using Npgsql; | ||
37 | using NpgsqlTypes; | ||
38 | |||
39 | namespace OpenSim.Data.PGSQL | ||
40 | { | ||
41 | /// <summary> | ||
42 | /// A management class for the MS SQL Storage Engine | ||
43 | /// </summary> | ||
44 | public class PGSQLManager | ||
45 | { | ||
46 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | /// <summary> | ||
49 | /// Connection string for ADO.net | ||
50 | /// </summary> | ||
51 | private readonly string connectionString; | ||
52 | |||
53 | /// <summary> | ||
54 | /// Initialize the manager and set the connectionstring | ||
55 | /// </summary> | ||
56 | /// <param name="connection"></param> | ||
57 | public PGSQLManager(string connection) | ||
58 | { | ||
59 | connectionString = connection; | ||
60 | InitializeMonoSecurity(); | ||
61 | } | ||
62 | |||
63 | public void InitializeMonoSecurity() | ||
64 | { | ||
65 | if (!Util.IsPlatformMono) | ||
66 | { | ||
67 | if (AppDomain.CurrentDomain.GetData("MonoSecurityPostgresAdded") == null) | ||
68 | { | ||
69 | AppDomain.CurrentDomain.SetData("MonoSecurityPostgresAdded", "true"); | ||
70 | |||
71 | AppDomain currentDomain = AppDomain.CurrentDomain; | ||
72 | currentDomain.AssemblyResolve += new ResolveEventHandler(ResolveEventHandlerMonoSec); | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | |||
77 | private System.Reflection.Assembly ResolveEventHandlerMonoSec(object sender, ResolveEventArgs args) | ||
78 | { | ||
79 | Assembly MyAssembly = null; | ||
80 | |||
81 | if (args.Name.Substring(0, args.Name.IndexOf(",")) == "Mono.Security") | ||
82 | { | ||
83 | MyAssembly = Assembly.LoadFrom("lib/NET/Mono.Security.dll"); | ||
84 | } | ||
85 | |||
86 | //Return the loaded assembly. | ||
87 | return MyAssembly; | ||
88 | } | ||
89 | |||
90 | /// <summary> | ||
91 | /// Type conversion to a SQLDbType functions | ||
92 | /// </summary> | ||
93 | /// <param name="type"></param> | ||
94 | /// <returns></returns> | ||
95 | internal NpgsqlDbType DbtypeFromType(Type type) | ||
96 | { | ||
97 | if (type == typeof(string)) | ||
98 | { | ||
99 | return NpgsqlDbType.Varchar; | ||
100 | } | ||
101 | if (type == typeof(double)) | ||
102 | { | ||
103 | return NpgsqlDbType.Double; | ||
104 | } | ||
105 | if (type == typeof(Single)) | ||
106 | { | ||
107 | return NpgsqlDbType.Double; | ||
108 | } | ||
109 | if (type == typeof(int)) | ||
110 | { | ||
111 | return NpgsqlDbType.Integer; | ||
112 | } | ||
113 | if (type == typeof(bool)) | ||
114 | { | ||
115 | return NpgsqlDbType.Boolean; | ||
116 | } | ||
117 | if (type == typeof(UUID)) | ||
118 | { | ||
119 | return NpgsqlDbType.Uuid; | ||
120 | } | ||
121 | if (type == typeof(byte)) | ||
122 | { | ||
123 | return NpgsqlDbType.Smallint; | ||
124 | } | ||
125 | if (type == typeof(sbyte)) | ||
126 | { | ||
127 | return NpgsqlDbType.Integer; | ||
128 | } | ||
129 | if (type == typeof(Byte[])) | ||
130 | { | ||
131 | return NpgsqlDbType.Bytea; | ||
132 | } | ||
133 | if (type == typeof(uint) || type == typeof(ushort)) | ||
134 | { | ||
135 | return NpgsqlDbType.Integer; | ||
136 | } | ||
137 | if (type == typeof(ulong)) | ||
138 | { | ||
139 | return NpgsqlDbType.Bigint; | ||
140 | } | ||
141 | if (type == typeof(DateTime)) | ||
142 | { | ||
143 | return NpgsqlDbType.Timestamp; | ||
144 | } | ||
145 | |||
146 | return NpgsqlDbType.Varchar; | ||
147 | } | ||
148 | |||
149 | internal NpgsqlDbType DbtypeFromString(Type type, string PGFieldType) | ||
150 | { | ||
151 | if (PGFieldType == "") | ||
152 | { | ||
153 | return DbtypeFromType(type); | ||
154 | } | ||
155 | |||
156 | if (PGFieldType == "character varying") | ||
157 | { | ||
158 | return NpgsqlDbType.Varchar; | ||
159 | } | ||
160 | if (PGFieldType == "double precision") | ||
161 | { | ||
162 | return NpgsqlDbType.Double; | ||
163 | } | ||
164 | if (PGFieldType == "integer") | ||
165 | { | ||
166 | return NpgsqlDbType.Integer; | ||
167 | } | ||
168 | if (PGFieldType == "smallint") | ||
169 | { | ||
170 | return NpgsqlDbType.Smallint; | ||
171 | } | ||
172 | if (PGFieldType == "boolean") | ||
173 | { | ||
174 | return NpgsqlDbType.Boolean; | ||
175 | } | ||
176 | if (PGFieldType == "uuid") | ||
177 | { | ||
178 | return NpgsqlDbType.Uuid; | ||
179 | } | ||
180 | if (PGFieldType == "bytea") | ||
181 | { | ||
182 | return NpgsqlDbType.Bytea; | ||
183 | } | ||
184 | |||
185 | return DbtypeFromType(type); | ||
186 | } | ||
187 | |||
188 | /// <summary> | ||
189 | /// Creates value for parameter. | ||
190 | /// </summary> | ||
191 | /// <param name="value">The value.</param> | ||
192 | /// <returns></returns> | ||
193 | private static object CreateParameterValue(object value) | ||
194 | { | ||
195 | Type valueType = value.GetType(); | ||
196 | |||
197 | if (valueType == typeof(UUID)) //TODO check if this works | ||
198 | { | ||
199 | return ((UUID) value).Guid; | ||
200 | } | ||
201 | if (valueType == typeof(UUID)) | ||
202 | { | ||
203 | return ((UUID)value).Guid; | ||
204 | } | ||
205 | if (valueType == typeof(bool)) | ||
206 | { | ||
207 | return (bool)value; | ||
208 | } | ||
209 | if (valueType == typeof(Byte[])) | ||
210 | { | ||
211 | return value; | ||
212 | } | ||
213 | if (valueType == typeof(int)) | ||
214 | { | ||
215 | return value; | ||
216 | } | ||
217 | return value; | ||
218 | } | ||
219 | |||
220 | /// <summary> | ||
221 | /// Create value for parameter based on PGSQL Schema | ||
222 | /// </summary> | ||
223 | /// <param name="value"></param> | ||
224 | /// <param name="PGFieldType"></param> | ||
225 | /// <returns></returns> | ||
226 | internal static object CreateParameterValue(object value, string PGFieldType) | ||
227 | { | ||
228 | if (PGFieldType == "uuid") | ||
229 | { | ||
230 | UUID uidout; | ||
231 | UUID.TryParse(value.ToString(), out uidout); | ||
232 | return uidout; | ||
233 | } | ||
234 | if (PGFieldType == "integer") | ||
235 | { | ||
236 | int intout; | ||
237 | int.TryParse(value.ToString(), out intout); | ||
238 | return intout; | ||
239 | } | ||
240 | if (PGFieldType == "boolean") | ||
241 | { | ||
242 | return (value.ToString() == "true"); | ||
243 | } | ||
244 | if (PGFieldType == "timestamp with time zone") | ||
245 | { | ||
246 | return (DateTime)value; | ||
247 | } | ||
248 | if (PGFieldType == "timestamp without time zone") | ||
249 | { | ||
250 | return (DateTime)value; | ||
251 | } | ||
252 | if (PGFieldType == "double precision") | ||
253 | { | ||
254 | return (Double)value; | ||
255 | } | ||
256 | return CreateParameterValue(value); | ||
257 | } | ||
258 | |||
259 | /// <summary> | ||
260 | /// Create a parameter for a command | ||
261 | /// </summary> | ||
262 | /// <param name="parameterName">Name of the parameter.</param> | ||
263 | /// <param name="parameterObject">parameter object.</param> | ||
264 | /// <returns></returns> | ||
265 | internal NpgsqlParameter CreateParameter(string parameterName, object parameterObject) | ||
266 | { | ||
267 | return CreateParameter(parameterName, parameterObject, false); | ||
268 | } | ||
269 | |||
270 | /// <summary> | ||
271 | /// Creates the parameter for a command. | ||
272 | /// </summary> | ||
273 | /// <param name="parameterName">Name of the parameter.</param> | ||
274 | /// <param name="parameterObject">parameter object.</param> | ||
275 | /// <param name="parameterOut">if set to <c>true</c> parameter is a output parameter</param> | ||
276 | /// <returns></returns> | ||
277 | internal NpgsqlParameter CreateParameter(string parameterName, object parameterObject, bool parameterOut) | ||
278 | { | ||
279 | //Tweak so we dont always have to add : sign | ||
280 | if (parameterName.StartsWith(":")) parameterName = parameterName.Replace(":",""); | ||
281 | |||
282 | //HACK if object is null, it is turned into a string, there are no nullable type till now | ||
283 | if (parameterObject == null) parameterObject = ""; | ||
284 | |||
285 | NpgsqlParameter parameter = new NpgsqlParameter(parameterName, DbtypeFromType(parameterObject.GetType())); | ||
286 | |||
287 | if (parameterOut) | ||
288 | { | ||
289 | parameter.Direction = ParameterDirection.Output; | ||
290 | } | ||
291 | else | ||
292 | { | ||
293 | parameter.Direction = ParameterDirection.Input; | ||
294 | parameter.Value = CreateParameterValue(parameterObject); | ||
295 | } | ||
296 | |||
297 | return parameter; | ||
298 | } | ||
299 | |||
300 | /// <summary> | ||
301 | /// Create a parameter with PGSQL schema type | ||
302 | /// </summary> | ||
303 | /// <param name="parameterName"></param> | ||
304 | /// <param name="parameterObject"></param> | ||
305 | /// <param name="PGFieldType"></param> | ||
306 | /// <returns></returns> | ||
307 | internal NpgsqlParameter CreateParameter(string parameterName, object parameterObject, string PGFieldType) | ||
308 | { | ||
309 | //Tweak so we dont always have to add : sign | ||
310 | if (parameterName.StartsWith(":")) parameterName = parameterName.Replace(":", ""); | ||
311 | |||
312 | //HACK if object is null, it is turned into a string, there are no nullable type till now | ||
313 | if (parameterObject == null) parameterObject = ""; | ||
314 | |||
315 | NpgsqlParameter parameter = new NpgsqlParameter(parameterName, DbtypeFromString(parameterObject.GetType(), PGFieldType)); | ||
316 | |||
317 | parameter.Direction = ParameterDirection.Input; | ||
318 | parameter.Value = CreateParameterValue(parameterObject, PGFieldType); | ||
319 | |||
320 | return parameter; | ||
321 | } | ||
322 | |||
323 | /// <summary> | ||
324 | /// Checks if we need to do some migrations to the database | ||
325 | /// </summary> | ||
326 | /// <param name="migrationStore">migrationStore.</param> | ||
327 | public void CheckMigration(string migrationStore) | ||
328 | { | ||
329 | using (NpgsqlConnection connection = new NpgsqlConnection(connectionString)) | ||
330 | { | ||
331 | connection.Open(); | ||
332 | Assembly assem = GetType().Assembly; | ||
333 | PGSQLMigration migration = new PGSQLMigration(connection, assem, migrationStore); | ||
334 | |||
335 | migration.Update(); | ||
336 | } | ||
337 | } | ||
338 | |||
339 | /// <summary> | ||
340 | /// Returns the version of this DB provider | ||
341 | /// </summary> | ||
342 | /// <returns>A string containing the DB provider</returns> | ||
343 | public string getVersion() | ||
344 | { | ||
345 | Module module = GetType().Module; | ||
346 | // string dllName = module.Assembly.ManifestModule.Name; | ||
347 | Version dllVersion = module.Assembly.GetName().Version; | ||
348 | |||
349 | return | ||
350 | string.Format("{0}.{1}.{2}.{3}", dllVersion.Major, dllVersion.Minor, dllVersion.Build, | ||
351 | dllVersion.Revision); | ||
352 | } | ||
353 | } | ||
354 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLMigration.cs b/OpenSim/Data/PGSQL/PGSQLMigration.cs new file mode 100644 index 0000000..709fde0 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLMigration.cs | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using Npgsql; | ||
29 | using System; | ||
30 | using System.Data; | ||
31 | using System.Data.Common; | ||
32 | using System.Reflection; | ||
33 | |||
34 | namespace OpenSim.Data.PGSQL | ||
35 | { | ||
36 | public class PGSQLMigration : Migration | ||
37 | { | ||
38 | public PGSQLMigration(NpgsqlConnection conn, Assembly assem, string type) | ||
39 | : base(conn, assem, type) | ||
40 | { | ||
41 | } | ||
42 | |||
43 | public PGSQLMigration(NpgsqlConnection conn, Assembly assem, string subtype, string type) | ||
44 | : base(conn, assem, subtype, type) | ||
45 | { | ||
46 | } | ||
47 | |||
48 | protected override int FindVersion(DbConnection conn, string type) | ||
49 | { | ||
50 | int version = 0; | ||
51 | NpgsqlConnection lcConn = (NpgsqlConnection)conn; | ||
52 | |||
53 | using (NpgsqlCommand cmd = lcConn.CreateCommand()) | ||
54 | { | ||
55 | try | ||
56 | { | ||
57 | cmd.CommandText = "select version from migrations where name = '" + type + "' " + | ||
58 | " order by version desc limit 1"; //Must be | ||
59 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
60 | { | ||
61 | if (reader.Read()) | ||
62 | { | ||
63 | version = Convert.ToInt32(reader["version"]); | ||
64 | } | ||
65 | reader.Close(); | ||
66 | } | ||
67 | } | ||
68 | catch | ||
69 | { | ||
70 | // Return -1 to indicate table does not exist | ||
71 | return -1; | ||
72 | } | ||
73 | } | ||
74 | return version; | ||
75 | } | ||
76 | |||
77 | protected override void ExecuteScript(DbConnection conn, string[] script) | ||
78 | { | ||
79 | if (!(conn is NpgsqlConnection)) | ||
80 | { | ||
81 | base.ExecuteScript(conn, script); | ||
82 | return; | ||
83 | } | ||
84 | |||
85 | foreach (string sql in script) | ||
86 | { | ||
87 | try | ||
88 | { | ||
89 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, (NpgsqlConnection)conn)) | ||
90 | { | ||
91 | cmd.ExecuteNonQuery(); | ||
92 | } | ||
93 | } | ||
94 | catch (Exception) | ||
95 | { | ||
96 | throw new Exception(sql); | ||
97 | |||
98 | } | ||
99 | } | ||
100 | } | ||
101 | } | ||
102 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLOfflineIMData.cs b/OpenSim/Data/PGSQL/PGSQLOfflineIMData.cs new file mode 100644 index 0000000..82e5ed8 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLOfflineIMData.cs | |||
@@ -0,0 +1,56 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Reflection; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using Npgsql; | ||
35 | |||
36 | namespace OpenSim.Data.PGSQL | ||
37 | { | ||
38 | public class PGSQLOfflineIMData : PGSQLGenericTableHandler<OfflineIMData>, IOfflineIMData | ||
39 | { | ||
40 | public PGSQLOfflineIMData(string connectionString, string realm) | ||
41 | : base(connectionString, realm, "IM_Store") | ||
42 | { | ||
43 | } | ||
44 | |||
45 | public void DeleteOld() | ||
46 | { | ||
47 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
48 | { | ||
49 | cmd.CommandText = String.Format("delete from {0} where \"TMStamp\" < CURRENT_DATE - INTERVAL '2 week'", m_Realm); | ||
50 | |||
51 | ExecuteNonQuery(cmd); | ||
52 | } | ||
53 | |||
54 | } | ||
55 | } | ||
56 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLPresenceData.cs b/OpenSim/Data/PGSQL/PGSQLPresenceData.cs new file mode 100755 index 0000000..0376585 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLPresenceData.cs | |||
@@ -0,0 +1,116 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Reflection; | ||
32 | using System.Threading; | ||
33 | using log4net; | ||
34 | using OpenMetaverse; | ||
35 | using OpenSim.Framework; | ||
36 | using Npgsql; | ||
37 | |||
38 | namespace OpenSim.Data.PGSQL | ||
39 | { | ||
40 | /// <summary> | ||
41 | /// A PGSQL Interface for the Presence Server | ||
42 | /// </summary> | ||
43 | public class PGSQLPresenceData : PGSQLGenericTableHandler<PresenceData>, | ||
44 | IPresenceData | ||
45 | { | ||
46 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | public PGSQLPresenceData(string connectionString, string realm) : | ||
49 | base(connectionString, realm, "Presence") | ||
50 | { | ||
51 | } | ||
52 | |||
53 | public PresenceData Get(UUID sessionID) | ||
54 | { | ||
55 | PresenceData[] ret = Get("SessionID", sessionID.ToString()); | ||
56 | |||
57 | if (ret.Length == 0) | ||
58 | return null; | ||
59 | |||
60 | return ret[0]; | ||
61 | } | ||
62 | |||
63 | public void LogoutRegionAgents(UUID regionID) | ||
64 | { | ||
65 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
66 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
67 | { | ||
68 | |||
69 | cmd.CommandText = String.Format("DELETE FROM {0} WHERE \"RegionID\" = :regionID", m_Realm); | ||
70 | |||
71 | cmd.Parameters.Add(m_database.CreateParameter("RegionID", regionID)); | ||
72 | cmd.Connection = conn; | ||
73 | conn.Open(); | ||
74 | cmd.ExecuteNonQuery(); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | public bool ReportAgent(UUID sessionID, UUID regionID) | ||
79 | { | ||
80 | PresenceData[] pd = Get("SessionID", sessionID.ToString()); | ||
81 | if (pd.Length == 0) | ||
82 | return false; | ||
83 | |||
84 | if (regionID == UUID.Zero) | ||
85 | return false; | ||
86 | |||
87 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
88 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
89 | { | ||
90 | |||
91 | cmd.CommandText = String.Format("UPDATE {0} SET \"RegionID\" = :regionID, \"LastSeen\" = now() WHERE \"SessionID\" = :sessionID", m_Realm); | ||
92 | |||
93 | cmd.Parameters.Add(m_database.CreateParameter("SessionID", sessionID)); | ||
94 | cmd.Parameters.Add(m_database.CreateParameter("RegionID", regionID)); | ||
95 | cmd.Connection = conn; | ||
96 | conn.Open(); | ||
97 | if (cmd.ExecuteNonQuery() == 0) | ||
98 | return false; | ||
99 | } | ||
100 | return true; | ||
101 | } | ||
102 | |||
103 | public bool VerifyAgent(UUID agentId, UUID secureSessionID) | ||
104 | { | ||
105 | PresenceData[] ret = Get("SecureSessionID", secureSessionID.ToString()); | ||
106 | |||
107 | if (ret.Length == 0) | ||
108 | return false; | ||
109 | |||
110 | if(ret[0].UserID != agentId.ToString()) | ||
111 | return false; | ||
112 | |||
113 | return true; | ||
114 | } | ||
115 | } | ||
116 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLRegionData.cs b/OpenSim/Data/PGSQL/PGSQLRegionData.cs new file mode 100644 index 0000000..b3076f0 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLRegionData.cs | |||
@@ -0,0 +1,392 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ''AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Drawing; | ||
32 | using System.IO; | ||
33 | using System.Reflection; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using RegionFlags = OpenSim.Framework.RegionFlags; | ||
40 | using Npgsql; | ||
41 | |||
42 | namespace OpenSim.Data.PGSQL | ||
43 | { | ||
44 | /// <summary> | ||
45 | /// A PGSQL Interface for the Region Server. | ||
46 | /// </summary> | ||
47 | public class PGSQLRegionData : IRegionData | ||
48 | { | ||
49 | private string m_Realm; | ||
50 | private List<string> m_ColumnNames = null; | ||
51 | private string m_ConnectionString; | ||
52 | private PGSQLManager m_database; | ||
53 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
54 | |||
55 | protected Dictionary<string, string> m_FieldTypes = new Dictionary<string, string>(); | ||
56 | |||
57 | protected virtual Assembly Assembly | ||
58 | { | ||
59 | get { return GetType().Assembly; } | ||
60 | } | ||
61 | |||
62 | public PGSQLRegionData(string connectionString, string realm) | ||
63 | { | ||
64 | m_Realm = realm; | ||
65 | m_ConnectionString = connectionString; | ||
66 | m_database = new PGSQLManager(connectionString); | ||
67 | |||
68 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
69 | { | ||
70 | conn.Open(); | ||
71 | Migration m = new Migration(conn, GetType().Assembly, "GridStore"); | ||
72 | m.Update(); | ||
73 | } | ||
74 | LoadFieldTypes(); | ||
75 | } | ||
76 | |||
77 | private void LoadFieldTypes() | ||
78 | { | ||
79 | m_FieldTypes = new Dictionary<string, string>(); | ||
80 | |||
81 | string query = string.Format(@"select column_name,data_type | ||
82 | from INFORMATION_SCHEMA.COLUMNS | ||
83 | where table_name = lower('{0}'); | ||
84 | |||
85 | ", m_Realm); | ||
86 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
87 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, conn)) | ||
88 | { | ||
89 | conn.Open(); | ||
90 | using (NpgsqlDataReader rdr = cmd.ExecuteReader()) | ||
91 | { | ||
92 | while (rdr.Read()) | ||
93 | { | ||
94 | // query produces 0 to many rows of single column, so always add the first item in each row | ||
95 | m_FieldTypes.Add((string)rdr[0], (string)rdr[1]); | ||
96 | } | ||
97 | } | ||
98 | } | ||
99 | } | ||
100 | |||
101 | public List<RegionData> Get(string regionName, UUID scopeID) | ||
102 | { | ||
103 | string sql = "select * from "+m_Realm+" where lower(\"regionName\") like lower(:regionName) "; | ||
104 | if (scopeID != UUID.Zero) | ||
105 | sql += " and \"ScopeID\" = :scopeID"; | ||
106 | sql += " order by lower(\"regionName\")"; | ||
107 | |||
108 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
109 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
110 | { | ||
111 | cmd.Parameters.Add(m_database.CreateParameter("regionName", regionName)); | ||
112 | if (scopeID != UUID.Zero) | ||
113 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); | ||
114 | conn.Open(); | ||
115 | return RunCommand(cmd); | ||
116 | } | ||
117 | } | ||
118 | |||
119 | public RegionData Get(int posX, int posY, UUID scopeID) | ||
120 | { | ||
121 | string sql = "select * from "+m_Realm+" where \"locX\" = :posX and \"locY\" = :posY"; | ||
122 | if (scopeID != UUID.Zero) | ||
123 | sql += " and \"ScopeID\" = :scopeID"; | ||
124 | |||
125 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
126 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
127 | { | ||
128 | cmd.Parameters.Add(m_database.CreateParameter("posX", posX)); | ||
129 | cmd.Parameters.Add(m_database.CreateParameter("posY", posY)); | ||
130 | if (scopeID != UUID.Zero) | ||
131 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); | ||
132 | conn.Open(); | ||
133 | List<RegionData> ret = RunCommand(cmd); | ||
134 | if (ret.Count == 0) | ||
135 | return null; | ||
136 | |||
137 | return ret[0]; | ||
138 | } | ||
139 | } | ||
140 | |||
141 | public RegionData Get(UUID regionID, UUID scopeID) | ||
142 | { | ||
143 | string sql = "select * from "+m_Realm+" where uuid = :regionID"; | ||
144 | if (scopeID != UUID.Zero) | ||
145 | sql += " and \"ScopeID\" = :scopeID"; | ||
146 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
147 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
148 | { | ||
149 | cmd.Parameters.Add(m_database.CreateParameter("regionID", regionID)); | ||
150 | if (scopeID != UUID.Zero) | ||
151 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); | ||
152 | conn.Open(); | ||
153 | List<RegionData> ret = RunCommand(cmd); | ||
154 | if (ret.Count == 0) | ||
155 | return null; | ||
156 | |||
157 | return ret[0]; | ||
158 | } | ||
159 | } | ||
160 | |||
161 | public List<RegionData> Get(int startX, int startY, int endX, int endY, UUID scopeID) | ||
162 | { | ||
163 | string sql = "select * from "+m_Realm+" where \"locX\" between :startX and :endX and \"locY\" between :startY and :endY"; | ||
164 | if (scopeID != UUID.Zero) | ||
165 | sql += " and \"ScopeID\" = :scopeID"; | ||
166 | |||
167 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
168 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
169 | { | ||
170 | cmd.Parameters.Add(m_database.CreateParameter("startX", startX)); | ||
171 | cmd.Parameters.Add(m_database.CreateParameter("startY", startY)); | ||
172 | cmd.Parameters.Add(m_database.CreateParameter("endX", endX)); | ||
173 | cmd.Parameters.Add(m_database.CreateParameter("endY", endY)); | ||
174 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); | ||
175 | conn.Open(); | ||
176 | return RunCommand(cmd); | ||
177 | } | ||
178 | } | ||
179 | |||
180 | public List<RegionData> RunCommand(NpgsqlCommand cmd) | ||
181 | { | ||
182 | List<RegionData> retList = new List<RegionData>(); | ||
183 | |||
184 | NpgsqlDataReader result = cmd.ExecuteReader(); | ||
185 | |||
186 | while (result.Read()) | ||
187 | { | ||
188 | RegionData ret = new RegionData(); | ||
189 | ret.Data = new Dictionary<string, object>(); | ||
190 | |||
191 | UUID regionID; | ||
192 | UUID.TryParse(result["uuid"].ToString(), out regionID); | ||
193 | ret.RegionID = regionID; | ||
194 | UUID scope; | ||
195 | UUID.TryParse(result["ScopeID"].ToString(), out scope); | ||
196 | ret.ScopeID = scope; | ||
197 | ret.RegionName = result["regionName"].ToString(); | ||
198 | ret.posX = Convert.ToInt32(result["locX"]); | ||
199 | ret.posY = Convert.ToInt32(result["locY"]); | ||
200 | ret.sizeX = Convert.ToInt32(result["sizeX"]); | ||
201 | ret.sizeY = Convert.ToInt32(result["sizeY"]); | ||
202 | |||
203 | if (m_ColumnNames == null) | ||
204 | { | ||
205 | m_ColumnNames = new List<string>(); | ||
206 | |||
207 | DataTable schemaTable = result.GetSchemaTable(); | ||
208 | foreach (DataRow row in schemaTable.Rows) | ||
209 | m_ColumnNames.Add(row["ColumnName"].ToString()); | ||
210 | } | ||
211 | |||
212 | foreach (string s in m_ColumnNames) | ||
213 | { | ||
214 | if (s == "uuid") | ||
215 | continue; | ||
216 | if (s == "ScopeID") | ||
217 | continue; | ||
218 | if (s == "regionName") | ||
219 | continue; | ||
220 | if (s == "locX") | ||
221 | continue; | ||
222 | if (s == "locY") | ||
223 | continue; | ||
224 | |||
225 | ret.Data[s] = result[s].ToString(); | ||
226 | } | ||
227 | |||
228 | retList.Add(ret); | ||
229 | } | ||
230 | return retList; | ||
231 | } | ||
232 | |||
233 | public bool Store(RegionData data) | ||
234 | { | ||
235 | if (data.Data.ContainsKey("uuid")) | ||
236 | data.Data.Remove("uuid"); | ||
237 | if (data.Data.ContainsKey("ScopeID")) | ||
238 | data.Data.Remove("ScopeID"); | ||
239 | if (data.Data.ContainsKey("regionName")) | ||
240 | data.Data.Remove("regionName"); | ||
241 | if (data.Data.ContainsKey("posX")) | ||
242 | data.Data.Remove("posX"); | ||
243 | if (data.Data.ContainsKey("posY")) | ||
244 | data.Data.Remove("posY"); | ||
245 | if (data.Data.ContainsKey("sizeX")) | ||
246 | data.Data.Remove("sizeX"); | ||
247 | if (data.Data.ContainsKey("sizeY")) | ||
248 | data.Data.Remove("sizeY"); | ||
249 | if (data.Data.ContainsKey("locX")) | ||
250 | data.Data.Remove("locX"); | ||
251 | if (data.Data.ContainsKey("locY")) | ||
252 | data.Data.Remove("locY"); | ||
253 | |||
254 | string[] fields = new List<string>(data.Data.Keys).ToArray(); | ||
255 | |||
256 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
257 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
258 | { | ||
259 | |||
260 | string update = "update " + m_Realm + " set \"locX\"=:posX, \"locY\"=:posY, \"sizeX\"=:sizeX, \"sizeY\"=:sizeY "; | ||
261 | |||
262 | foreach (string field in fields) | ||
263 | { | ||
264 | |||
265 | update += ", "; | ||
266 | update += " \"" + field + "\" = :" + field; | ||
267 | |||
268 | if (m_FieldTypes.ContainsKey(field)) | ||
269 | cmd.Parameters.Add(m_database.CreateParameter(field, data.Data[field], m_FieldTypes[field])); | ||
270 | else | ||
271 | cmd.Parameters.Add(m_database.CreateParameter(field, data.Data[field])); | ||
272 | } | ||
273 | |||
274 | update += " where uuid = :regionID"; | ||
275 | |||
276 | if (data.ScopeID != UUID.Zero) | ||
277 | update += " and \"ScopeID\" = :scopeID"; | ||
278 | |||
279 | cmd.CommandText = update; | ||
280 | cmd.Connection = conn; | ||
281 | cmd.Parameters.Add(m_database.CreateParameter("regionID", data.RegionID)); | ||
282 | cmd.Parameters.Add(m_database.CreateParameter("regionName", data.RegionName)); | ||
283 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", data.ScopeID)); | ||
284 | cmd.Parameters.Add(m_database.CreateParameter("posX", data.posX)); | ||
285 | cmd.Parameters.Add(m_database.CreateParameter("posY", data.posY)); | ||
286 | cmd.Parameters.Add(m_database.CreateParameter("sizeX", data.sizeX)); | ||
287 | cmd.Parameters.Add(m_database.CreateParameter("sizeY", data.sizeY)); | ||
288 | conn.Open(); | ||
289 | try | ||
290 | { | ||
291 | if (cmd.ExecuteNonQuery() < 1) | ||
292 | { | ||
293 | string insert = "insert into " + m_Realm + " (uuid, \"ScopeID\", \"locX\", \"locY\", \"sizeX\", \"sizeY\", \"regionName\", \"" + | ||
294 | String.Join("\", \"", fields) + | ||
295 | "\") values (:regionID, :scopeID, :posX, :posY, :sizeX, :sizeY, :regionName, :" + String.Join(", :", fields) + ")"; | ||
296 | |||
297 | cmd.CommandText = insert; | ||
298 | |||
299 | try | ||
300 | { | ||
301 | if (cmd.ExecuteNonQuery() < 1) | ||
302 | { | ||
303 | return false; | ||
304 | } | ||
305 | } | ||
306 | catch (Exception ex) | ||
307 | { | ||
308 | m_log.Warn("[PGSQL Grid]: Error inserting into Regions table: " + ex.Message + ", INSERT sql: " + insert); | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | catch (Exception ex) | ||
313 | { | ||
314 | m_log.Warn("[PGSQL Grid]: Error updating Regions table: " + ex.Message + ", UPDATE sql: " + update); | ||
315 | } | ||
316 | } | ||
317 | |||
318 | return true; | ||
319 | } | ||
320 | |||
321 | public bool SetDataItem(UUID regionID, string item, string value) | ||
322 | { | ||
323 | string sql = "update " + m_Realm + | ||
324 | " set \"" + item + "\" = :" + item + " where uuid = :UUID"; | ||
325 | |||
326 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
327 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
328 | { | ||
329 | cmd.Parameters.Add(m_database.CreateParameter("" + item, value)); | ||
330 | cmd.Parameters.Add(m_database.CreateParameter("UUID", regionID)); | ||
331 | conn.Open(); | ||
332 | if (cmd.ExecuteNonQuery() > 0) | ||
333 | return true; | ||
334 | } | ||
335 | return false; | ||
336 | } | ||
337 | |||
338 | public bool Delete(UUID regionID) | ||
339 | { | ||
340 | string sql = "delete from " + m_Realm + | ||
341 | " where uuid = :UUID"; | ||
342 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
343 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
344 | { | ||
345 | cmd.Parameters.Add(m_database.CreateParameter("UUID", regionID)); | ||
346 | conn.Open(); | ||
347 | if (cmd.ExecuteNonQuery() > 0) | ||
348 | return true; | ||
349 | } | ||
350 | return false; | ||
351 | } | ||
352 | |||
353 | public List<RegionData> GetDefaultRegions(UUID scopeID) | ||
354 | { | ||
355 | return Get((int)RegionFlags.DefaultRegion, scopeID); | ||
356 | } | ||
357 | |||
358 | public List<RegionData> GetDefaultHypergridRegions(UUID scopeID) | ||
359 | { | ||
360 | return Get((int)RegionFlags.DefaultHGRegion, scopeID); | ||
361 | } | ||
362 | |||
363 | public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y) | ||
364 | { | ||
365 | List<RegionData> regions = Get((int)RegionFlags.FallbackRegion, scopeID); | ||
366 | RegionDataDistanceCompare distanceComparer = new RegionDataDistanceCompare(x, y); | ||
367 | regions.Sort(distanceComparer); | ||
368 | |||
369 | return regions; | ||
370 | } | ||
371 | |||
372 | public List<RegionData> GetHyperlinks(UUID scopeID) | ||
373 | { | ||
374 | return Get((int)RegionFlags.Hyperlink, scopeID); | ||
375 | } | ||
376 | |||
377 | private List<RegionData> Get(int regionFlags, UUID scopeID) | ||
378 | { | ||
379 | string sql = "SELECT * FROM " + m_Realm + " WHERE (\"flags\" & " + regionFlags.ToString() + ") <> 0"; | ||
380 | if (scopeID != UUID.Zero) | ||
381 | sql += " AND \"ScopeID\" = :scopeID"; | ||
382 | |||
383 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
384 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
385 | { | ||
386 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); | ||
387 | conn.Open(); | ||
388 | return RunCommand(cmd); | ||
389 | } | ||
390 | } | ||
391 | } | ||
392 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLSimulationData.cs b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs new file mode 100644 index 0000000..77d87d4 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLSimulationData.cs | |||
@@ -0,0 +1,2243 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.Drawing; | ||
32 | using System.IO; | ||
33 | using System.Reflection; | ||
34 | using log4net; | ||
35 | using OpenMetaverse; | ||
36 | using OpenSim.Framework; | ||
37 | using OpenSim.Region.Framework.Interfaces; | ||
38 | using OpenSim.Region.Framework.Scenes; | ||
39 | using Npgsql; | ||
40 | |||
41 | namespace OpenSim.Data.PGSQL | ||
42 | { | ||
43 | /// <summary> | ||
44 | /// A PGSQL Interface for the Region Server. | ||
45 | /// </summary> | ||
46 | public class PGSQLSimulationData : ISimulationDataStore | ||
47 | { | ||
48 | private const string _migrationStore = "RegionStore"; | ||
49 | private const string LogHeader = "[REGION DB PGSQL]"; | ||
50 | |||
51 | // private static FileSystemDataStore Instance = new FileSystemDataStore(); | ||
52 | private static readonly ILog _Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
53 | |||
54 | /// <summary> | ||
55 | /// The database manager | ||
56 | /// </summary> | ||
57 | private PGSQLManager _Database; | ||
58 | private string m_connectionString; | ||
59 | protected virtual Assembly Assembly | ||
60 | { | ||
61 | get { return GetType().Assembly; } | ||
62 | } | ||
63 | |||
64 | public PGSQLSimulationData() | ||
65 | { | ||
66 | } | ||
67 | |||
68 | public PGSQLSimulationData(string connectionString) | ||
69 | { | ||
70 | Initialise(connectionString); | ||
71 | } | ||
72 | |||
73 | /// <summary> | ||
74 | /// Initialises the region datastore | ||
75 | /// </summary> | ||
76 | /// <param name="connectionString">The connection string.</param> | ||
77 | public void Initialise(string connectionString) | ||
78 | { | ||
79 | m_connectionString = connectionString; | ||
80 | _Database = new PGSQLManager(connectionString); | ||
81 | |||
82 | using (NpgsqlConnection conn = new NpgsqlConnection(connectionString)) | ||
83 | { | ||
84 | conn.Open(); | ||
85 | //New Migration settings | ||
86 | Migration m = new Migration(conn, Assembly, "RegionStore"); | ||
87 | m.Update(); | ||
88 | } | ||
89 | } | ||
90 | |||
91 | /// <summary> | ||
92 | /// Dispose the database | ||
93 | /// </summary> | ||
94 | public void Dispose() { } | ||
95 | |||
96 | #region SceneObjectGroup region for loading and Store of the scene. | ||
97 | |||
98 | /// <summary> | ||
99 | /// Loads the objects present in the region. | ||
100 | /// </summary> | ||
101 | /// <param name="regionUUID">The region UUID.</param> | ||
102 | /// <returns></returns> | ||
103 | public List<SceneObjectGroup> LoadObjects(UUID regionUUID) | ||
104 | { | ||
105 | UUID lastGroupID = UUID.Zero; | ||
106 | |||
107 | Dictionary<UUID, SceneObjectPart> prims = new Dictionary<UUID, SceneObjectPart>(); | ||
108 | Dictionary<UUID, SceneObjectGroup> objects = new Dictionary<UUID, SceneObjectGroup>(); | ||
109 | SceneObjectGroup grp = null; | ||
110 | |||
111 | string sql = @"SELECT *, | ||
112 | CASE WHEN prims.""UUID"" = prims.""SceneGroupID"" THEN 0 ELSE 1 END as sort | ||
113 | FROM prims | ||
114 | LEFT JOIN primshapes ON prims.""UUID"" = primshapes.""UUID"" | ||
115 | WHERE ""RegionUUID"" = :RegionUUID | ||
116 | ORDER BY ""SceneGroupID"" asc, sort asc, ""LinkNumber"" asc"; | ||
117 | |||
118 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
119 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) | ||
120 | { | ||
121 | command.Parameters.Add(_Database.CreateParameter("regionUUID", regionUUID)); | ||
122 | conn.Open(); | ||
123 | using (NpgsqlDataReader reader = command.ExecuteReader()) | ||
124 | { | ||
125 | while (reader.Read()) | ||
126 | { | ||
127 | SceneObjectPart sceneObjectPart = BuildPrim(reader); | ||
128 | if (reader["Shape"] is DBNull) | ||
129 | sceneObjectPart.Shape = PrimitiveBaseShape.Default; | ||
130 | else | ||
131 | sceneObjectPart.Shape = BuildShape(reader); | ||
132 | |||
133 | prims[sceneObjectPart.UUID] = sceneObjectPart; | ||
134 | |||
135 | UUID groupID = new UUID((Guid)reader["SceneGroupID"]); | ||
136 | |||
137 | if (groupID != lastGroupID) // New SOG | ||
138 | { | ||
139 | if (grp != null) | ||
140 | objects[grp.UUID] = grp; | ||
141 | |||
142 | lastGroupID = groupID; | ||
143 | |||
144 | // There sometimes exist OpenSim bugs that 'orphan groups' so that none of the prims are | ||
145 | // recorded as the root prim (for which the UUID must equal the persisted group UUID). In | ||
146 | // this case, force the UUID to be the same as the group UUID so that at least these can be | ||
147 | // deleted (we need to change the UUID so that any other prims in the linkset can also be | ||
148 | // deleted). | ||
149 | if (sceneObjectPart.UUID != groupID && groupID != UUID.Zero) | ||
150 | { | ||
151 | _Log.WarnFormat( | ||
152 | "[REGION DB]: Found root prim {0} {1} at {2} where group was actually {3}. Forcing UUID to group UUID", | ||
153 | sceneObjectPart.Name, sceneObjectPart.UUID, sceneObjectPart.GroupPosition, groupID); | ||
154 | |||
155 | sceneObjectPart.UUID = groupID; | ||
156 | } | ||
157 | |||
158 | grp = new SceneObjectGroup(sceneObjectPart); | ||
159 | } | ||
160 | else | ||
161 | { | ||
162 | // Black magic to preserve link numbers | ||
163 | // Why is this needed, fix this in AddPart method. | ||
164 | int link = sceneObjectPart.LinkNum; | ||
165 | |||
166 | grp.AddPart(sceneObjectPart); | ||
167 | |||
168 | if (link != 0) | ||
169 | sceneObjectPart.LinkNum = link; | ||
170 | } | ||
171 | } | ||
172 | } | ||
173 | } | ||
174 | |||
175 | if (grp != null) | ||
176 | objects[grp.UUID] = grp; | ||
177 | |||
178 | // Instead of attempting to LoadItems on every prim, | ||
179 | // most of which probably have no items... get a | ||
180 | // list from DB of all prims which have items and | ||
181 | // LoadItems only on those | ||
182 | List<SceneObjectPart> primsWithInventory = new List<SceneObjectPart>(); | ||
183 | string qry = "select distinct \"primID\" from primitems"; | ||
184 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
185 | using (NpgsqlCommand command = new NpgsqlCommand(qry, conn)) | ||
186 | { | ||
187 | conn.Open(); | ||
188 | using (NpgsqlDataReader itemReader = command.ExecuteReader()) | ||
189 | { | ||
190 | while (itemReader.Read()) | ||
191 | { | ||
192 | if (!(itemReader["primID"] is DBNull)) | ||
193 | { | ||
194 | UUID primID = new UUID(itemReader["primID"].ToString()); | ||
195 | if (prims.ContainsKey(primID)) | ||
196 | { | ||
197 | primsWithInventory.Add(prims[primID]); | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | } | ||
203 | |||
204 | LoadItems(primsWithInventory); | ||
205 | |||
206 | _Log.DebugFormat("[REGION DB]: Loaded {0} objects using {1} prims", objects.Count, prims.Count); | ||
207 | |||
208 | return new List<SceneObjectGroup>(objects.Values); | ||
209 | } | ||
210 | |||
211 | /// <summary> | ||
212 | /// Load in the prim's persisted inventory. | ||
213 | /// </summary> | ||
214 | /// <param name="allPrims">all prims with inventory on a region</param> | ||
215 | private void LoadItems(List<SceneObjectPart> allPrimsWithInventory) | ||
216 | { | ||
217 | string sql = @"SELECT * FROM primitems WHERE ""primID"" = :PrimID"; | ||
218 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
219 | using (NpgsqlCommand command = new NpgsqlCommand(sql, conn)) | ||
220 | { | ||
221 | conn.Open(); | ||
222 | foreach (SceneObjectPart objectPart in allPrimsWithInventory) | ||
223 | { | ||
224 | command.Parameters.Clear(); | ||
225 | command.Parameters.Add(_Database.CreateParameter("PrimID", objectPart.UUID)); | ||
226 | |||
227 | List<TaskInventoryItem> inventory = new List<TaskInventoryItem>(); | ||
228 | |||
229 | using (NpgsqlDataReader reader = command.ExecuteReader()) | ||
230 | { | ||
231 | while (reader.Read()) | ||
232 | { | ||
233 | TaskInventoryItem item = BuildItem(reader); | ||
234 | |||
235 | item.ParentID = objectPart.UUID; // Values in database are | ||
236 | // often wrong | ||
237 | inventory.Add(item); | ||
238 | } | ||
239 | } | ||
240 | |||
241 | objectPart.Inventory.RestoreInventoryItems(inventory); | ||
242 | } | ||
243 | } | ||
244 | } | ||
245 | |||
246 | /// <summary> | ||
247 | /// Stores all object's details apart from inventory | ||
248 | /// </summary> | ||
249 | /// <param name="obj"></param> | ||
250 | /// <param name="regionUUID"></param> | ||
251 | public void StoreObject(SceneObjectGroup obj, UUID regionUUID) | ||
252 | { | ||
253 | uint flags = obj.RootPart.GetEffectiveObjectFlags(); | ||
254 | // Eligibility check | ||
255 | // | ||
256 | if ((flags & (uint)PrimFlags.Temporary) != 0) | ||
257 | return; | ||
258 | if ((flags & (uint)PrimFlags.TemporaryOnRez) != 0) | ||
259 | return; | ||
260 | |||
261 | //_Log.DebugFormat("[PGSQL]: Adding/Changing SceneObjectGroup: {0} to region: {1}, object has {2} prims.", obj.UUID, regionUUID, obj.Parts.Length); | ||
262 | |||
263 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
264 | { | ||
265 | conn.Open(); | ||
266 | NpgsqlTransaction transaction = conn.BeginTransaction(); | ||
267 | |||
268 | try | ||
269 | { | ||
270 | foreach (SceneObjectPart sceneObjectPart in obj.Parts) | ||
271 | { | ||
272 | //Update prim | ||
273 | using (NpgsqlCommand sqlCommand = conn.CreateCommand()) | ||
274 | { | ||
275 | sqlCommand.Transaction = transaction; | ||
276 | try | ||
277 | { | ||
278 | StoreSceneObjectPrim(sceneObjectPart, sqlCommand, obj.UUID, regionUUID); | ||
279 | } | ||
280 | catch (NpgsqlException sqlEx) | ||
281 | { | ||
282 | _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrim SQL error: {0} at line {1}", sqlEx.Message, sqlEx.Line); | ||
283 | throw; | ||
284 | } | ||
285 | } | ||
286 | |||
287 | //Update primshapes | ||
288 | using (NpgsqlCommand sqlCommand = conn.CreateCommand()) | ||
289 | { | ||
290 | sqlCommand.Transaction = transaction; | ||
291 | try | ||
292 | { | ||
293 | StoreSceneObjectPrimShapes(sceneObjectPart, sqlCommand, obj.UUID, regionUUID); | ||
294 | } | ||
295 | catch (NpgsqlException sqlEx) | ||
296 | { | ||
297 | _Log.ErrorFormat("[REGION DB]: Store SceneObjectPrimShapes SQL error: {0} at line {1}", sqlEx.Message, sqlEx.Line); | ||
298 | throw; | ||
299 | } | ||
300 | } | ||
301 | } | ||
302 | |||
303 | transaction.Commit(); | ||
304 | } | ||
305 | catch (Exception ex) | ||
306 | { | ||
307 | _Log.ErrorFormat("[REGION DB]: Store SceneObjectGroup error: {0}, Rolling back...", ex.Message); | ||
308 | try | ||
309 | { | ||
310 | transaction.Rollback(); | ||
311 | } | ||
312 | catch (Exception ex2) | ||
313 | { | ||
314 | //Show error | ||
315 | _Log.InfoFormat("[REGION DB]: Rollback of SceneObjectGroup store transaction failed with error: {0}", ex2.Message); | ||
316 | |||
317 | } | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | |||
322 | /// <summary> | ||
323 | /// Stores the prim of the sceneobjectpart. | ||
324 | /// </summary> | ||
325 | /// <param name="sceneObjectPart">The sceneobjectpart or prim.</param> | ||
326 | /// <param name="sqlCommand">The SQL command with the transaction.</param> | ||
327 | /// <param name="sceneGroupID">The scenegroup UUID.</param> | ||
328 | /// <param name="regionUUID">The region UUID.</param> | ||
329 | private void StoreSceneObjectPrim(SceneObjectPart sceneObjectPart, NpgsqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID) | ||
330 | { | ||
331 | //Big query to update or insert a new prim. | ||
332 | |||
333 | string queryPrims = @" | ||
334 | UPDATE prims SET | ||
335 | ""CreationDate"" = :CreationDate, ""Name"" = :Name, ""Text"" = :Text, ""Description"" = :Description, ""SitName"" = :SitName, | ||
336 | ""TouchName"" = :TouchName, ""ObjectFlags"" = :ObjectFlags, ""OwnerMask"" = :OwnerMask, ""NextOwnerMask"" = :NextOwnerMask, ""GroupMask"" = :GroupMask, | ||
337 | ""EveryoneMask"" = :EveryoneMask, ""BaseMask"" = :BaseMask, ""PositionX"" = :PositionX, ""PositionY"" = :PositionY, ""PositionZ"" = :PositionZ, | ||
338 | ""GroupPositionX"" = :GroupPositionX, ""GroupPositionY"" = :GroupPositionY, ""GroupPositionZ"" = :GroupPositionZ, ""VelocityX"" = :VelocityX, | ||
339 | ""VelocityY"" = :VelocityY, ""VelocityZ"" = :VelocityZ, ""AngularVelocityX"" = :AngularVelocityX, ""AngularVelocityY"" = :AngularVelocityY, | ||
340 | ""AngularVelocityZ"" = :AngularVelocityZ, ""AccelerationX"" = :AccelerationX, ""AccelerationY"" = :AccelerationY, | ||
341 | ""AccelerationZ"" = :AccelerationZ, ""RotationX"" = :RotationX, ""RotationY"" = :RotationY, ""RotationZ"" = :RotationZ, ""RotationW"" = :RotationW, | ||
342 | ""SitTargetOffsetX"" = :SitTargetOffsetX, ""SitTargetOffsetY"" = :SitTargetOffsetY, ""SitTargetOffsetZ"" = :SitTargetOffsetZ, | ||
343 | ""SitTargetOrientW"" = :SitTargetOrientW, ""SitTargetOrientX"" = :SitTargetOrientX, ""SitTargetOrientY"" = :SitTargetOrientY, | ||
344 | ""SitTargetOrientZ"" = :SitTargetOrientZ, ""RegionUUID"" = :RegionUUID, ""CreatorID"" = :CreatorID, ""OwnerID"" = :OwnerID, ""GroupID"" = :GroupID, | ||
345 | ""LastOwnerID"" = :LastOwnerID, ""SceneGroupID"" = :SceneGroupID, ""PayPrice"" = :PayPrice, ""PayButton1"" = :PayButton1, ""PayButton2"" = :PayButton2, | ||
346 | ""PayButton3"" = :PayButton3, ""PayButton4"" = :PayButton4, ""LoopedSound"" = :LoopedSound, ""LoopedSoundGain"" = :LoopedSoundGain, | ||
347 | ""TextureAnimation"" = :TextureAnimation, ""OmegaX"" = :OmegaX, ""OmegaY"" = :OmegaY, ""OmegaZ"" = :OmegaZ, ""CameraEyeOffsetX"" = :CameraEyeOffsetX, | ||
348 | ""CameraEyeOffsetY"" = :CameraEyeOffsetY, ""CameraEyeOffsetZ"" = :CameraEyeOffsetZ, ""CameraAtOffsetX"" = :CameraAtOffsetX, | ||
349 | ""CameraAtOffsetY"" = :CameraAtOffsetY, ""CameraAtOffsetZ"" = :CameraAtOffsetZ, ""ForceMouselook"" = :ForceMouselook, | ||
350 | ""ScriptAccessPin"" = :ScriptAccessPin, ""AllowedDrop"" = :AllowedDrop, ""DieAtEdge"" = :DieAtEdge, ""SalePrice"" = :SalePrice, | ||
351 | ""SaleType"" = :SaleType, ""ColorR"" = :ColorR, ""ColorG"" = :ColorG, ""ColorB"" = :ColorB, ""ColorA"" = :ColorA, ""ParticleSystem"" = :ParticleSystem, | ||
352 | ""ClickAction"" = :ClickAction, ""Material"" = :Material, ""CollisionSound"" = :CollisionSound, ""CollisionSoundVolume"" = :CollisionSoundVolume, ""PassTouches"" = :PassTouches, | ||
353 | ""LinkNumber"" = :LinkNumber, ""MediaURL"" = :MediaURL, ""DynAttrs"" = :DynAttrs, | ||
354 | ""PhysicsShapeType"" = :PhysicsShapeType, ""Density"" = :Density, ""GravityModifier"" = :GravityModifier, ""Friction"" = :Friction, ""Restitution"" = :Restitution | ||
355 | WHERE ""UUID"" = :UUID ; | ||
356 | |||
357 | INSERT INTO | ||
358 | prims ( | ||
359 | ""UUID"", ""CreationDate"", ""Name"", ""Text"", ""Description"", ""SitName"", ""TouchName"", ""ObjectFlags"", ""OwnerMask"", ""NextOwnerMask"", ""GroupMask"", | ||
360 | ""EveryoneMask"", ""BaseMask"", ""PositionX"", ""PositionY"", ""PositionZ"", ""GroupPositionX"", ""GroupPositionY"", ""GroupPositionZ"", ""VelocityX"", | ||
361 | ""VelocityY"", ""VelocityZ"", ""AngularVelocityX"", ""AngularVelocityY"", ""AngularVelocityZ"", ""AccelerationX"", ""AccelerationY"", ""AccelerationZ"", | ||
362 | ""RotationX"", ""RotationY"", ""RotationZ"", ""RotationW"", ""SitTargetOffsetX"", ""SitTargetOffsetY"", ""SitTargetOffsetZ"", ""SitTargetOrientW"", | ||
363 | ""SitTargetOrientX"", ""SitTargetOrientY"", ""SitTargetOrientZ"", ""RegionUUID"", ""CreatorID"", ""OwnerID"", ""GroupID"", ""LastOwnerID"", ""SceneGroupID"", | ||
364 | ""PayPrice"", ""PayButton1"", ""PayButton2"", ""PayButton3"", ""PayButton4"", ""LoopedSound"", ""LoopedSoundGain"", ""TextureAnimation"", ""OmegaX"", | ||
365 | ""OmegaY"", ""OmegaZ"", ""CameraEyeOffsetX"", ""CameraEyeOffsetY"", ""CameraEyeOffsetZ"", ""CameraAtOffsetX"", ""CameraAtOffsetY"", ""CameraAtOffsetZ"", | ||
366 | ""ForceMouselook"", ""ScriptAccessPin"", ""AllowedDrop"", ""DieAtEdge"", ""SalePrice"", ""SaleType"", ""ColorR"", ""ColorG"", ""ColorB"", ""ColorA"", | ||
367 | ""ParticleSystem"", ""ClickAction"", ""Material"", ""CollisionSound"", ""CollisionSoundVolume"", ""PassTouches"", ""LinkNumber"", ""MediaURL"", ""DynAttrs"", | ||
368 | ""PhysicsShapeType"", ""Density"", ""GravityModifier"", ""Friction"", ""Restitution"" | ||
369 | ) Select | ||
370 | :UUID, :CreationDate, :Name, :Text, :Description, :SitName, :TouchName, :ObjectFlags, :OwnerMask, :NextOwnerMask, :GroupMask, | ||
371 | :EveryoneMask, :BaseMask, :PositionX, :PositionY, :PositionZ, :GroupPositionX, :GroupPositionY, :GroupPositionZ, :VelocityX, | ||
372 | :VelocityY, :VelocityZ, :AngularVelocityX, :AngularVelocityY, :AngularVelocityZ, :AccelerationX, :AccelerationY, :AccelerationZ, | ||
373 | :RotationX, :RotationY, :RotationZ, :RotationW, :SitTargetOffsetX, :SitTargetOffsetY, :SitTargetOffsetZ, :SitTargetOrientW, | ||
374 | :SitTargetOrientX, :SitTargetOrientY, :SitTargetOrientZ, :RegionUUID, :CreatorID, :OwnerID, :GroupID, :LastOwnerID, :SceneGroupID, | ||
375 | :PayPrice, :PayButton1, :PayButton2, :PayButton3, :PayButton4, :LoopedSound, :LoopedSoundGain, :TextureAnimation, :OmegaX, | ||
376 | :OmegaY, :OmegaZ, :CameraEyeOffsetX, :CameraEyeOffsetY, :CameraEyeOffsetZ, :CameraAtOffsetX, :CameraAtOffsetY, :CameraAtOffsetZ, | ||
377 | :ForceMouselook, :ScriptAccessPin, :AllowedDrop, :DieAtEdge, :SalePrice, :SaleType, :ColorR, :ColorG, :ColorB, :ColorA, | ||
378 | :ParticleSystem, :ClickAction, :Material, :CollisionSound, :CollisionSoundVolume, :PassTouches, :LinkNumber, :MediaURL, :DynAttrs, | ||
379 | :PhysicsShapeType, :Density, :GravityModifier, :Friction, :Restitution | ||
380 | where not EXISTS (SELECT ""UUID"" FROM prims WHERE ""UUID"" = :UUID); | ||
381 | "; | ||
382 | |||
383 | //Set commandtext. | ||
384 | sqlCommand.CommandText = queryPrims; | ||
385 | //Add parameters | ||
386 | sqlCommand.Parameters.AddRange(CreatePrimParameters(sceneObjectPart, sceneGroupID, regionUUID)); | ||
387 | |||
388 | //Execute the query. If it fails then error is trapped in calling function | ||
389 | sqlCommand.ExecuteNonQuery(); | ||
390 | } | ||
391 | |||
392 | /// <summary> | ||
393 | /// Stores the scene object prim shapes. | ||
394 | /// </summary> | ||
395 | /// <param name="sceneObjectPart">The sceneobjectpart containing prim shape.</param> | ||
396 | /// <param name="sqlCommand">The SQL command with the transaction.</param> | ||
397 | /// <param name="sceneGroupID">The scenegroup UUID.</param> | ||
398 | /// <param name="regionUUID">The region UUID.</param> | ||
399 | private void StoreSceneObjectPrimShapes(SceneObjectPart sceneObjectPart, NpgsqlCommand sqlCommand, UUID sceneGroupID, UUID regionUUID) | ||
400 | { | ||
401 | //Big query to or insert or update primshapes | ||
402 | |||
403 | string queryPrimShapes = @" | ||
404 | UPDATE primshapes SET | ||
405 | ""Shape"" = :Shape, ""ScaleX"" = :ScaleX, ""ScaleY"" = :ScaleY, ""ScaleZ"" = :ScaleZ, ""PCode"" = :PCode, ""PathBegin"" = :PathBegin, | ||
406 | ""PathEnd"" = :PathEnd, ""PathScaleX"" = :PathScaleX, ""PathScaleY"" = :PathScaleY, ""PathShearX"" = :PathShearX, ""PathShearY"" = :PathShearY, | ||
407 | ""PathSkew"" = :PathSkew, ""PathCurve"" = :PathCurve, ""PathRadiusOffset"" = :PathRadiusOffset, ""PathRevolutions"" = :PathRevolutions, | ||
408 | ""PathTaperX"" = :PathTaperX, ""PathTaperY"" = :PathTaperY, ""PathTwist"" = :PathTwist, ""PathTwistBegin"" = :PathTwistBegin, | ||
409 | ""ProfileBegin"" = :ProfileBegin, ""ProfileEnd"" = :ProfileEnd, ""ProfileCurve"" = :ProfileCurve, ""ProfileHollow"" = :ProfileHollow, | ||
410 | ""Texture"" = :Texture, ""ExtraParams"" = :ExtraParams, ""State"" = :State, ""Media"" = :Media | ||
411 | WHERE ""UUID"" = :UUID ; | ||
412 | |||
413 | INSERT INTO | ||
414 | primshapes ( | ||
415 | ""UUID"", ""Shape"", ""ScaleX"", ""ScaleY"", ""ScaleZ"", ""PCode"", ""PathBegin"", ""PathEnd"", ""PathScaleX"", ""PathScaleY"", ""PathShearX"", ""PathShearY"", | ||
416 | ""PathSkew"", ""PathCurve"", ""PathRadiusOffset"", ""PathRevolutions"", ""PathTaperX"", ""PathTaperY"", ""PathTwist"", ""PathTwistBegin"", ""ProfileBegin"", | ||
417 | ""ProfileEnd"", ""ProfileCurve"", ""ProfileHollow"", ""Texture"", ""ExtraParams"", ""State"", ""Media"" | ||
418 | ) | ||
419 | Select | ||
420 | :UUID, :Shape, :ScaleX, :ScaleY, :ScaleZ, :PCode, :PathBegin, :PathEnd, :PathScaleX, :PathScaleY, :PathShearX, :PathShearY, | ||
421 | :PathSkew, :PathCurve, :PathRadiusOffset, :PathRevolutions, :PathTaperX, :PathTaperY, :PathTwist, :PathTwistBegin, :ProfileBegin, | ||
422 | :ProfileEnd, :ProfileCurve, :ProfileHollow, :Texture, :ExtraParams, :State, :Media | ||
423 | where not EXISTS (SELECT ""UUID"" FROM primshapes WHERE ""UUID"" = :UUID); | ||
424 | "; | ||
425 | |||
426 | //Set commandtext. | ||
427 | sqlCommand.CommandText = queryPrimShapes; | ||
428 | |||
429 | //Add parameters | ||
430 | sqlCommand.Parameters.AddRange(CreatePrimShapeParameters(sceneObjectPart, sceneGroupID, regionUUID)); | ||
431 | |||
432 | //Execute the query. If it fails then error is trapped in calling function | ||
433 | sqlCommand.ExecuteNonQuery(); | ||
434 | |||
435 | } | ||
436 | |||
437 | /// <summary> | ||
438 | /// Removes a object from the database. | ||
439 | /// Meaning removing it from tables Prims, PrimShapes and PrimItems | ||
440 | /// </summary> | ||
441 | /// <param name="objectID">id of scenegroup</param> | ||
442 | /// <param name="regionUUID">regionUUID (is this used anyway</param> | ||
443 | public void RemoveObject(UUID objectID, UUID regionUUID) | ||
444 | { | ||
445 | //_Log.InfoFormat("[PGSQL]: Removing obj: {0} from region: {1}", objectID, regionUUID); | ||
446 | |||
447 | //Remove from prims and primsitem table | ||
448 | string sqlPrims = @"DELETE FROM PRIMS WHERE ""SceneGroupID"" = :objectID"; | ||
449 | string sqlPrimItems = @"DELETE FROM PRIMITEMS WHERE ""primID"" in (SELECT ""UUID"" FROM PRIMS WHERE ""SceneGroupID"" = :objectID)"; | ||
450 | string sqlPrimShapes = @"DELETE FROM PRIMSHAPES WHERE ""UUID"" in (SELECT ""UUID"" FROM PRIMS WHERE ""SceneGroupID"" = :objectID)"; | ||
451 | |||
452 | lock (_Database) | ||
453 | { | ||
454 | //Using the non transaction mode. | ||
455 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
456 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
457 | { | ||
458 | cmd.Connection = conn; | ||
459 | cmd.CommandText = sqlPrimShapes; | ||
460 | conn.Open(); | ||
461 | cmd.Parameters.Add(_Database.CreateParameter("objectID", objectID)); | ||
462 | cmd.ExecuteNonQuery(); | ||
463 | |||
464 | cmd.CommandText = sqlPrimItems; | ||
465 | cmd.ExecuteNonQuery(); | ||
466 | |||
467 | cmd.CommandText = sqlPrims; | ||
468 | cmd.ExecuteNonQuery(); | ||
469 | } | ||
470 | } | ||
471 | } | ||
472 | |||
473 | /// <summary> | ||
474 | /// Store the inventory of a prim. Warning deletes everything first and then adds all again. | ||
475 | /// </summary> | ||
476 | /// <param name="primID"></param> | ||
477 | /// <param name="items"></param> | ||
478 | public void StorePrimInventory(UUID primID, ICollection<TaskInventoryItem> items) | ||
479 | { | ||
480 | //_Log.InfoFormat("[REGION DB: Persisting Prim Inventory with prim ID {0}", primID); | ||
481 | |||
482 | //Statement from PGSQL section! | ||
483 | // For now, we're just going to crudely remove all the previous inventory items | ||
484 | // no matter whether they have changed or not, and replace them with the current set. | ||
485 | |||
486 | //Delete everything from PrimID | ||
487 | //TODO add index on PrimID in DB, if not already exist | ||
488 | |||
489 | string sql = @"delete from primitems where ""primID"" = :primID"; | ||
490 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
491 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
492 | { | ||
493 | cmd.Parameters.Add(_Database.CreateParameter("primID", primID)); | ||
494 | conn.Open(); | ||
495 | cmd.ExecuteNonQuery(); | ||
496 | } | ||
497 | |||
498 | sql = | ||
499 | @"INSERT INTO primitems ( | ||
500 | ""itemID"",""primID"",""assetID"",""parentFolderID"",""invType"",""assetType"",""name"",""description"",""creationDate"",""creatorID"",""ownerID"",""lastOwnerID"",""groupID"", | ||
501 | ""nextPermissions"",""currentPermissions"",""basePermissions"",""everyonePermissions"",""groupPermissions"",""flags"") | ||
502 | VALUES (:itemID,:primID,:assetID,:parentFolderID,:invType,:assetType,:name,:description,:creationDate,:creatorID,:ownerID, | ||
503 | :lastOwnerID,:groupID,:nextPermissions,:currentPermissions,:basePermissions,:everyonePermissions,:groupPermissions,:flags)"; | ||
504 | |||
505 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
506 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
507 | { | ||
508 | conn.Open(); | ||
509 | foreach (TaskInventoryItem taskItem in items) | ||
510 | { | ||
511 | cmd.Parameters.AddRange(CreatePrimInventoryParameters(taskItem)); | ||
512 | cmd.ExecuteNonQuery(); | ||
513 | cmd.Parameters.Clear(); | ||
514 | } | ||
515 | } | ||
516 | } | ||
517 | |||
518 | #endregion | ||
519 | |||
520 | /// <summary> | ||
521 | /// Loads the terrain map. | ||
522 | /// </summary> | ||
523 | /// <param name="regionID">regionID.</param> | ||
524 | /// <returns></returns> | ||
525 | public double[,] LoadTerrain(UUID regionID) | ||
526 | { | ||
527 | double[,] ret = null; | ||
528 | TerrainData terrData = LoadTerrain(regionID, (int)Constants.RegionSize, (int)Constants.RegionSize, (int)Constants.RegionHeight); | ||
529 | if (terrData != null) | ||
530 | ret = terrData.GetDoubles(); | ||
531 | return ret; | ||
532 | } | ||
533 | |||
534 | // Returns 'null' if region not found | ||
535 | public TerrainData LoadTerrain(UUID regionID, int pSizeX, int pSizeY, int pSizeZ) | ||
536 | { | ||
537 | TerrainData terrData = null; | ||
538 | |||
539 | string sql = @"select ""RegionUUID"", ""Revision"", ""Heightfield"" from terrain | ||
540 | where ""RegionUUID"" = :RegionUUID order by ""Revision"" desc limit 1; "; | ||
541 | |||
542 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
543 | { | ||
544 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
545 | { | ||
546 | // PGSqlParameter param = new PGSqlParameter(); | ||
547 | cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); | ||
548 | conn.Open(); | ||
549 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
550 | { | ||
551 | int rev; | ||
552 | if (reader.Read()) | ||
553 | { | ||
554 | rev = Convert.ToInt32(reader["Revision"]); | ||
555 | byte[] blob = (byte[])reader["Heightfield"]; | ||
556 | terrData = TerrainData.CreateFromDatabaseBlobFactory(pSizeX, pSizeY, pSizeZ, rev, blob); | ||
557 | } | ||
558 | else | ||
559 | { | ||
560 | _Log.Info("[REGION DB]: No terrain found for region"); | ||
561 | return null; | ||
562 | } | ||
563 | _Log.Info("[REGION DB]: Loaded terrain revision r" + rev); | ||
564 | } | ||
565 | } | ||
566 | } | ||
567 | |||
568 | return terrData; | ||
569 | } | ||
570 | |||
571 | // Legacy entry point for when terrain was always a 256x256 heightmap | ||
572 | public void StoreTerrain(double[,] terrain, UUID regionID) | ||
573 | { | ||
574 | StoreTerrain(new HeightmapTerrainData(terrain), regionID); | ||
575 | } | ||
576 | |||
577 | /// <summary> | ||
578 | /// Stores the terrain map to DB. | ||
579 | /// </summary> | ||
580 | /// <param name="terrain">terrain map data.</param> | ||
581 | /// <param name="regionID">regionID.</param> | ||
582 | public void StoreTerrain(TerrainData terrData, UUID regionID) | ||
583 | { | ||
584 | //Delete old terrain map | ||
585 | string sql = @"delete from terrain where ""RegionUUID""=:RegionUUID"; | ||
586 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
587 | { | ||
588 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
589 | { | ||
590 | cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); | ||
591 | conn.Open(); | ||
592 | cmd.ExecuteNonQuery(); | ||
593 | |||
594 | _Log.InfoFormat("{0} Deleted terrain revision id = {1}", LogHeader, regionID); | ||
595 | } | ||
596 | } | ||
597 | |||
598 | int terrainDBRevision; | ||
599 | Array terrainDBblob; | ||
600 | terrData.GetDatabaseBlob(out terrainDBRevision, out terrainDBblob); | ||
601 | |||
602 | sql = @"insert into terrain(""RegionUUID"", ""Revision"", ""Heightfield"") values(:RegionUUID, :Revision, :Heightfield)"; | ||
603 | |||
604 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
605 | { | ||
606 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
607 | { | ||
608 | cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionID)); | ||
609 | cmd.Parameters.Add(_Database.CreateParameter("Revision", terrainDBRevision)); | ||
610 | cmd.Parameters.Add(_Database.CreateParameter("Heightfield", terrainDBblob)); | ||
611 | conn.Open(); | ||
612 | cmd.ExecuteNonQuery(); | ||
613 | |||
614 | _Log.InfoFormat("{0} Stored terrain id = {1}, terrainSize = <{2},{3}>", | ||
615 | LogHeader, regionID, terrData.SizeX, terrData.SizeY); | ||
616 | } | ||
617 | } | ||
618 | |||
619 | } | ||
620 | |||
621 | /// <summary> | ||
622 | /// Loads all the land objects of a region. | ||
623 | /// </summary> | ||
624 | /// <param name="regionUUID">The region UUID.</param> | ||
625 | /// <returns></returns> | ||
626 | public List<LandData> LoadLandObjects(UUID regionUUID) | ||
627 | { | ||
628 | List<LandData> LandDataForRegion = new List<LandData>(); | ||
629 | |||
630 | string sql = @"select * from land where ""RegionUUID"" = :RegionUUID"; | ||
631 | |||
632 | //Retrieve all land data from region | ||
633 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
634 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
635 | { | ||
636 | cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID)); | ||
637 | conn.Open(); | ||
638 | using (NpgsqlDataReader readerLandData = cmd.ExecuteReader()) | ||
639 | { | ||
640 | while (readerLandData.Read()) | ||
641 | { | ||
642 | LandDataForRegion.Add(BuildLandData(readerLandData)); | ||
643 | } | ||
644 | } | ||
645 | } | ||
646 | |||
647 | //Retrieve all accesslist data for all landdata | ||
648 | foreach (LandData LandData in LandDataForRegion) | ||
649 | { | ||
650 | sql = @"select * from landaccesslist where ""LandUUID"" = :LandUUID"; | ||
651 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
652 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
653 | { | ||
654 | cmd.Parameters.Add(_Database.CreateParameter("LandUUID", LandData.GlobalID)); | ||
655 | conn.Open(); | ||
656 | using (NpgsqlDataReader readerAccessList = cmd.ExecuteReader()) | ||
657 | { | ||
658 | while (readerAccessList.Read()) | ||
659 | { | ||
660 | LandData.ParcelAccessList.Add(BuildLandAccessData(readerAccessList)); | ||
661 | } | ||
662 | } | ||
663 | } | ||
664 | } | ||
665 | |||
666 | //Return data | ||
667 | return LandDataForRegion; | ||
668 | } | ||
669 | |||
670 | /// <summary> | ||
671 | /// Stores land object with landaccess list. | ||
672 | /// </summary> | ||
673 | /// <param name="parcel">parcel data.</param> | ||
674 | public void StoreLandObject(ILandObject parcel) | ||
675 | { | ||
676 | //As this is only one record in land table I just delete all and then add a new record. | ||
677 | //As the delete landaccess is already in the pgsql code | ||
678 | |||
679 | //Delete old values | ||
680 | RemoveLandObject(parcel.LandData.GlobalID); | ||
681 | |||
682 | //Insert new values | ||
683 | string sql = @"INSERT INTO land | ||
684 | (""UUID"",""RegionUUID"",""LocalLandID"",""Bitmap"",""Name"",""Description"",""OwnerUUID"",""IsGroupOwned"",""Area"",""AuctionID"",""Category"",""ClaimDate"",""ClaimPrice"", | ||
685 | ""GroupUUID"",""SalePrice"",""LandStatus"",""LandFlags"",""LandingType"",""MediaAutoScale"",""MediaTextureUUID"",""MediaURL"",""MusicURL"",""PassHours"",""PassPrice"", | ||
686 | ""SnapshotUUID"",""UserLocationX"",""UserLocationY"",""UserLocationZ"",""UserLookAtX"",""UserLookAtY"",""UserLookAtZ"",""AuthbuyerID"",""OtherCleanTime"") | ||
687 | VALUES | ||
688 | (:UUID,:RegionUUID,:LocalLandID,:Bitmap,:Name,:Description,:OwnerUUID,:IsGroupOwned,:Area,:AuctionID,:Category,:ClaimDate,:ClaimPrice, | ||
689 | :GroupUUID,:SalePrice,:LandStatus,:LandFlags,:LandingType,:MediaAutoScale,:MediaTextureUUID,:MediaURL,:MusicURL,:PassHours,:PassPrice, | ||
690 | :SnapshotUUID,:UserLocationX,:UserLocationY,:UserLocationZ,:UserLookAtX,:UserLookAtY,:UserLookAtZ,:AuthbuyerID,:OtherCleanTime)"; | ||
691 | |||
692 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
693 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
694 | { | ||
695 | cmd.Parameters.AddRange(CreateLandParameters(parcel.LandData, parcel.RegionUUID)); | ||
696 | conn.Open(); | ||
697 | cmd.ExecuteNonQuery(); | ||
698 | } | ||
699 | |||
700 | sql = @"INSERT INTO landaccesslist (""LandUUID"",""AccessUUID"",""LandFlags"",""Expires"") VALUES (:LandUUID,:AccessUUID,:Flags,:Expires)"; | ||
701 | |||
702 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
703 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
704 | { | ||
705 | conn.Open(); | ||
706 | foreach (LandAccessEntry parcelAccessEntry in parcel.LandData.ParcelAccessList) | ||
707 | { | ||
708 | cmd.Parameters.AddRange(CreateLandAccessParameters(parcelAccessEntry, parcel.RegionUUID)); | ||
709 | |||
710 | cmd.ExecuteNonQuery(); | ||
711 | cmd.Parameters.Clear(); | ||
712 | } | ||
713 | } | ||
714 | } | ||
715 | |||
716 | /// <summary> | ||
717 | /// Removes a land object from DB. | ||
718 | /// </summary> | ||
719 | /// <param name="globalID">UUID of landobject</param> | ||
720 | public void RemoveLandObject(UUID globalID) | ||
721 | { | ||
722 | string sql = @"delete from land where ""UUID""=:UUID"; | ||
723 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
724 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
725 | { | ||
726 | cmd.Parameters.Add(_Database.CreateParameter("UUID", globalID)); | ||
727 | conn.Open(); | ||
728 | cmd.ExecuteNonQuery(); | ||
729 | } | ||
730 | sql = @"delete from landaccesslist where ""LandUUID""=:UUID"; | ||
731 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
732 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
733 | { | ||
734 | cmd.Parameters.Add(_Database.CreateParameter("UUID", globalID)); | ||
735 | conn.Open(); | ||
736 | cmd.ExecuteNonQuery(); | ||
737 | } | ||
738 | } | ||
739 | public RegionLightShareData LoadRegionWindlightSettings(UUID regionUUID) | ||
740 | { | ||
741 | RegionLightShareData nWP = new RegionLightShareData(); | ||
742 | nWP.OnSave += StoreRegionWindlightSettings; | ||
743 | |||
744 | string sql = @"select * from regionwindlight where ""region_id"" = :regionID"; | ||
745 | |||
746 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
747 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
748 | { | ||
749 | cmd.Parameters.Add(_Database.CreateParameter("regionID", regionUUID.ToString() )); | ||
750 | conn.Open(); | ||
751 | using (NpgsqlDataReader result = cmd.ExecuteReader()) | ||
752 | { | ||
753 | if (!result.Read()) | ||
754 | { | ||
755 | //No result, so store our default windlight profile and return it | ||
756 | nWP.regionID = regionUUID; | ||
757 | StoreRegionWindlightSettings(nWP); | ||
758 | return nWP; | ||
759 | } | ||
760 | else | ||
761 | { | ||
762 | nWP.regionID = DBGuid.FromDB(result["region_id"]); | ||
763 | nWP.waterColor.X = Convert.ToSingle(result["water_color_r"]); | ||
764 | nWP.waterColor.Y = Convert.ToSingle(result["water_color_g"]); | ||
765 | nWP.waterColor.Z = Convert.ToSingle(result["water_color_b"]); | ||
766 | nWP.waterFogDensityExponent = Convert.ToSingle(result["water_fog_density_exponent"]); | ||
767 | nWP.underwaterFogModifier = Convert.ToSingle(result["underwater_fog_modifier"]); | ||
768 | nWP.reflectionWaveletScale.X = Convert.ToSingle(result["reflection_wavelet_scale_1"]); | ||
769 | nWP.reflectionWaveletScale.Y = Convert.ToSingle(result["reflection_wavelet_scale_2"]); | ||
770 | nWP.reflectionWaveletScale.Z = Convert.ToSingle(result["reflection_wavelet_scale_3"]); | ||
771 | nWP.fresnelScale = Convert.ToSingle(result["fresnel_scale"]); | ||
772 | nWP.fresnelOffset = Convert.ToSingle(result["fresnel_offset"]); | ||
773 | nWP.refractScaleAbove = Convert.ToSingle(result["refract_scale_above"]); | ||
774 | nWP.refractScaleBelow = Convert.ToSingle(result["refract_scale_below"]); | ||
775 | nWP.blurMultiplier = Convert.ToSingle(result["blur_multiplier"]); | ||
776 | nWP.bigWaveDirection.X = Convert.ToSingle(result["big_wave_direction_x"]); | ||
777 | nWP.bigWaveDirection.Y = Convert.ToSingle(result["big_wave_direction_y"]); | ||
778 | nWP.littleWaveDirection.X = Convert.ToSingle(result["little_wave_direction_x"]); | ||
779 | nWP.littleWaveDirection.Y = Convert.ToSingle(result["little_wave_direction_y"]); | ||
780 | UUID.TryParse(result["normal_map_texture"].ToString(), out nWP.normalMapTexture); | ||
781 | nWP.horizon.X = Convert.ToSingle(result["horizon_r"]); | ||
782 | nWP.horizon.Y = Convert.ToSingle(result["horizon_g"]); | ||
783 | nWP.horizon.Z = Convert.ToSingle(result["horizon_b"]); | ||
784 | nWP.horizon.W = Convert.ToSingle(result["horizon_i"]); | ||
785 | nWP.hazeHorizon = Convert.ToSingle(result["haze_horizon"]); | ||
786 | nWP.blueDensity.X = Convert.ToSingle(result["blue_density_r"]); | ||
787 | nWP.blueDensity.Y = Convert.ToSingle(result["blue_density_g"]); | ||
788 | nWP.blueDensity.Z = Convert.ToSingle(result["blue_density_b"]); | ||
789 | nWP.blueDensity.W = Convert.ToSingle(result["blue_density_i"]); | ||
790 | nWP.hazeDensity = Convert.ToSingle(result["haze_density"]); | ||
791 | nWP.densityMultiplier = Convert.ToSingle(result["density_multiplier"]); | ||
792 | nWP.distanceMultiplier = Convert.ToSingle(result["distance_multiplier"]); | ||
793 | nWP.maxAltitude = Convert.ToUInt16(result["max_altitude"]); | ||
794 | nWP.sunMoonColor.X = Convert.ToSingle(result["sun_moon_color_r"]); | ||
795 | nWP.sunMoonColor.Y = Convert.ToSingle(result["sun_moon_color_g"]); | ||
796 | nWP.sunMoonColor.Z = Convert.ToSingle(result["sun_moon_color_b"]); | ||
797 | nWP.sunMoonColor.W = Convert.ToSingle(result["sun_moon_color_i"]); | ||
798 | nWP.sunMoonPosition = Convert.ToSingle(result["sun_moon_position"]); | ||
799 | nWP.ambient.X = Convert.ToSingle(result["ambient_r"]); | ||
800 | nWP.ambient.Y = Convert.ToSingle(result["ambient_g"]); | ||
801 | nWP.ambient.Z = Convert.ToSingle(result["ambient_b"]); | ||
802 | nWP.ambient.W = Convert.ToSingle(result["ambient_i"]); | ||
803 | nWP.eastAngle = Convert.ToSingle(result["east_angle"]); | ||
804 | nWP.sunGlowFocus = Convert.ToSingle(result["sun_glow_focus"]); | ||
805 | nWP.sunGlowSize = Convert.ToSingle(result["sun_glow_size"]); | ||
806 | nWP.sceneGamma = Convert.ToSingle(result["scene_gamma"]); | ||
807 | nWP.starBrightness = Convert.ToSingle(result["star_brightness"]); | ||
808 | nWP.cloudColor.X = Convert.ToSingle(result["cloud_color_r"]); | ||
809 | nWP.cloudColor.Y = Convert.ToSingle(result["cloud_color_g"]); | ||
810 | nWP.cloudColor.Z = Convert.ToSingle(result["cloud_color_b"]); | ||
811 | nWP.cloudColor.W = Convert.ToSingle(result["cloud_color_i"]); | ||
812 | nWP.cloudXYDensity.X = Convert.ToSingle(result["cloud_x"]); | ||
813 | nWP.cloudXYDensity.Y = Convert.ToSingle(result["cloud_y"]); | ||
814 | nWP.cloudXYDensity.Z = Convert.ToSingle(result["cloud_density"]); | ||
815 | nWP.cloudCoverage = Convert.ToSingle(result["cloud_coverage"]); | ||
816 | nWP.cloudScale = Convert.ToSingle(result["cloud_scale"]); | ||
817 | nWP.cloudDetailXYDensity.X = Convert.ToSingle(result["cloud_detail_x"]); | ||
818 | nWP.cloudDetailXYDensity.Y = Convert.ToSingle(result["cloud_detail_y"]); | ||
819 | nWP.cloudDetailXYDensity.Z = Convert.ToSingle(result["cloud_detail_density"]); | ||
820 | nWP.cloudScrollX = Convert.ToSingle(result["cloud_scroll_x"]); | ||
821 | nWP.cloudScrollXLock = Convert.ToBoolean(result["cloud_scroll_x_lock"]); | ||
822 | nWP.cloudScrollY = Convert.ToSingle(result["cloud_scroll_y"]); | ||
823 | nWP.cloudScrollYLock = Convert.ToBoolean(result["cloud_scroll_y_lock"]); | ||
824 | nWP.drawClassicClouds = Convert.ToBoolean(result["draw_classic_clouds"]); | ||
825 | nWP.valid = true; | ||
826 | } | ||
827 | } | ||
828 | } | ||
829 | return nWP; | ||
830 | } | ||
831 | |||
832 | public void RemoveRegionWindlightSettings(UUID regionID) | ||
833 | { | ||
834 | string sql = @"delete from regionwindlight where ""region_id"" = :region_id"; | ||
835 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
836 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
837 | { | ||
838 | conn.Open(); | ||
839 | cmd.Parameters.Add(_Database.CreateParameter("region_id", regionID.ToString())); | ||
840 | cmd.ExecuteNonQuery(); | ||
841 | } | ||
842 | } | ||
843 | |||
844 | public void StoreRegionWindlightSettings(RegionLightShareData wl) | ||
845 | { | ||
846 | string sql = @"select region_id from regionwindlight where ""region_id"" = :region_id limit 1;"; | ||
847 | bool exists = false; | ||
848 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
849 | { | ||
850 | conn.Open(); | ||
851 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
852 | { | ||
853 | cmd.Parameters.Add(_Database.CreateParameter("region_id", wl.regionID.ToString() )); | ||
854 | NpgsqlDataReader dr = cmd.ExecuteReader(); | ||
855 | exists = dr.Read(); | ||
856 | } | ||
857 | } | ||
858 | if (exists) | ||
859 | { | ||
860 | RemoveRegionWindlightSettings(wl.regionID); | ||
861 | } | ||
862 | |||
863 | // sql insert | ||
864 | sql = @"INSERT INTO regionwindlight | ||
865 | (region_id | ||
866 | ,water_color_r | ||
867 | ,water_color_g | ||
868 | ,water_color_b | ||
869 | ,water_fog_density_exponent | ||
870 | ,underwater_fog_modifier | ||
871 | ,reflection_wavelet_scale_1 | ||
872 | ,reflection_wavelet_scale_2 | ||
873 | ,reflection_wavelet_scale_3 | ||
874 | ,fresnel_scale | ||
875 | ,fresnel_offset | ||
876 | ,refract_scale_above | ||
877 | ,refract_scale_below | ||
878 | ,blur_multiplier | ||
879 | ,big_wave_direction_x | ||
880 | ,big_wave_direction_y | ||
881 | ,little_wave_direction_x | ||
882 | ,little_wave_direction_y | ||
883 | ,normal_map_texture | ||
884 | ,horizon_r | ||
885 | ,horizon_g | ||
886 | ,horizon_b | ||
887 | ,horizon_i | ||
888 | ,haze_horizon | ||
889 | ,blue_density_r | ||
890 | ,blue_density_g | ||
891 | ,blue_density_b | ||
892 | ,blue_density_i | ||
893 | ,haze_density | ||
894 | ,density_multiplier | ||
895 | ,distance_multiplier | ||
896 | ,max_altitude | ||
897 | ,sun_moon_color_r | ||
898 | ,sun_moon_color_g | ||
899 | ,sun_moon_color_b | ||
900 | ,sun_moon_color_i | ||
901 | ,sun_moon_position | ||
902 | ,ambient_r | ||
903 | ,ambient_g | ||
904 | ,ambient_b | ||
905 | ,ambient_i | ||
906 | ,east_angle | ||
907 | ,sun_glow_focus | ||
908 | ,sun_glow_size | ||
909 | ,scene_gamma | ||
910 | ,star_brightness | ||
911 | ,cloud_color_r | ||
912 | ,cloud_color_g | ||
913 | ,cloud_color_b | ||
914 | ,cloud_color_i | ||
915 | ,cloud_x | ||
916 | ,cloud_y | ||
917 | ,cloud_density | ||
918 | ,cloud_coverage | ||
919 | ,cloud_scale | ||
920 | ,cloud_detail_x | ||
921 | ,cloud_detail_y | ||
922 | ,cloud_detail_density | ||
923 | ,cloud_scroll_x | ||
924 | ,cloud_scroll_x_lock | ||
925 | ,cloud_scroll_y | ||
926 | ,cloud_scroll_y_lock | ||
927 | ,draw_classic_clouds) | ||
928 | VALUES | ||
929 | (:region_id | ||
930 | ,:water_color_r | ||
931 | ,:water_color_g | ||
932 | ,:water_color_b | ||
933 | ,:water_fog_density_exponent | ||
934 | ,:underwater_fog_modifier | ||
935 | ,:reflection_wavelet_scale_1 | ||
936 | ,:reflection_wavelet_scale_2 | ||
937 | ,:reflection_wavelet_scale_3 | ||
938 | ,:fresnel_scale | ||
939 | ,:fresnel_offset | ||
940 | ,:refract_scale_above | ||
941 | ,:refract_scale_below | ||
942 | ,:blur_multiplier | ||
943 | ,:big_wave_direction_x | ||
944 | ,:big_wave_direction_y | ||
945 | ,:little_wave_direction_x | ||
946 | ,:little_wave_direction_y | ||
947 | ,:normal_map_texture | ||
948 | ,:horizon_r | ||
949 | ,:horizon_g | ||
950 | ,:horizon_b | ||
951 | ,:horizon_i | ||
952 | ,:haze_horizon | ||
953 | ,:blue_density_r | ||
954 | ,:blue_density_g | ||
955 | ,:blue_density_b | ||
956 | ,:blue_density_i | ||
957 | ,:haze_density | ||
958 | ,:density_multiplier | ||
959 | ,:distance_multiplier | ||
960 | ,:max_altitude | ||
961 | ,:sun_moon_color_r | ||
962 | ,:sun_moon_color_g | ||
963 | ,:sun_moon_color_b | ||
964 | ,:sun_moon_color_i | ||
965 | ,:sun_moon_position | ||
966 | ,:ambient_r | ||
967 | ,:ambient_g | ||
968 | ,:ambient_b | ||
969 | ,:ambient_i | ||
970 | ,:east_angle | ||
971 | ,:sun_glow_focus | ||
972 | ,:sun_glow_size | ||
973 | ,:scene_gamma | ||
974 | ,:star_brightness | ||
975 | ,:cloud_color_r | ||
976 | ,:cloud_color_g | ||
977 | ,:cloud_color_b | ||
978 | ,:cloud_color_i | ||
979 | ,:cloud_x | ||
980 | ,:cloud_y | ||
981 | ,:cloud_density | ||
982 | ,:cloud_coverage | ||
983 | ,:cloud_scale | ||
984 | ,:cloud_detail_x | ||
985 | ,:cloud_detail_y | ||
986 | ,:cloud_detail_density | ||
987 | ,:cloud_scroll_x | ||
988 | ,:cloud_scroll_x_lock | ||
989 | ,:cloud_scroll_y | ||
990 | ,:cloud_scroll_y_lock | ||
991 | ,:draw_classic_clouds);"; | ||
992 | |||
993 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
994 | { | ||
995 | conn.Open(); | ||
996 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
997 | { | ||
998 | cmd.Parameters.Add(_Database.CreateParameter("region_id", wl.regionID.ToString())); | ||
999 | cmd.Parameters.Add(_Database.CreateParameter("water_color_r", wl.waterColor.X)); | ||
1000 | cmd.Parameters.Add(_Database.CreateParameter("water_color_g", wl.waterColor.Y)); | ||
1001 | cmd.Parameters.Add(_Database.CreateParameter("water_color_b", wl.waterColor.Z)); | ||
1002 | cmd.Parameters.Add(_Database.CreateParameter("water_fog_density_exponent", wl.waterFogDensityExponent)); | ||
1003 | cmd.Parameters.Add(_Database.CreateParameter("underwater_fog_modifier", wl.underwaterFogModifier)); | ||
1004 | cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X)); | ||
1005 | cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y)); | ||
1006 | cmd.Parameters.Add(_Database.CreateParameter("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z)); | ||
1007 | cmd.Parameters.Add(_Database.CreateParameter("fresnel_scale", wl.fresnelScale)); | ||
1008 | cmd.Parameters.Add(_Database.CreateParameter("fresnel_offset", wl.fresnelOffset)); | ||
1009 | cmd.Parameters.Add(_Database.CreateParameter("refract_scale_above", wl.refractScaleAbove)); | ||
1010 | cmd.Parameters.Add(_Database.CreateParameter("refract_scale_below", wl.refractScaleBelow)); | ||
1011 | cmd.Parameters.Add(_Database.CreateParameter("blur_multiplier", wl.blurMultiplier)); | ||
1012 | cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_x", wl.bigWaveDirection.X)); | ||
1013 | cmd.Parameters.Add(_Database.CreateParameter("big_wave_direction_y", wl.bigWaveDirection.Y)); | ||
1014 | cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_x", wl.littleWaveDirection.X)); | ||
1015 | cmd.Parameters.Add(_Database.CreateParameter("little_wave_direction_y", wl.littleWaveDirection.Y)); | ||
1016 | cmd.Parameters.Add(_Database.CreateParameter("normal_map_texture", wl.normalMapTexture.ToString())); | ||
1017 | cmd.Parameters.Add(_Database.CreateParameter("horizon_r", wl.horizon.X)); | ||
1018 | cmd.Parameters.Add(_Database.CreateParameter("horizon_g", wl.horizon.Y)); | ||
1019 | cmd.Parameters.Add(_Database.CreateParameter("horizon_b", wl.horizon.Z)); | ||
1020 | cmd.Parameters.Add(_Database.CreateParameter("horizon_i", wl.horizon.W)); | ||
1021 | cmd.Parameters.Add(_Database.CreateParameter("haze_horizon", wl.hazeHorizon)); | ||
1022 | cmd.Parameters.Add(_Database.CreateParameter("blue_density_r", wl.blueDensity.X)); | ||
1023 | cmd.Parameters.Add(_Database.CreateParameter("blue_density_g", wl.blueDensity.Y)); | ||
1024 | cmd.Parameters.Add(_Database.CreateParameter("blue_density_b", wl.blueDensity.Z)); | ||
1025 | cmd.Parameters.Add(_Database.CreateParameter("blue_density_i", wl.blueDensity.W)); | ||
1026 | cmd.Parameters.Add(_Database.CreateParameter("haze_density", wl.hazeDensity)); | ||
1027 | cmd.Parameters.Add(_Database.CreateParameter("density_multiplier", wl.densityMultiplier)); | ||
1028 | cmd.Parameters.Add(_Database.CreateParameter("distance_multiplier", wl.distanceMultiplier)); | ||
1029 | cmd.Parameters.Add(_Database.CreateParameter("max_altitude", wl.maxAltitude)); | ||
1030 | cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_r", wl.sunMoonColor.X)); | ||
1031 | cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_g", wl.sunMoonColor.Y)); | ||
1032 | cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_b", wl.sunMoonColor.Z)); | ||
1033 | cmd.Parameters.Add(_Database.CreateParameter("sun_moon_color_i", wl.sunMoonColor.W)); | ||
1034 | cmd.Parameters.Add(_Database.CreateParameter("sun_moon_position", wl.sunMoonPosition)); | ||
1035 | cmd.Parameters.Add(_Database.CreateParameter("ambient_r", wl.ambient.X)); | ||
1036 | cmd.Parameters.Add(_Database.CreateParameter("ambient_g", wl.ambient.Y)); | ||
1037 | cmd.Parameters.Add(_Database.CreateParameter("ambient_b", wl.ambient.Z)); | ||
1038 | cmd.Parameters.Add(_Database.CreateParameter("ambient_i", wl.ambient.W)); | ||
1039 | cmd.Parameters.Add(_Database.CreateParameter("east_angle", wl.eastAngle)); | ||
1040 | cmd.Parameters.Add(_Database.CreateParameter("sun_glow_focus", wl.sunGlowFocus)); | ||
1041 | cmd.Parameters.Add(_Database.CreateParameter("sun_glow_size", wl.sunGlowSize)); | ||
1042 | cmd.Parameters.Add(_Database.CreateParameter("scene_gamma", wl.sceneGamma)); | ||
1043 | cmd.Parameters.Add(_Database.CreateParameter("star_brightness", wl.starBrightness)); | ||
1044 | cmd.Parameters.Add(_Database.CreateParameter("cloud_color_r", wl.cloudColor.X)); | ||
1045 | cmd.Parameters.Add(_Database.CreateParameter("cloud_color_g", wl.cloudColor.Y)); | ||
1046 | cmd.Parameters.Add(_Database.CreateParameter("cloud_color_b", wl.cloudColor.Z)); | ||
1047 | cmd.Parameters.Add(_Database.CreateParameter("cloud_color_i", wl.cloudColor.W)); | ||
1048 | cmd.Parameters.Add(_Database.CreateParameter("cloud_x", wl.cloudXYDensity.X)); | ||
1049 | cmd.Parameters.Add(_Database.CreateParameter("cloud_y", wl.cloudXYDensity.Y)); | ||
1050 | cmd.Parameters.Add(_Database.CreateParameter("cloud_density", wl.cloudXYDensity.Z)); | ||
1051 | cmd.Parameters.Add(_Database.CreateParameter("cloud_coverage", wl.cloudCoverage)); | ||
1052 | cmd.Parameters.Add(_Database.CreateParameter("cloud_scale", wl.cloudScale)); | ||
1053 | cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_x", wl.cloudDetailXYDensity.X)); | ||
1054 | cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_y", wl.cloudDetailXYDensity.Y)); | ||
1055 | cmd.Parameters.Add(_Database.CreateParameter("cloud_detail_density", wl.cloudDetailXYDensity.Z)); | ||
1056 | cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x", wl.cloudScrollX)); | ||
1057 | cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_x_lock", wl.cloudScrollXLock)); | ||
1058 | cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y", wl.cloudScrollY)); | ||
1059 | cmd.Parameters.Add(_Database.CreateParameter("cloud_scroll_y_lock", wl.cloudScrollYLock)); | ||
1060 | cmd.Parameters.Add(_Database.CreateParameter("draw_classic_clouds", wl.drawClassicClouds)); | ||
1061 | |||
1062 | cmd.ExecuteNonQuery(); | ||
1063 | } | ||
1064 | } | ||
1065 | #region update | ||
1066 | // } | ||
1067 | // else | ||
1068 | // { | ||
1069 | // // sql update | ||
1070 | // sql = @"UPDATE [OpenSim].[dbo].[regionwindlight] | ||
1071 | // SET [region_id] = @region_id | ||
1072 | // ,[water_color_r] = @water_color_r | ||
1073 | // ,[water_color_g] = @water_color_g | ||
1074 | // ,[water_color_b] = @water_color_b | ||
1075 | // ,[water_fog_density_exponent] = @water_fog_density_exponent | ||
1076 | // ,[underwater_fog_modifier] = @underwater_fog_modifier | ||
1077 | // ,[reflection_wavelet_scale_1] = @reflection_wavelet_scale_1 | ||
1078 | // ,[reflection_wavelet_scale_2] = @reflection_wavelet_scale_2 | ||
1079 | // ,[reflection_wavelet_scale_3] = @reflection_wavelet_scale_3 | ||
1080 | // ,[fresnel_scale] = @fresnel_scale | ||
1081 | // ,[fresnel_offset] = @fresnel_offset | ||
1082 | // ,[refract_scale_above] = @refract_scale_above | ||
1083 | // ,[refract_scale_below] = @refract_scale_below | ||
1084 | // ,[blur_multiplier] = @blur_multiplier | ||
1085 | // ,[big_wave_direction_x] = @big_wave_direction_x | ||
1086 | // ,[big_wave_direction_y] = @big_wave_direction_y | ||
1087 | // ,[little_wave_direction_x] = @little_wave_direction_x | ||
1088 | // ,[little_wave_direction_y] = @little_wave_direction_y | ||
1089 | // ,[normal_map_texture] = @normal_map_texture | ||
1090 | // ,[horizon_r] = @horizon_r | ||
1091 | // ,[horizon_g] = @horizon_g | ||
1092 | // ,[horizon_b] = @horizon_b | ||
1093 | // ,[horizon_i] = @horizon_i | ||
1094 | // ,[haze_horizon] = @haze_horizon | ||
1095 | // ,[blue_density_r] = @blue_density_r | ||
1096 | // ,[blue_density_g] = @blue_density_g | ||
1097 | // ,[blue_density_b] = @blue_density_b | ||
1098 | // ,[blue_density_i] = @blue_density_i | ||
1099 | // ,[haze_density] = @haze_density | ||
1100 | // ,[density_multiplier] = @density_multiplier | ||
1101 | // ,[distance_multiplier] = @distance_multiplier | ||
1102 | // ,[max_altitude] = @max_altitude | ||
1103 | // ,[sun_moon_color_r] = @sun_moon_color_r | ||
1104 | // ,[sun_moon_color_g] = @sun_moon_color_g | ||
1105 | // ,[sun_moon_color_b] = @sun_moon_color_b | ||
1106 | // ,[sun_moon_color_i] = @sun_moon_color_i | ||
1107 | // ,[sun_moon_position] = @sun_moon_position | ||
1108 | // ,[ambient_r] = @ambient_r | ||
1109 | // ,[ambient_g] = @ambient_g | ||
1110 | // ,[ambient_b] = @ambient_b | ||
1111 | // ,[ambient_i] = @ambient_i | ||
1112 | // ,[east_angle] = @east_angle | ||
1113 | // ,[sun_glow_focus] = @sun_glow_focus | ||
1114 | // ,[sun_glow_size] = @sun_glow_size | ||
1115 | // ,[scene_gamma] = @scene_gamma | ||
1116 | // ,[star_brightness] = @star_brightness | ||
1117 | // ,[cloud_color_r] = @cloud_color_r | ||
1118 | // ,[cloud_color_g] = @cloud_color_g | ||
1119 | // ,[cloud_color_b] = @cloud_color_b | ||
1120 | // ,[cloud_color_i] = @cloud_color_i | ||
1121 | // ,[cloud_x] = @cloud_x | ||
1122 | // ,[cloud_y] = @cloud_y | ||
1123 | // ,[cloud_density] = @cloud_density | ||
1124 | // ,[cloud_coverage] = @cloud_coverage | ||
1125 | // ,[cloud_scale] = @cloud_scale | ||
1126 | // ,[cloud_detail_x] = @cloud_detail_x | ||
1127 | // ,[cloud_detail_y] = @cloud_detail_y | ||
1128 | // ,[cloud_detail_density] = @cloud_detail_density | ||
1129 | // ,[cloud_scroll_x] = @cloud_scroll_x | ||
1130 | // ,[cloud_scroll_x_lock] = @cloud_scroll_x_lock | ||
1131 | // ,[cloud_scroll_y] = @cloud_scroll_y | ||
1132 | // ,[cloud_scroll_y_lock] = @cloud_scroll_y_lock | ||
1133 | // ,[draw_classic_clouds] = @draw_classic_clouds | ||
1134 | // WHERE region_id = @region_id"; | ||
1135 | // using (SqlConnection conn = new SqlConnection(m_connectionString)) | ||
1136 | // { | ||
1137 | // conn.Open(); | ||
1138 | // using (SqlCommand cmd = new SqlCommand(sql, conn)) | ||
1139 | // { | ||
1140 | // cmd.Parameters.AddWithValue("region_id", wl.regionID); | ||
1141 | // cmd.Parameters.AddWithValue("water_color_r", wl.waterColor.X); | ||
1142 | // cmd.Parameters.AddWithValue("water_color_g", wl.waterColor.Y); | ||
1143 | // cmd.Parameters.AddWithValue("water_color_b", wl.waterColor.Z); | ||
1144 | // cmd.Parameters.AddWithValue("water_fog_density_exponent", wl.waterFogDensityExponent); | ||
1145 | // cmd.Parameters.AddWithValue("underwater_fog_modifier", wl.underwaterFogModifier); | ||
1146 | // cmd.Parameters.AddWithValue("reflection_wavelet_scale_1", wl.reflectionWaveletScale.X); | ||
1147 | // cmd.Parameters.AddWithValue("reflection_wavelet_scale_2", wl.reflectionWaveletScale.Y); | ||
1148 | // cmd.Parameters.AddWithValue("reflection_wavelet_scale_3", wl.reflectionWaveletScale.Z); | ||
1149 | // cmd.Parameters.AddWithValue("fresnel_scale", wl.fresnelScale); | ||
1150 | // cmd.Parameters.AddWithValue("fresnel_offset", wl.fresnelOffset); | ||
1151 | // cmd.Parameters.AddWithValue("refract_scale_above", wl.refractScaleAbove); | ||
1152 | // cmd.Parameters.AddWithValue("refract_scale_below", wl.refractScaleBelow); | ||
1153 | // cmd.Parameters.AddWithValue("blur_multiplier", wl.blurMultiplier); | ||
1154 | // cmd.Parameters.AddWithValue("big_wave_direction_x", wl.bigWaveDirection.X); | ||
1155 | // cmd.Parameters.AddWithValue("big_wave_direction_y", wl.bigWaveDirection.Y); | ||
1156 | // cmd.Parameters.AddWithValue("little_wave_direction_x", wl.littleWaveDirection.X); | ||
1157 | // cmd.Parameters.AddWithValue("little_wave_direction_y", wl.littleWaveDirection.Y); | ||
1158 | // cmd.Parameters.AddWithValue("normal_map_texture", wl.normalMapTexture); | ||
1159 | // cmd.Parameters.AddWithValue("horizon_r", wl.horizon.X); | ||
1160 | // cmd.Parameters.AddWithValue("horizon_g", wl.horizon.Y); | ||
1161 | // cmd.Parameters.AddWithValue("horizon_b", wl.horizon.Z); | ||
1162 | // cmd.Parameters.AddWithValue("horizon_i", wl.horizon.W); | ||
1163 | // cmd.Parameters.AddWithValue("haze_horizon", wl.hazeHorizon); | ||
1164 | // cmd.Parameters.AddWithValue("blue_density_r", wl.blueDensity.X); | ||
1165 | // cmd.Parameters.AddWithValue("blue_density_g", wl.blueDensity.Y); | ||
1166 | // cmd.Parameters.AddWithValue("blue_density_b", wl.blueDensity.Z); | ||
1167 | // cmd.Parameters.AddWithValue("blue_density_i", wl.blueDensity.W); | ||
1168 | // cmd.Parameters.AddWithValue("haze_density", wl.hazeDensity); | ||
1169 | // cmd.Parameters.AddWithValue("density_multiplier", wl.densityMultiplier); | ||
1170 | // cmd.Parameters.AddWithValue("distance_multiplier", wl.distanceMultiplier); | ||
1171 | // cmd.Parameters.AddWithValue("max_altitude", wl.maxAltitude); | ||
1172 | // cmd.Parameters.AddWithValue("sun_moon_color_r", wl.sunMoonColor.X); | ||
1173 | // cmd.Parameters.AddWithValue("sun_moon_color_g", wl.sunMoonColor.Y); | ||
1174 | // cmd.Parameters.AddWithValue("sun_moon_color_b", wl.sunMoonColor.Z); | ||
1175 | // cmd.Parameters.AddWithValue("sun_moon_color_i", wl.sunMoonColor.W); | ||
1176 | // cmd.Parameters.AddWithValue("sun_moon_position", wl.sunMoonPosition); | ||
1177 | // cmd.Parameters.AddWithValue("ambient_r", wl.ambient.X); | ||
1178 | // cmd.Parameters.AddWithValue("ambient_g", wl.ambient.Y); | ||
1179 | // cmd.Parameters.AddWithValue("ambient_b", wl.ambient.Z); | ||
1180 | // cmd.Parameters.AddWithValue("ambient_i", wl.ambient.W); | ||
1181 | // cmd.Parameters.AddWithValue("east_angle", wl.eastAngle); | ||
1182 | // cmd.Parameters.AddWithValue("sun_glow_focus", wl.sunGlowFocus); | ||
1183 | // cmd.Parameters.AddWithValue("sun_glow_size", wl.sunGlowSize); | ||
1184 | // cmd.Parameters.AddWithValue("scene_gamma", wl.sceneGamma); | ||
1185 | // cmd.Parameters.AddWithValue("star_brightness", wl.starBrightness); | ||
1186 | // cmd.Parameters.AddWithValue("cloud_color_r", wl.cloudColor.X); | ||
1187 | // cmd.Parameters.AddWithValue("cloud_color_g", wl.cloudColor.Y); | ||
1188 | // cmd.Parameters.AddWithValue("cloud_color_b", wl.cloudColor.Z); | ||
1189 | // cmd.Parameters.AddWithValue("cloud_color_i", wl.cloudColor.W); | ||
1190 | // cmd.Parameters.AddWithValue("cloud_x", wl.cloudXYDensity.X); | ||
1191 | // cmd.Parameters.AddWithValue("cloud_y", wl.cloudXYDensity.Y); | ||
1192 | // cmd.Parameters.AddWithValue("cloud_density", wl.cloudXYDensity.Z); | ||
1193 | // cmd.Parameters.AddWithValue("cloud_coverage", wl.cloudCoverage); | ||
1194 | // cmd.Parameters.AddWithValue("cloud_scale", wl.cloudScale); | ||
1195 | // cmd.Parameters.AddWithValue("cloud_detail_x", wl.cloudDetailXYDensity.X); | ||
1196 | // cmd.Parameters.AddWithValue("cloud_detail_y", wl.cloudDetailXYDensity.Y); | ||
1197 | // cmd.Parameters.AddWithValue("cloud_detail_density", wl.cloudDetailXYDensity.Z); | ||
1198 | // cmd.Parameters.AddWithValue("cloud_scroll_x", wl.cloudScrollX); | ||
1199 | // cmd.Parameters.AddWithValue("cloud_scroll_x_lock", wl.cloudScrollXLock); | ||
1200 | // cmd.Parameters.AddWithValue("cloud_scroll_y", wl.cloudScrollY); | ||
1201 | // cmd.Parameters.AddWithValue("cloud_scroll_y_lock", wl.cloudScrollYLock); | ||
1202 | // cmd.Parameters.AddWithValue("draw_classic_clouds", wl.drawClassicClouds); | ||
1203 | |||
1204 | // cmd.ExecuteNonQuery(); | ||
1205 | // } | ||
1206 | // } | ||
1207 | // } | ||
1208 | #endregion | ||
1209 | } | ||
1210 | |||
1211 | #region Environment Settings | ||
1212 | public string LoadRegionEnvironmentSettings(UUID regionUUID) | ||
1213 | { | ||
1214 | string sql = "select * from regionenvironment where region_id = :region_id"; | ||
1215 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1216 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1217 | { | ||
1218 | cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID)); | ||
1219 | conn.Open(); | ||
1220 | using (NpgsqlDataReader result = cmd.ExecuteReader()) | ||
1221 | { | ||
1222 | if (!result.Read()) | ||
1223 | { | ||
1224 | return String.Empty; | ||
1225 | } | ||
1226 | else | ||
1227 | { | ||
1228 | return Convert.ToString(result["llsd_settings"]); | ||
1229 | } | ||
1230 | } | ||
1231 | } | ||
1232 | } | ||
1233 | |||
1234 | public void StoreRegionEnvironmentSettings(UUID regionUUID, string settings) | ||
1235 | { | ||
1236 | { | ||
1237 | string sql = "DELETE FROM regionenvironment WHERE region_id = :region_id ;"; | ||
1238 | |||
1239 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1240 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1241 | { | ||
1242 | cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID)); | ||
1243 | conn.Open(); | ||
1244 | cmd.ExecuteNonQuery(); | ||
1245 | } | ||
1246 | |||
1247 | sql = "INSERT INTO regionenvironment (region_id, llsd_settings) VALUES (:region_id, :llsd_settings) ;"; | ||
1248 | |||
1249 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1250 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1251 | { | ||
1252 | cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID)); | ||
1253 | cmd.Parameters.Add(_Database.CreateParameter("llsd_settings", settings)); | ||
1254 | |||
1255 | conn.Open(); | ||
1256 | cmd.ExecuteNonQuery(); | ||
1257 | } | ||
1258 | } | ||
1259 | } | ||
1260 | |||
1261 | public void RemoveRegionEnvironmentSettings(UUID regionUUID) | ||
1262 | { | ||
1263 | string sql = "delete from regionenvironment where region_id = :region_id ;"; | ||
1264 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1265 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1266 | { | ||
1267 | cmd.Parameters.Add(_Database.CreateParameter("region_id", regionUUID)); | ||
1268 | |||
1269 | conn.Open(); | ||
1270 | cmd.ExecuteNonQuery(); | ||
1271 | } | ||
1272 | } | ||
1273 | #endregion | ||
1274 | |||
1275 | /// <summary> | ||
1276 | /// Loads the settings of a region. | ||
1277 | /// </summary> | ||
1278 | /// <param name="regionUUID">The region UUID.</param> | ||
1279 | /// <returns></returns> | ||
1280 | public RegionSettings LoadRegionSettings(UUID regionUUID) | ||
1281 | { | ||
1282 | string sql = @"select * from regionsettings where ""regionUUID"" = :regionUUID"; | ||
1283 | RegionSettings regionSettings; | ||
1284 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1285 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1286 | { | ||
1287 | cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionUUID)); | ||
1288 | conn.Open(); | ||
1289 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
1290 | { | ||
1291 | if (reader.Read()) | ||
1292 | { | ||
1293 | regionSettings = BuildRegionSettings(reader); | ||
1294 | regionSettings.OnSave += StoreRegionSettings; | ||
1295 | |||
1296 | return regionSettings; | ||
1297 | } | ||
1298 | } | ||
1299 | } | ||
1300 | |||
1301 | //If we reach this point then there are new region settings for that region | ||
1302 | regionSettings = new RegionSettings(); | ||
1303 | regionSettings.RegionUUID = regionUUID; | ||
1304 | regionSettings.OnSave += StoreRegionSettings; | ||
1305 | |||
1306 | //Store new values | ||
1307 | StoreNewRegionSettings(regionSettings); | ||
1308 | |||
1309 | LoadSpawnPoints(regionSettings); | ||
1310 | |||
1311 | return regionSettings; | ||
1312 | } | ||
1313 | |||
1314 | /// <summary> | ||
1315 | /// Store region settings, need to check if the check is really necesary. If we can make something for creating new region. | ||
1316 | /// </summary> | ||
1317 | /// <param name="regionSettings">region settings.</param> | ||
1318 | public void StoreRegionSettings(RegionSettings regionSettings) | ||
1319 | { | ||
1320 | //Little check if regionUUID already exist in DB | ||
1321 | string regionUUID; | ||
1322 | string sql = @"SELECT ""regionUUID"" FROM regionsettings WHERE ""regionUUID"" = :regionUUID"; | ||
1323 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1324 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1325 | { | ||
1326 | cmd.Parameters.Add(_Database.CreateParameter("regionUUID", regionSettings.RegionUUID)); | ||
1327 | conn.Open(); | ||
1328 | regionUUID = cmd.ExecuteScalar().ToString(); | ||
1329 | } | ||
1330 | |||
1331 | if (string.IsNullOrEmpty(regionUUID)) | ||
1332 | { | ||
1333 | StoreNewRegionSettings(regionSettings); | ||
1334 | } | ||
1335 | else | ||
1336 | { | ||
1337 | //This method only updates region settings!!! First call LoadRegionSettings to create new region settings in DB | ||
1338 | sql = | ||
1339 | @"UPDATE regionsettings SET block_terraform = :block_terraform ,block_fly = :block_fly ,allow_damage = :allow_damage | ||
1340 | ,restrict_pushing = :restrict_pushing ,allow_land_resell = :allow_land_resell ,allow_land_join_divide = :allow_land_join_divide | ||
1341 | ,block_show_in_search = :block_show_in_search ,agent_limit = :agent_limit ,object_bonus = :object_bonus ,maturity = :maturity | ||
1342 | ,disable_scripts = :disable_scripts ,disable_collisions = :disable_collisions ,disable_physics = :disable_physics | ||
1343 | ,terrain_texture_1 = :terrain_texture_1 ,terrain_texture_2 = :terrain_texture_2 ,terrain_texture_3 = :terrain_texture_3 | ||
1344 | ,terrain_texture_4 = :terrain_texture_4 ,elevation_1_nw = :elevation_1_nw ,elevation_2_nw = :elevation_2_nw | ||
1345 | ,elevation_1_ne = :elevation_1_ne ,elevation_2_ne = :elevation_2_ne ,elevation_1_se = :elevation_1_se ,elevation_2_se = :elevation_2_se | ||
1346 | ,elevation_1_sw = :elevation_1_sw ,elevation_2_sw = :elevation_2_sw ,water_height = :water_height ,terrain_raise_limit = :terrain_raise_limit | ||
1347 | ,terrain_lower_limit = :terrain_lower_limit ,use_estate_sun = :use_estate_sun ,fixed_sun = :fixed_sun ,sun_position = :sun_position | ||
1348 | ,covenant = :covenant ,covenant_datetime = :covenant_datetime, sunvectorx = :sunvectorx, sunvectory = :sunvectory, sunvectorz = :sunvectorz, | ||
1349 | ""Sandbox"" = :Sandbox, loaded_creation_datetime = :loaded_creation_datetime, loaded_creation_id = :loaded_creation_id, ""map_tile_ID"" = :TerrainImageID, | ||
1350 | ""TelehubObject"" = :telehubobject, ""parcel_tile_ID"" = :ParcelImageID | ||
1351 | WHERE ""regionUUID"" = :regionUUID"; | ||
1352 | |||
1353 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1354 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1355 | { | ||
1356 | cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings)); | ||
1357 | conn.Open(); | ||
1358 | cmd.ExecuteNonQuery(); | ||
1359 | } | ||
1360 | } | ||
1361 | SaveSpawnPoints(regionSettings); | ||
1362 | } | ||
1363 | |||
1364 | public void Shutdown() | ||
1365 | { | ||
1366 | //Not used?? | ||
1367 | } | ||
1368 | |||
1369 | #region Private Methods | ||
1370 | |||
1371 | /// <summary> | ||
1372 | /// Stores new regionsettings. | ||
1373 | /// </summary> | ||
1374 | /// <param name="regionSettings">The region settings.</param> | ||
1375 | private void StoreNewRegionSettings(RegionSettings regionSettings) | ||
1376 | { | ||
1377 | string sql = @"INSERT INTO regionsettings | ||
1378 | (""regionUUID"",block_terraform,block_fly,allow_damage,restrict_pushing,allow_land_resell,allow_land_join_divide, | ||
1379 | block_show_in_search,agent_limit,object_bonus,maturity,disable_scripts,disable_collisions,disable_physics, | ||
1380 | terrain_texture_1,terrain_texture_2,terrain_texture_3,terrain_texture_4,elevation_1_nw,elevation_2_nw,elevation_1_ne, | ||
1381 | elevation_2_ne,elevation_1_se,elevation_2_se,elevation_1_sw,elevation_2_sw,water_height,terrain_raise_limit, | ||
1382 | terrain_lower_limit,use_estate_sun,fixed_sun,sun_position,covenant,covenant_datetime,sunvectorx, sunvectory, sunvectorz, | ||
1383 | ""Sandbox"", loaded_creation_datetime, loaded_creation_id | ||
1384 | ) | ||
1385 | VALUES | ||
1386 | (:regionUUID,:block_terraform,:block_fly,:allow_damage,:restrict_pushing,:allow_land_resell,:allow_land_join_divide, | ||
1387 | :block_show_in_search,:agent_limit,:object_bonus,:maturity,:disable_scripts,:disable_collisions,:disable_physics, | ||
1388 | :terrain_texture_1,:terrain_texture_2,:terrain_texture_3,:terrain_texture_4,:elevation_1_nw,:elevation_2_nw,:elevation_1_ne, | ||
1389 | :elevation_2_ne,:elevation_1_se,:elevation_2_se,:elevation_1_sw,:elevation_2_sw,:water_height,:terrain_raise_limit, | ||
1390 | :terrain_lower_limit,:use_estate_sun,:fixed_sun,:sun_position,:covenant, :covenant_datetime, :sunvectorx,:sunvectory, | ||
1391 | :sunvectorz, :Sandbox, :loaded_creation_datetime, :loaded_creation_id )"; | ||
1392 | |||
1393 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
1394 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
1395 | { | ||
1396 | cmd.Parameters.AddRange(CreateRegionSettingParameters(regionSettings)); | ||
1397 | conn.Open(); | ||
1398 | cmd.ExecuteNonQuery(); | ||
1399 | } | ||
1400 | } | ||
1401 | |||
1402 | #region Private DataRecord conversion methods | ||
1403 | |||
1404 | /// <summary> | ||
1405 | /// Builds the region settings from a datarecod. | ||
1406 | /// </summary> | ||
1407 | /// <param name="row">datarecord with regionsettings.</param> | ||
1408 | /// <returns></returns> | ||
1409 | private static RegionSettings BuildRegionSettings(IDataRecord row) | ||
1410 | { | ||
1411 | //TODO change this is some more generic code so we doesnt have to change it every time a new field is added? | ||
1412 | RegionSettings newSettings = new RegionSettings(); | ||
1413 | |||
1414 | newSettings.RegionUUID = new UUID((Guid)row["regionUUID"]); | ||
1415 | newSettings.BlockTerraform = Convert.ToBoolean(row["block_terraform"]); | ||
1416 | newSettings.AllowDamage = Convert.ToBoolean(row["allow_damage"]); | ||
1417 | newSettings.BlockFly = Convert.ToBoolean(row["block_fly"]); | ||
1418 | newSettings.RestrictPushing = Convert.ToBoolean(row["restrict_pushing"]); | ||
1419 | newSettings.AllowLandResell = Convert.ToBoolean(row["allow_land_resell"]); | ||
1420 | newSettings.AllowLandJoinDivide = Convert.ToBoolean(row["allow_land_join_divide"]); | ||
1421 | newSettings.BlockShowInSearch = Convert.ToBoolean(row["block_show_in_search"]); | ||
1422 | newSettings.AgentLimit = Convert.ToInt32(row["agent_limit"]); | ||
1423 | newSettings.ObjectBonus = Convert.ToDouble(row["object_bonus"]); | ||
1424 | newSettings.Maturity = Convert.ToInt32(row["maturity"]); | ||
1425 | newSettings.DisableScripts = Convert.ToBoolean(row["disable_scripts"]); | ||
1426 | newSettings.DisableCollisions = Convert.ToBoolean(row["disable_collisions"]); | ||
1427 | newSettings.DisablePhysics = Convert.ToBoolean(row["disable_physics"]); | ||
1428 | newSettings.TerrainTexture1 = new UUID((Guid)row["terrain_texture_1"]); | ||
1429 | newSettings.TerrainTexture2 = new UUID((Guid)row["terrain_texture_2"]); | ||
1430 | newSettings.TerrainTexture3 = new UUID((Guid)row["terrain_texture_3"]); | ||
1431 | newSettings.TerrainTexture4 = new UUID((Guid)row["terrain_texture_4"]); | ||
1432 | newSettings.Elevation1NW = Convert.ToDouble(row["elevation_1_nw"]); | ||
1433 | newSettings.Elevation2NW = Convert.ToDouble(row["elevation_2_nw"]); | ||
1434 | newSettings.Elevation1NE = Convert.ToDouble(row["elevation_1_ne"]); | ||
1435 | newSettings.Elevation2NE = Convert.ToDouble(row["elevation_2_ne"]); | ||
1436 | newSettings.Elevation1SE = Convert.ToDouble(row["elevation_1_se"]); | ||
1437 | newSettings.Elevation2SE = Convert.ToDouble(row["elevation_2_se"]); | ||
1438 | newSettings.Elevation1SW = Convert.ToDouble(row["elevation_1_sw"]); | ||
1439 | newSettings.Elevation2SW = Convert.ToDouble(row["elevation_2_sw"]); | ||
1440 | newSettings.WaterHeight = Convert.ToDouble(row["water_height"]); | ||
1441 | newSettings.TerrainRaiseLimit = Convert.ToDouble(row["terrain_raise_limit"]); | ||
1442 | newSettings.TerrainLowerLimit = Convert.ToDouble(row["terrain_lower_limit"]); | ||
1443 | newSettings.UseEstateSun = Convert.ToBoolean(row["use_estate_sun"]); | ||
1444 | newSettings.Sandbox = Convert.ToBoolean(row["Sandbox"]); | ||
1445 | newSettings.FixedSun = Convert.ToBoolean(row["fixed_sun"]); | ||
1446 | newSettings.SunPosition = Convert.ToDouble(row["sun_position"]); | ||
1447 | newSettings.SunVector = new Vector3( | ||
1448 | Convert.ToSingle(row["sunvectorx"]), | ||
1449 | Convert.ToSingle(row["sunvectory"]), | ||
1450 | Convert.ToSingle(row["sunvectorz"]) | ||
1451 | ); | ||
1452 | newSettings.Covenant = new UUID((Guid)row["covenant"]); | ||
1453 | newSettings.CovenantChangedDateTime = Convert.ToInt32(row["covenant_datetime"]); | ||
1454 | newSettings.LoadedCreationDateTime = Convert.ToInt32(row["loaded_creation_datetime"]); | ||
1455 | |||
1456 | if (row["loaded_creation_id"] is DBNull) | ||
1457 | newSettings.LoadedCreationID = ""; | ||
1458 | else | ||
1459 | newSettings.LoadedCreationID = (String)row["loaded_creation_id"]; | ||
1460 | |||
1461 | newSettings.TerrainImageID = new UUID((string)row["map_tile_ID"]); | ||
1462 | newSettings.ParcelImageID = new UUID((Guid)row["parcel_tile_ID"]); | ||
1463 | newSettings.TelehubObject = new UUID((Guid)row["TelehubObject"]); | ||
1464 | |||
1465 | return newSettings; | ||
1466 | } | ||
1467 | |||
1468 | /// <summary> | ||
1469 | /// Builds the land data from a datarecord. | ||
1470 | /// </summary> | ||
1471 | /// <param name="row">datarecord with land data</param> | ||
1472 | /// <returns></returns> | ||
1473 | private static LandData BuildLandData(IDataRecord row) | ||
1474 | { | ||
1475 | LandData newData = new LandData(); | ||
1476 | |||
1477 | newData.GlobalID = new UUID((Guid)row["UUID"]); | ||
1478 | newData.LocalID = Convert.ToInt32(row["LocalLandID"]); | ||
1479 | |||
1480 | // Bitmap is a byte[512] | ||
1481 | newData.Bitmap = (Byte[])row["Bitmap"]; | ||
1482 | |||
1483 | newData.Name = (string)row["Name"]; | ||
1484 | newData.Description = (string)row["Description"]; | ||
1485 | newData.OwnerID = new UUID((Guid)row["OwnerUUID"]); | ||
1486 | newData.IsGroupOwned = Convert.ToBoolean(row["IsGroupOwned"]); | ||
1487 | newData.Area = Convert.ToInt32(row["Area"]); | ||
1488 | newData.AuctionID = Convert.ToUInt32(row["AuctionID"]); //Unemplemented | ||
1489 | newData.Category = (ParcelCategory)Convert.ToInt32(row["Category"]); | ||
1490 | //Enum libsecondlife.Parcel.ParcelCategory | ||
1491 | newData.ClaimDate = Convert.ToInt32(row["ClaimDate"]); | ||
1492 | newData.ClaimPrice = Convert.ToInt32(row["ClaimPrice"]); | ||
1493 | newData.GroupID = new UUID((Guid)row["GroupUUID"]); | ||
1494 | newData.SalePrice = Convert.ToInt32(row["SalePrice"]); | ||
1495 | newData.Status = (ParcelStatus)Convert.ToInt32(row["LandStatus"]); | ||
1496 | //Enum. libsecondlife.Parcel.ParcelStatus | ||
1497 | newData.Flags = Convert.ToUInt32(row["LandFlags"]); | ||
1498 | newData.LandingType = Convert.ToByte(row["LandingType"]); | ||
1499 | newData.MediaAutoScale = Convert.ToByte(row["MediaAutoScale"]); | ||
1500 | newData.MediaID = new UUID((Guid)row["MediaTextureUUID"]); | ||
1501 | newData.MediaURL = (string)row["MediaURL"]; | ||
1502 | newData.MusicURL = (string)row["MusicURL"]; | ||
1503 | newData.PassHours = Convert.ToSingle(row["PassHours"]); | ||
1504 | newData.PassPrice = Convert.ToInt32(row["PassPrice"]); | ||
1505 | |||
1506 | // UUID authedbuyer; | ||
1507 | // UUID snapshotID; | ||
1508 | // | ||
1509 | // if (UUID.TryParse((string)row["AuthBuyerID"], out authedbuyer)) | ||
1510 | // newData.AuthBuyerID = authedbuyer; | ||
1511 | // | ||
1512 | // if (UUID.TryParse((string)row["SnapshotUUID"], out snapshotID)) | ||
1513 | // newData.SnapshotID = snapshotID; | ||
1514 | newData.AuthBuyerID = new UUID((Guid)row["AuthBuyerID"]); | ||
1515 | newData.SnapshotID = new UUID((Guid)row["SnapshotUUID"]); | ||
1516 | |||
1517 | newData.OtherCleanTime = Convert.ToInt32(row["OtherCleanTime"]); | ||
1518 | |||
1519 | try | ||
1520 | { | ||
1521 | newData.UserLocation = | ||
1522 | new Vector3(Convert.ToSingle(row["UserLocationX"]), Convert.ToSingle(row["UserLocationY"]), | ||
1523 | Convert.ToSingle(row["UserLocationZ"])); | ||
1524 | newData.UserLookAt = | ||
1525 | new Vector3(Convert.ToSingle(row["UserLookAtX"]), Convert.ToSingle(row["UserLookAtY"]), | ||
1526 | Convert.ToSingle(row["UserLookAtZ"])); | ||
1527 | } | ||
1528 | catch (InvalidCastException) | ||
1529 | { | ||
1530 | newData.UserLocation = Vector3.Zero; | ||
1531 | newData.UserLookAt = Vector3.Zero; | ||
1532 | _Log.ErrorFormat("[PARCEL]: unable to get parcel telehub settings for {1}", newData.Name); | ||
1533 | } | ||
1534 | |||
1535 | newData.ParcelAccessList = new List<LandAccessEntry>(); | ||
1536 | newData.MediaDescription = (string)row["MediaDescription"]; | ||
1537 | newData.MediaType = (string)row["MediaType"]; | ||
1538 | newData.MediaWidth = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[0]); | ||
1539 | newData.MediaHeight = Convert.ToInt32((((string)row["MediaSize"]).Split(','))[1]); | ||
1540 | newData.MediaLoop = Convert.ToBoolean(row["MediaLoop"]); | ||
1541 | newData.ObscureMusic = Convert.ToBoolean(row["ObscureMusic"]); | ||
1542 | newData.ObscureMedia = Convert.ToBoolean(row["ObscureMedia"]); | ||
1543 | |||
1544 | return newData; | ||
1545 | } | ||
1546 | |||
1547 | /// <summary> | ||
1548 | /// Builds the landaccess data from a data record. | ||
1549 | /// </summary> | ||
1550 | /// <param name="row">datarecord with landaccess data</param> | ||
1551 | /// <returns></returns> | ||
1552 | private static LandAccessEntry BuildLandAccessData(IDataRecord row) | ||
1553 | { | ||
1554 | LandAccessEntry entry = new LandAccessEntry(); | ||
1555 | entry.AgentID = new UUID((Guid)row["AccessUUID"]); | ||
1556 | entry.Flags = (AccessList)Convert.ToInt32(row["Flags"]); | ||
1557 | entry.Expires = Convert.ToInt32(row["Expires"]); | ||
1558 | return entry; | ||
1559 | } | ||
1560 | |||
1561 | /// <summary> | ||
1562 | /// Builds the prim from a datarecord. | ||
1563 | /// </summary> | ||
1564 | /// <param name="primRow">datarecord</param> | ||
1565 | /// <returns></returns> | ||
1566 | private static SceneObjectPart BuildPrim(IDataRecord primRow) | ||
1567 | { | ||
1568 | SceneObjectPart prim = new SceneObjectPart(); | ||
1569 | |||
1570 | prim.UUID = new UUID((Guid)primRow["UUID"]); | ||
1571 | // explicit conversion of integers is required, which sort | ||
1572 | // of sucks. No idea if there is a shortcut here or not. | ||
1573 | prim.CreationDate = Convert.ToInt32(primRow["CreationDate"]); | ||
1574 | prim.Name = (string)primRow["Name"]; | ||
1575 | // various text fields | ||
1576 | prim.Text = (string)primRow["Text"]; | ||
1577 | prim.Color = Color.FromArgb(Convert.ToInt32(primRow["ColorA"]), | ||
1578 | Convert.ToInt32(primRow["ColorR"]), | ||
1579 | Convert.ToInt32(primRow["ColorG"]), | ||
1580 | Convert.ToInt32(primRow["ColorB"])); | ||
1581 | prim.Description = (string)primRow["Description"]; | ||
1582 | prim.SitName = (string)primRow["SitName"]; | ||
1583 | prim.TouchName = (string)primRow["TouchName"]; | ||
1584 | // permissions | ||
1585 | prim.Flags = (PrimFlags)Convert.ToUInt32(primRow["ObjectFlags"]); | ||
1586 | //prim.creatorID = new UUID((Guid)primRow["creatorID"]); | ||
1587 | prim.CreatorIdentification = (string)primRow["CreatorID"].ToString(); | ||
1588 | prim.OwnerID = new UUID((Guid)primRow["OwnerID"]); | ||
1589 | prim.GroupID = new UUID((Guid)primRow["GroupID"]); | ||
1590 | prim.LastOwnerID = new UUID((Guid)primRow["LastOwnerID"]); | ||
1591 | prim.OwnerMask = Convert.ToUInt32(primRow["OwnerMask"]); | ||
1592 | prim.NextOwnerMask = Convert.ToUInt32(primRow["NextOwnerMask"]); | ||
1593 | prim.GroupMask = Convert.ToUInt32(primRow["GroupMask"]); | ||
1594 | prim.EveryoneMask = Convert.ToUInt32(primRow["EveryoneMask"]); | ||
1595 | prim.BaseMask = Convert.ToUInt32(primRow["BaseMask"]); | ||
1596 | // vectors | ||
1597 | prim.OffsetPosition = new Vector3( | ||
1598 | Convert.ToSingle(primRow["PositionX"]), | ||
1599 | Convert.ToSingle(primRow["PositionY"]), | ||
1600 | Convert.ToSingle(primRow["PositionZ"])); | ||
1601 | |||
1602 | prim.GroupPosition = new Vector3( | ||
1603 | Convert.ToSingle(primRow["GroupPositionX"]), | ||
1604 | Convert.ToSingle(primRow["GroupPositionY"]), | ||
1605 | Convert.ToSingle(primRow["GroupPositionZ"])); | ||
1606 | |||
1607 | prim.Velocity = new Vector3( | ||
1608 | Convert.ToSingle(primRow["VelocityX"]), | ||
1609 | Convert.ToSingle(primRow["VelocityY"]), | ||
1610 | Convert.ToSingle(primRow["VelocityZ"])); | ||
1611 | |||
1612 | prim.AngularVelocity = new Vector3( | ||
1613 | Convert.ToSingle(primRow["AngularVelocityX"]), | ||
1614 | Convert.ToSingle(primRow["AngularVelocityY"]), | ||
1615 | Convert.ToSingle(primRow["AngularVelocityZ"])); | ||
1616 | |||
1617 | prim.Acceleration = new Vector3( | ||
1618 | Convert.ToSingle(primRow["AccelerationX"]), | ||
1619 | Convert.ToSingle(primRow["AccelerationY"]), | ||
1620 | Convert.ToSingle(primRow["AccelerationZ"])); | ||
1621 | |||
1622 | // quaternions | ||
1623 | prim.RotationOffset = new Quaternion( | ||
1624 | Convert.ToSingle(primRow["RotationX"]), | ||
1625 | Convert.ToSingle(primRow["RotationY"]), | ||
1626 | Convert.ToSingle(primRow["RotationZ"]), | ||
1627 | Convert.ToSingle(primRow["RotationW"])); | ||
1628 | |||
1629 | prim.SitTargetPositionLL = new Vector3( | ||
1630 | Convert.ToSingle(primRow["SitTargetOffsetX"]), | ||
1631 | Convert.ToSingle(primRow["SitTargetOffsetY"]), | ||
1632 | Convert.ToSingle(primRow["SitTargetOffsetZ"])); | ||
1633 | |||
1634 | prim.SitTargetOrientationLL = new Quaternion( | ||
1635 | Convert.ToSingle(primRow["SitTargetOrientX"]), | ||
1636 | Convert.ToSingle(primRow["SitTargetOrientY"]), | ||
1637 | Convert.ToSingle(primRow["SitTargetOrientZ"]), | ||
1638 | Convert.ToSingle(primRow["SitTargetOrientW"])); | ||
1639 | |||
1640 | prim.PayPrice[0] = Convert.ToInt32(primRow["PayPrice"]); | ||
1641 | prim.PayPrice[1] = Convert.ToInt32(primRow["PayButton1"]); | ||
1642 | prim.PayPrice[2] = Convert.ToInt32(primRow["PayButton2"]); | ||
1643 | prim.PayPrice[3] = Convert.ToInt32(primRow["PayButton3"]); | ||
1644 | prim.PayPrice[4] = Convert.ToInt32(primRow["PayButton4"]); | ||
1645 | |||
1646 | prim.Sound = new UUID((Guid)primRow["LoopedSound"]); | ||
1647 | prim.SoundGain = Convert.ToSingle(primRow["LoopedSoundGain"]); | ||
1648 | prim.SoundFlags = 1; // If it's persisted at all, it's looped | ||
1649 | |||
1650 | if (!(primRow["TextureAnimation"] is DBNull)) | ||
1651 | prim.TextureAnimation = (Byte[])primRow["TextureAnimation"]; | ||
1652 | if (!(primRow["ParticleSystem"] is DBNull)) | ||
1653 | prim.ParticleSystem = (Byte[])primRow["ParticleSystem"]; | ||
1654 | |||
1655 | prim.AngularVelocity = new Vector3( | ||
1656 | Convert.ToSingle(primRow["OmegaX"]), | ||
1657 | Convert.ToSingle(primRow["OmegaY"]), | ||
1658 | Convert.ToSingle(primRow["OmegaZ"])); | ||
1659 | |||
1660 | prim.SetCameraEyeOffset(new Vector3( | ||
1661 | Convert.ToSingle(primRow["CameraEyeOffsetX"]), | ||
1662 | Convert.ToSingle(primRow["CameraEyeOffsetY"]), | ||
1663 | Convert.ToSingle(primRow["CameraEyeOffsetZ"]) | ||
1664 | )); | ||
1665 | |||
1666 | prim.SetCameraAtOffset(new Vector3( | ||
1667 | Convert.ToSingle(primRow["CameraAtOffsetX"]), | ||
1668 | Convert.ToSingle(primRow["CameraAtOffsetY"]), | ||
1669 | Convert.ToSingle(primRow["CameraAtOffsetZ"]) | ||
1670 | )); | ||
1671 | |||
1672 | if (Convert.ToInt16(primRow["ForceMouselook"]) != 0) | ||
1673 | prim.SetForceMouselook(true); | ||
1674 | |||
1675 | prim.ScriptAccessPin = Convert.ToInt32(primRow["ScriptAccessPin"]); | ||
1676 | |||
1677 | if (Convert.ToInt16(primRow["AllowedDrop"]) != 0) | ||
1678 | prim.AllowedDrop = true; | ||
1679 | |||
1680 | if (Convert.ToInt16(primRow["DieAtEdge"]) != 0) | ||
1681 | prim.DIE_AT_EDGE = true; | ||
1682 | |||
1683 | prim.SalePrice = Convert.ToInt32(primRow["SalePrice"]); | ||
1684 | prim.ObjectSaleType = Convert.ToByte(primRow["SaleType"]); | ||
1685 | |||
1686 | prim.Material = Convert.ToByte(primRow["Material"]); | ||
1687 | |||
1688 | if (!(primRow["ClickAction"] is DBNull)) | ||
1689 | prim.ClickAction = Convert.ToByte(primRow["ClickAction"]); | ||
1690 | |||
1691 | prim.CollisionSound = new UUID((Guid)primRow["CollisionSound"]); | ||
1692 | prim.CollisionSoundVolume = Convert.ToSingle(primRow["CollisionSoundVolume"]); | ||
1693 | |||
1694 | prim.PassTouches = (bool)primRow["PassTouches"]; | ||
1695 | |||
1696 | if (!(primRow["MediaURL"] is System.DBNull)) | ||
1697 | prim.MediaUrl = (string)primRow["MediaURL"]; | ||
1698 | |||
1699 | if (!(primRow["DynAttrs"] is System.DBNull) && (string)primRow["DynAttrs"] != "") | ||
1700 | prim.DynAttrs = DAMap.FromXml((string)primRow["DynAttrs"]); | ||
1701 | else | ||
1702 | prim.DynAttrs = new DAMap(); | ||
1703 | |||
1704 | prim.PhysicsShapeType = Convert.ToByte(primRow["PhysicsShapeType"]); | ||
1705 | prim.Density = Convert.ToSingle(primRow["Density"]); | ||
1706 | prim.GravityModifier = Convert.ToSingle(primRow["GravityModifier"]); | ||
1707 | prim.Friction = Convert.ToSingle(primRow["Friction"]); | ||
1708 | prim.Restitution = Convert.ToSingle(primRow["Restitution"]); | ||
1709 | |||
1710 | return prim; | ||
1711 | } | ||
1712 | |||
1713 | /// <summary> | ||
1714 | /// Builds the prim shape from a datarecord. | ||
1715 | /// </summary> | ||
1716 | /// <param name="shapeRow">The row.</param> | ||
1717 | /// <returns></returns> | ||
1718 | private static PrimitiveBaseShape BuildShape(IDataRecord shapeRow) | ||
1719 | { | ||
1720 | PrimitiveBaseShape baseShape = new PrimitiveBaseShape(); | ||
1721 | |||
1722 | baseShape.Scale = new Vector3( | ||
1723 | (float)Convert.ToDouble(shapeRow["ScaleX"]), | ||
1724 | (float)Convert.ToDouble(shapeRow["ScaleY"]), | ||
1725 | (float)Convert.ToDouble(shapeRow["ScaleZ"])); | ||
1726 | |||
1727 | // paths | ||
1728 | baseShape.PCode = Convert.ToByte(shapeRow["PCode"]); | ||
1729 | baseShape.PathBegin = Convert.ToUInt16(shapeRow["PathBegin"]); | ||
1730 | baseShape.PathEnd = Convert.ToUInt16(shapeRow["PathEnd"]); | ||
1731 | baseShape.PathScaleX = Convert.ToByte(shapeRow["PathScaleX"]); | ||
1732 | baseShape.PathScaleY = Convert.ToByte(shapeRow["PathScaleY"]); | ||
1733 | baseShape.PathShearX = Convert.ToByte(shapeRow["PathShearX"]); | ||
1734 | baseShape.PathShearY = Convert.ToByte(shapeRow["PathShearY"]); | ||
1735 | baseShape.PathSkew = Convert.ToSByte(shapeRow["PathSkew"]); | ||
1736 | baseShape.PathCurve = Convert.ToByte(shapeRow["PathCurve"]); | ||
1737 | baseShape.PathRadiusOffset = Convert.ToSByte(shapeRow["PathRadiusOffset"]); | ||
1738 | baseShape.PathRevolutions = Convert.ToByte(shapeRow["PathRevolutions"]); | ||
1739 | baseShape.PathTaperX = Convert.ToSByte(shapeRow["PathTaperX"]); | ||
1740 | baseShape.PathTaperY = Convert.ToSByte(shapeRow["PathTaperY"]); | ||
1741 | baseShape.PathTwist = Convert.ToSByte(shapeRow["PathTwist"]); | ||
1742 | baseShape.PathTwistBegin = Convert.ToSByte(shapeRow["PathTwistBegin"]); | ||
1743 | // profile | ||
1744 | baseShape.ProfileBegin = Convert.ToUInt16(shapeRow["ProfileBegin"]); | ||
1745 | baseShape.ProfileEnd = Convert.ToUInt16(shapeRow["ProfileEnd"]); | ||
1746 | baseShape.ProfileCurve = Convert.ToByte(shapeRow["ProfileCurve"]); | ||
1747 | baseShape.ProfileHollow = Convert.ToUInt16(shapeRow["ProfileHollow"]); | ||
1748 | |||
1749 | byte[] textureEntry = (byte[])shapeRow["Texture"]; | ||
1750 | baseShape.TextureEntry = textureEntry; | ||
1751 | |||
1752 | baseShape.ExtraParams = (byte[])shapeRow["ExtraParams"]; | ||
1753 | |||
1754 | try | ||
1755 | { | ||
1756 | baseShape.State = Convert.ToByte(shapeRow["State"]); | ||
1757 | } | ||
1758 | catch (InvalidCastException) | ||
1759 | { | ||
1760 | } | ||
1761 | |||
1762 | if (!(shapeRow["Media"] is System.DBNull)) | ||
1763 | { | ||
1764 | baseShape.Media = PrimitiveBaseShape.MediaList.FromXml((string)shapeRow["Media"]); | ||
1765 | } | ||
1766 | |||
1767 | return baseShape; | ||
1768 | } | ||
1769 | |||
1770 | /// <summary> | ||
1771 | /// Build a prim inventory item from the persisted data. | ||
1772 | /// </summary> | ||
1773 | /// <param name="inventoryRow"></param> | ||
1774 | /// <returns></returns> | ||
1775 | private static TaskInventoryItem BuildItem(IDataRecord inventoryRow) | ||
1776 | { | ||
1777 | TaskInventoryItem taskItem = new TaskInventoryItem(); | ||
1778 | |||
1779 | taskItem.ItemID = new UUID((Guid)inventoryRow["itemID"]); | ||
1780 | taskItem.ParentPartID = new UUID((Guid)inventoryRow["primID"]); | ||
1781 | taskItem.AssetID = new UUID((Guid)inventoryRow["assetID"]); | ||
1782 | taskItem.ParentID = new UUID((Guid)inventoryRow["parentFolderID"]); | ||
1783 | |||
1784 | taskItem.InvType = Convert.ToInt32(inventoryRow["invType"]); | ||
1785 | taskItem.Type = Convert.ToInt32(inventoryRow["assetType"]); | ||
1786 | |||
1787 | taskItem.Name = (string)inventoryRow["name"]; | ||
1788 | taskItem.Description = (string)inventoryRow["description"]; | ||
1789 | taskItem.CreationDate = Convert.ToUInt32(inventoryRow["creationDate"]); | ||
1790 | //taskItem.creatorID = new UUID((Guid)inventoryRow["creatorID"]); | ||
1791 | taskItem.CreatorIdentification = (string)inventoryRow["creatorID"].ToString(); | ||
1792 | taskItem.OwnerID = new UUID((Guid)inventoryRow["ownerID"]); | ||
1793 | taskItem.LastOwnerID = new UUID((Guid)inventoryRow["lastOwnerID"]); | ||
1794 | taskItem.GroupID = new UUID((Guid)inventoryRow["groupID"]); | ||
1795 | |||
1796 | taskItem.NextPermissions = Convert.ToUInt32(inventoryRow["nextPermissions"]); | ||
1797 | taskItem.CurrentPermissions = Convert.ToUInt32(inventoryRow["currentPermissions"]); | ||
1798 | taskItem.BasePermissions = Convert.ToUInt32(inventoryRow["basePermissions"]); | ||
1799 | taskItem.EveryonePermissions = Convert.ToUInt32(inventoryRow["everyonePermissions"]); | ||
1800 | taskItem.GroupPermissions = Convert.ToUInt32(inventoryRow["groupPermissions"]); | ||
1801 | taskItem.Flags = Convert.ToUInt32(inventoryRow["flags"]); | ||
1802 | |||
1803 | return taskItem; | ||
1804 | } | ||
1805 | |||
1806 | #endregion | ||
1807 | |||
1808 | #region Create parameters methods | ||
1809 | |||
1810 | /// <summary> | ||
1811 | /// Creates the prim inventory parameters. | ||
1812 | /// </summary> | ||
1813 | /// <param name="taskItem">item in inventory.</param> | ||
1814 | /// <returns></returns> | ||
1815 | private NpgsqlParameter[] CreatePrimInventoryParameters(TaskInventoryItem taskItem) | ||
1816 | { | ||
1817 | List<NpgsqlParameter> parameters = new List<NpgsqlParameter>(); | ||
1818 | |||
1819 | parameters.Add(_Database.CreateParameter("itemID", taskItem.ItemID)); | ||
1820 | parameters.Add(_Database.CreateParameter("primID", taskItem.ParentPartID)); | ||
1821 | parameters.Add(_Database.CreateParameter("assetID", taskItem.AssetID)); | ||
1822 | parameters.Add(_Database.CreateParameter("parentFolderID", taskItem.ParentID)); | ||
1823 | parameters.Add(_Database.CreateParameter("invType", taskItem.InvType)); | ||
1824 | parameters.Add(_Database.CreateParameter("assetType", taskItem.Type)); | ||
1825 | |||
1826 | parameters.Add(_Database.CreateParameter("name", taskItem.Name)); | ||
1827 | parameters.Add(_Database.CreateParameter("description", taskItem.Description)); | ||
1828 | parameters.Add(_Database.CreateParameter("creationDate", taskItem.CreationDate)); | ||
1829 | parameters.Add(_Database.CreateParameter("creatorID", taskItem.CreatorID)); | ||
1830 | parameters.Add(_Database.CreateParameter("ownerID", taskItem.OwnerID)); | ||
1831 | parameters.Add(_Database.CreateParameter("lastOwnerID", taskItem.LastOwnerID)); | ||
1832 | parameters.Add(_Database.CreateParameter("groupID", taskItem.GroupID)); | ||
1833 | parameters.Add(_Database.CreateParameter("nextPermissions", taskItem.NextPermissions)); | ||
1834 | parameters.Add(_Database.CreateParameter("currentPermissions", taskItem.CurrentPermissions)); | ||
1835 | parameters.Add(_Database.CreateParameter("basePermissions", taskItem.BasePermissions)); | ||
1836 | parameters.Add(_Database.CreateParameter("everyonePermissions", taskItem.EveryonePermissions)); | ||
1837 | parameters.Add(_Database.CreateParameter("groupPermissions", taskItem.GroupPermissions)); | ||
1838 | parameters.Add(_Database.CreateParameter("flags", taskItem.Flags)); | ||
1839 | |||
1840 | return parameters.ToArray(); | ||
1841 | } | ||
1842 | |||
1843 | /// <summary> | ||
1844 | /// Creates the region setting parameters. | ||
1845 | /// </summary> | ||
1846 | /// <param name="settings">regionsettings.</param> | ||
1847 | /// <returns></returns> | ||
1848 | private NpgsqlParameter[] CreateRegionSettingParameters(RegionSettings settings) | ||
1849 | { | ||
1850 | List<NpgsqlParameter> parameters = new List<NpgsqlParameter>(); | ||
1851 | |||
1852 | parameters.Add(_Database.CreateParameter("regionUUID", settings.RegionUUID)); | ||
1853 | parameters.Add(_Database.CreateParameter("block_terraform", settings.BlockTerraform)); | ||
1854 | parameters.Add(_Database.CreateParameter("block_fly", settings.BlockFly)); | ||
1855 | parameters.Add(_Database.CreateParameter("allow_damage", settings.AllowDamage)); | ||
1856 | parameters.Add(_Database.CreateParameter("restrict_pushing", settings.RestrictPushing)); | ||
1857 | parameters.Add(_Database.CreateParameter("allow_land_resell", settings.AllowLandResell)); | ||
1858 | parameters.Add(_Database.CreateParameter("allow_land_join_divide", settings.AllowLandJoinDivide)); | ||
1859 | parameters.Add(_Database.CreateParameter("block_show_in_search", settings.BlockShowInSearch)); | ||
1860 | parameters.Add(_Database.CreateParameter("agent_limit", settings.AgentLimit)); | ||
1861 | parameters.Add(_Database.CreateParameter("object_bonus", settings.ObjectBonus)); | ||
1862 | parameters.Add(_Database.CreateParameter("maturity", settings.Maturity)); | ||
1863 | parameters.Add(_Database.CreateParameter("disable_scripts", settings.DisableScripts)); | ||
1864 | parameters.Add(_Database.CreateParameter("disable_collisions", settings.DisableCollisions)); | ||
1865 | parameters.Add(_Database.CreateParameter("disable_physics", settings.DisablePhysics)); | ||
1866 | parameters.Add(_Database.CreateParameter("terrain_texture_1", settings.TerrainTexture1)); | ||
1867 | parameters.Add(_Database.CreateParameter("terrain_texture_2", settings.TerrainTexture2)); | ||
1868 | parameters.Add(_Database.CreateParameter("terrain_texture_3", settings.TerrainTexture3)); | ||
1869 | parameters.Add(_Database.CreateParameter("terrain_texture_4", settings.TerrainTexture4)); | ||
1870 | parameters.Add(_Database.CreateParameter("elevation_1_nw", settings.Elevation1NW)); | ||
1871 | parameters.Add(_Database.CreateParameter("elevation_2_nw", settings.Elevation2NW)); | ||
1872 | parameters.Add(_Database.CreateParameter("elevation_1_ne", settings.Elevation1NE)); | ||
1873 | parameters.Add(_Database.CreateParameter("elevation_2_ne", settings.Elevation2NE)); | ||
1874 | parameters.Add(_Database.CreateParameter("elevation_1_se", settings.Elevation1SE)); | ||
1875 | parameters.Add(_Database.CreateParameter("elevation_2_se", settings.Elevation2SE)); | ||
1876 | parameters.Add(_Database.CreateParameter("elevation_1_sw", settings.Elevation1SW)); | ||
1877 | parameters.Add(_Database.CreateParameter("elevation_2_sw", settings.Elevation2SW)); | ||
1878 | parameters.Add(_Database.CreateParameter("water_height", settings.WaterHeight)); | ||
1879 | parameters.Add(_Database.CreateParameter("terrain_raise_limit", settings.TerrainRaiseLimit)); | ||
1880 | parameters.Add(_Database.CreateParameter("terrain_lower_limit", settings.TerrainLowerLimit)); | ||
1881 | parameters.Add(_Database.CreateParameter("use_estate_sun", settings.UseEstateSun)); | ||
1882 | parameters.Add(_Database.CreateParameter("Sandbox", settings.Sandbox)); | ||
1883 | parameters.Add(_Database.CreateParameter("fixed_sun", settings.FixedSun)); | ||
1884 | parameters.Add(_Database.CreateParameter("sun_position", settings.SunPosition)); | ||
1885 | parameters.Add(_Database.CreateParameter("sunvectorx", settings.SunVector.X)); | ||
1886 | parameters.Add(_Database.CreateParameter("sunvectory", settings.SunVector.Y)); | ||
1887 | parameters.Add(_Database.CreateParameter("sunvectorz", settings.SunVector.Z)); | ||
1888 | parameters.Add(_Database.CreateParameter("covenant", settings.Covenant)); | ||
1889 | parameters.Add(_Database.CreateParameter("covenant_datetime", settings.CovenantChangedDateTime)); | ||
1890 | parameters.Add(_Database.CreateParameter("Loaded_Creation_DateTime", settings.LoadedCreationDateTime)); | ||
1891 | parameters.Add(_Database.CreateParameter("Loaded_Creation_ID", settings.LoadedCreationID)); | ||
1892 | parameters.Add(_Database.CreateParameter("TerrainImageID", settings.TerrainImageID)); | ||
1893 | parameters.Add(_Database.CreateParameter("ParcelImageID", settings.ParcelImageID)); | ||
1894 | parameters.Add(_Database.CreateParameter("TelehubObject", settings.TelehubObject)); | ||
1895 | |||
1896 | return parameters.ToArray(); | ||
1897 | } | ||
1898 | |||
1899 | /// <summary> | ||
1900 | /// Creates the land parameters. | ||
1901 | /// </summary> | ||
1902 | /// <param name="land">land parameters.</param> | ||
1903 | /// <param name="regionUUID">region UUID.</param> | ||
1904 | /// <returns></returns> | ||
1905 | private NpgsqlParameter[] CreateLandParameters(LandData land, UUID regionUUID) | ||
1906 | { | ||
1907 | List<NpgsqlParameter> parameters = new List<NpgsqlParameter>(); | ||
1908 | |||
1909 | parameters.Add(_Database.CreateParameter("UUID", land.GlobalID)); | ||
1910 | parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID)); | ||
1911 | parameters.Add(_Database.CreateParameter("LocalLandID", land.LocalID)); | ||
1912 | |||
1913 | // Bitmap is a byte[512] | ||
1914 | parameters.Add(_Database.CreateParameter("Bitmap", land.Bitmap)); | ||
1915 | |||
1916 | parameters.Add(_Database.CreateParameter("Name", land.Name)); | ||
1917 | parameters.Add(_Database.CreateParameter("Description", land.Description)); | ||
1918 | parameters.Add(_Database.CreateParameter("OwnerUUID", land.OwnerID)); | ||
1919 | parameters.Add(_Database.CreateParameter("IsGroupOwned", land.IsGroupOwned)); | ||
1920 | parameters.Add(_Database.CreateParameter("Area", land.Area)); | ||
1921 | parameters.Add(_Database.CreateParameter("AuctionID", land.AuctionID)); //Unemplemented | ||
1922 | parameters.Add(_Database.CreateParameter("Category", (int)land.Category)); //Enum libsecondlife.Parcel.ParcelCategory | ||
1923 | parameters.Add(_Database.CreateParameter("ClaimDate", land.ClaimDate)); | ||
1924 | parameters.Add(_Database.CreateParameter("ClaimPrice", land.ClaimPrice)); | ||
1925 | parameters.Add(_Database.CreateParameter("GroupUUID", land.GroupID)); | ||
1926 | parameters.Add(_Database.CreateParameter("SalePrice", land.SalePrice)); | ||
1927 | parameters.Add(_Database.CreateParameter("LandStatus", (int)land.Status)); //Enum. libsecondlife.Parcel.ParcelStatus | ||
1928 | parameters.Add(_Database.CreateParameter("LandFlags", land.Flags)); | ||
1929 | parameters.Add(_Database.CreateParameter("LandingType", Convert.ToInt32( land.LandingType) )); | ||
1930 | parameters.Add(_Database.CreateParameter("MediaAutoScale", Convert.ToInt32( land.MediaAutoScale ))); | ||
1931 | parameters.Add(_Database.CreateParameter("MediaTextureUUID", land.MediaID)); | ||
1932 | parameters.Add(_Database.CreateParameter("MediaURL", land.MediaURL)); | ||
1933 | parameters.Add(_Database.CreateParameter("MusicURL", land.MusicURL)); | ||
1934 | parameters.Add(_Database.CreateParameter("PassHours", land.PassHours)); | ||
1935 | parameters.Add(_Database.CreateParameter("PassPrice", land.PassPrice)); | ||
1936 | parameters.Add(_Database.CreateParameter("SnapshotUUID", land.SnapshotID)); | ||
1937 | parameters.Add(_Database.CreateParameter("UserLocationX", land.UserLocation.X)); | ||
1938 | parameters.Add(_Database.CreateParameter("UserLocationY", land.UserLocation.Y)); | ||
1939 | parameters.Add(_Database.CreateParameter("UserLocationZ", land.UserLocation.Z)); | ||
1940 | parameters.Add(_Database.CreateParameter("UserLookAtX", land.UserLookAt.X)); | ||
1941 | parameters.Add(_Database.CreateParameter("UserLookAtY", land.UserLookAt.Y)); | ||
1942 | parameters.Add(_Database.CreateParameter("UserLookAtZ", land.UserLookAt.Z)); | ||
1943 | parameters.Add(_Database.CreateParameter("AuthBuyerID", land.AuthBuyerID)); | ||
1944 | parameters.Add(_Database.CreateParameter("OtherCleanTime", land.OtherCleanTime)); | ||
1945 | |||
1946 | return parameters.ToArray(); | ||
1947 | } | ||
1948 | |||
1949 | /// <summary> | ||
1950 | /// Creates the land access parameters. | ||
1951 | /// </summary> | ||
1952 | /// <param name="parcelAccessEntry">parcel access entry.</param> | ||
1953 | /// <param name="parcelID">parcel ID.</param> | ||
1954 | /// <returns></returns> | ||
1955 | private NpgsqlParameter[] CreateLandAccessParameters(LandAccessEntry parcelAccessEntry, UUID parcelID) | ||
1956 | { | ||
1957 | List<NpgsqlParameter> parameters = new List<NpgsqlParameter>(); | ||
1958 | |||
1959 | parameters.Add(_Database.CreateParameter("LandUUID", parcelID)); | ||
1960 | parameters.Add(_Database.CreateParameter("AccessUUID", parcelAccessEntry.AgentID)); | ||
1961 | parameters.Add(_Database.CreateParameter("Flags", parcelAccessEntry.Flags)); | ||
1962 | parameters.Add(_Database.CreateParameter("Expires", parcelAccessEntry.Expires)); | ||
1963 | |||
1964 | return parameters.ToArray(); | ||
1965 | } | ||
1966 | |||
1967 | /// <summary> | ||
1968 | /// Creates the prim parameters for storing in DB. | ||
1969 | /// </summary> | ||
1970 | /// <param name="prim">Basic data of SceneObjectpart prim.</param> | ||
1971 | /// <param name="sceneGroupID">The scenegroup ID.</param> | ||
1972 | /// <param name="regionUUID">The region ID.</param> | ||
1973 | /// <returns></returns> | ||
1974 | private NpgsqlParameter[] CreatePrimParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID) | ||
1975 | { | ||
1976 | List<NpgsqlParameter> parameters = new List<NpgsqlParameter>(); | ||
1977 | |||
1978 | parameters.Add(_Database.CreateParameter("UUID", prim.UUID)); | ||
1979 | parameters.Add(_Database.CreateParameter("RegionUUID", regionUUID)); | ||
1980 | parameters.Add(_Database.CreateParameter("CreationDate", prim.CreationDate)); | ||
1981 | parameters.Add(_Database.CreateParameter("Name", prim.Name)); | ||
1982 | parameters.Add(_Database.CreateParameter("SceneGroupID", sceneGroupID)); | ||
1983 | // the UUID of the root part for this SceneObjectGroup | ||
1984 | // various text fields | ||
1985 | parameters.Add(_Database.CreateParameter("Text", prim.Text)); | ||
1986 | parameters.Add(_Database.CreateParameter("ColorR", prim.Color.R)); | ||
1987 | parameters.Add(_Database.CreateParameter("ColorG", prim.Color.G)); | ||
1988 | parameters.Add(_Database.CreateParameter("ColorB", prim.Color.B)); | ||
1989 | parameters.Add(_Database.CreateParameter("ColorA", prim.Color.A)); | ||
1990 | parameters.Add(_Database.CreateParameter("Description", prim.Description)); | ||
1991 | parameters.Add(_Database.CreateParameter("SitName", prim.SitName)); | ||
1992 | parameters.Add(_Database.CreateParameter("TouchName", prim.TouchName)); | ||
1993 | // permissions | ||
1994 | parameters.Add(_Database.CreateParameter("ObjectFlags", (uint)prim.Flags)); | ||
1995 | parameters.Add(_Database.CreateParameter("CreatorID", prim.CreatorID)); | ||
1996 | parameters.Add(_Database.CreateParameter("OwnerID", prim.OwnerID)); | ||
1997 | parameters.Add(_Database.CreateParameter("GroupID", prim.GroupID)); | ||
1998 | parameters.Add(_Database.CreateParameter("LastOwnerID", prim.LastOwnerID)); | ||
1999 | parameters.Add(_Database.CreateParameter("OwnerMask", prim.OwnerMask)); | ||
2000 | parameters.Add(_Database.CreateParameter("NextOwnerMask", prim.NextOwnerMask)); | ||
2001 | parameters.Add(_Database.CreateParameter("GroupMask", prim.GroupMask)); | ||
2002 | parameters.Add(_Database.CreateParameter("EveryoneMask", prim.EveryoneMask)); | ||
2003 | parameters.Add(_Database.CreateParameter("BaseMask", prim.BaseMask)); | ||
2004 | // vectors | ||
2005 | parameters.Add(_Database.CreateParameter("PositionX", prim.OffsetPosition.X)); | ||
2006 | parameters.Add(_Database.CreateParameter("PositionY", prim.OffsetPosition.Y)); | ||
2007 | parameters.Add(_Database.CreateParameter("PositionZ", prim.OffsetPosition.Z)); | ||
2008 | parameters.Add(_Database.CreateParameter("GroupPositionX", prim.GroupPosition.X)); | ||
2009 | parameters.Add(_Database.CreateParameter("GroupPositionY", prim.GroupPosition.Y)); | ||
2010 | parameters.Add(_Database.CreateParameter("GroupPositionZ", prim.GroupPosition.Z)); | ||
2011 | parameters.Add(_Database.CreateParameter("VelocityX", prim.Velocity.X)); | ||
2012 | parameters.Add(_Database.CreateParameter("VelocityY", prim.Velocity.Y)); | ||
2013 | parameters.Add(_Database.CreateParameter("VelocityZ", prim.Velocity.Z)); | ||
2014 | parameters.Add(_Database.CreateParameter("AngularVelocityX", prim.AngularVelocity.X)); | ||
2015 | parameters.Add(_Database.CreateParameter("AngularVelocityY", prim.AngularVelocity.Y)); | ||
2016 | parameters.Add(_Database.CreateParameter("AngularVelocityZ", prim.AngularVelocity.Z)); | ||
2017 | parameters.Add(_Database.CreateParameter("AccelerationX", prim.Acceleration.X)); | ||
2018 | parameters.Add(_Database.CreateParameter("AccelerationY", prim.Acceleration.Y)); | ||
2019 | parameters.Add(_Database.CreateParameter("AccelerationZ", prim.Acceleration.Z)); | ||
2020 | // quaternions | ||
2021 | parameters.Add(_Database.CreateParameter("RotationX", prim.RotationOffset.X)); | ||
2022 | parameters.Add(_Database.CreateParameter("RotationY", prim.RotationOffset.Y)); | ||
2023 | parameters.Add(_Database.CreateParameter("RotationZ", prim.RotationOffset.Z)); | ||
2024 | parameters.Add(_Database.CreateParameter("RotationW", prim.RotationOffset.W)); | ||
2025 | |||
2026 | // Sit target | ||
2027 | Vector3 sitTargetPos = prim.SitTargetPositionLL; | ||
2028 | parameters.Add(_Database.CreateParameter("SitTargetOffsetX", sitTargetPos.X)); | ||
2029 | parameters.Add(_Database.CreateParameter("SitTargetOffsetY", sitTargetPos.Y)); | ||
2030 | parameters.Add(_Database.CreateParameter("SitTargetOffsetZ", sitTargetPos.Z)); | ||
2031 | |||
2032 | Quaternion sitTargetOrient = prim.SitTargetOrientationLL; | ||
2033 | parameters.Add(_Database.CreateParameter("SitTargetOrientW", sitTargetOrient.W)); | ||
2034 | parameters.Add(_Database.CreateParameter("SitTargetOrientX", sitTargetOrient.X)); | ||
2035 | parameters.Add(_Database.CreateParameter("SitTargetOrientY", sitTargetOrient.Y)); | ||
2036 | parameters.Add(_Database.CreateParameter("SitTargetOrientZ", sitTargetOrient.Z)); | ||
2037 | |||
2038 | parameters.Add(_Database.CreateParameter("PayPrice", prim.PayPrice[0])); | ||
2039 | parameters.Add(_Database.CreateParameter("PayButton1", prim.PayPrice[1])); | ||
2040 | parameters.Add(_Database.CreateParameter("PayButton2", prim.PayPrice[2])); | ||
2041 | parameters.Add(_Database.CreateParameter("PayButton3", prim.PayPrice[3])); | ||
2042 | parameters.Add(_Database.CreateParameter("PayButton4", prim.PayPrice[4])); | ||
2043 | |||
2044 | if ((prim.SoundFlags & 1) != 0) // Looped | ||
2045 | { | ||
2046 | parameters.Add(_Database.CreateParameter("LoopedSound", prim.Sound)); | ||
2047 | parameters.Add(_Database.CreateParameter("LoopedSoundGain", prim.SoundGain)); | ||
2048 | } | ||
2049 | else | ||
2050 | { | ||
2051 | parameters.Add(_Database.CreateParameter("LoopedSound", UUID.Zero)); | ||
2052 | parameters.Add(_Database.CreateParameter("LoopedSoundGain", 0.0f)); | ||
2053 | } | ||
2054 | |||
2055 | parameters.Add(_Database.CreateParameter("TextureAnimation", prim.TextureAnimation)); | ||
2056 | parameters.Add(_Database.CreateParameter("ParticleSystem", prim.ParticleSystem)); | ||
2057 | |||
2058 | parameters.Add(_Database.CreateParameter("OmegaX", prim.AngularVelocity.X)); | ||
2059 | parameters.Add(_Database.CreateParameter("OmegaY", prim.AngularVelocity.Y)); | ||
2060 | parameters.Add(_Database.CreateParameter("OmegaZ", prim.AngularVelocity.Z)); | ||
2061 | |||
2062 | parameters.Add(_Database.CreateParameter("CameraEyeOffsetX", prim.GetCameraEyeOffset().X)); | ||
2063 | parameters.Add(_Database.CreateParameter("CameraEyeOffsetY", prim.GetCameraEyeOffset().Y)); | ||
2064 | parameters.Add(_Database.CreateParameter("CameraEyeOffsetZ", prim.GetCameraEyeOffset().Z)); | ||
2065 | |||
2066 | parameters.Add(_Database.CreateParameter("CameraAtOffsetX", prim.GetCameraAtOffset().X)); | ||
2067 | parameters.Add(_Database.CreateParameter("CameraAtOffsetY", prim.GetCameraAtOffset().Y)); | ||
2068 | parameters.Add(_Database.CreateParameter("CameraAtOffsetZ", prim.GetCameraAtOffset().Z)); | ||
2069 | |||
2070 | if (prim.GetForceMouselook()) | ||
2071 | parameters.Add(_Database.CreateParameter("ForceMouselook", 1)); | ||
2072 | else | ||
2073 | parameters.Add(_Database.CreateParameter("ForceMouselook", 0)); | ||
2074 | |||
2075 | parameters.Add(_Database.CreateParameter("ScriptAccessPin", prim.ScriptAccessPin)); | ||
2076 | |||
2077 | if (prim.AllowedDrop) | ||
2078 | parameters.Add(_Database.CreateParameter("AllowedDrop", 1)); | ||
2079 | else | ||
2080 | parameters.Add(_Database.CreateParameter("AllowedDrop", 0)); | ||
2081 | |||
2082 | if (prim.DIE_AT_EDGE) | ||
2083 | parameters.Add(_Database.CreateParameter("DieAtEdge", 1)); | ||
2084 | else | ||
2085 | parameters.Add(_Database.CreateParameter("DieAtEdge", 0)); | ||
2086 | |||
2087 | parameters.Add(_Database.CreateParameter("SalePrice", prim.SalePrice)); | ||
2088 | parameters.Add(_Database.CreateParameter("SaleType", prim.ObjectSaleType)); | ||
2089 | |||
2090 | byte clickAction = prim.ClickAction; | ||
2091 | parameters.Add(_Database.CreateParameter("ClickAction", clickAction)); | ||
2092 | |||
2093 | parameters.Add(_Database.CreateParameter("Material", prim.Material)); | ||
2094 | |||
2095 | parameters.Add(_Database.CreateParameter("CollisionSound", prim.CollisionSound)); | ||
2096 | parameters.Add(_Database.CreateParameter("CollisionSoundVolume", prim.CollisionSoundVolume)); | ||
2097 | |||
2098 | parameters.Add(_Database.CreateParameter("PassTouches", prim.PassTouches)); | ||
2099 | |||
2100 | parameters.Add(_Database.CreateParameter("LinkNumber", prim.LinkNum)); | ||
2101 | parameters.Add(_Database.CreateParameter("MediaURL", prim.MediaUrl)); | ||
2102 | |||
2103 | if (prim.DynAttrs.CountNamespaces > 0) | ||
2104 | parameters.Add(_Database.CreateParameter("DynAttrs", prim.DynAttrs.ToXml())); | ||
2105 | else | ||
2106 | parameters.Add(_Database.CreateParameter("DynAttrs", null)); | ||
2107 | |||
2108 | parameters.Add(_Database.CreateParameter("PhysicsShapeType", prim.PhysicsShapeType)); | ||
2109 | parameters.Add(_Database.CreateParameter("Density", (double)prim.Density)); | ||
2110 | parameters.Add(_Database.CreateParameter("GravityModifier", (double)prim.GravityModifier)); | ||
2111 | parameters.Add(_Database.CreateParameter("Friction", (double)prim.Friction)); | ||
2112 | parameters.Add(_Database.CreateParameter("Restitution", (double)prim.Restitution)); | ||
2113 | |||
2114 | return parameters.ToArray(); | ||
2115 | } | ||
2116 | |||
2117 | /// <summary> | ||
2118 | /// Creates the primshape parameters for stroing in DB. | ||
2119 | /// </summary> | ||
2120 | /// <param name="prim">Basic data of SceneObjectpart prim.</param> | ||
2121 | /// <param name="sceneGroupID">The scene group ID.</param> | ||
2122 | /// <param name="regionUUID">The region UUID.</param> | ||
2123 | /// <returns></returns> | ||
2124 | private NpgsqlParameter[] CreatePrimShapeParameters(SceneObjectPart prim, UUID sceneGroupID, UUID regionUUID) | ||
2125 | { | ||
2126 | List<NpgsqlParameter> parameters = new List<NpgsqlParameter>(); | ||
2127 | |||
2128 | PrimitiveBaseShape s = prim.Shape; | ||
2129 | parameters.Add(_Database.CreateParameter("UUID", prim.UUID)); | ||
2130 | // shape is an enum | ||
2131 | parameters.Add(_Database.CreateParameter("Shape", 0)); | ||
2132 | // vectors | ||
2133 | parameters.Add(_Database.CreateParameter("ScaleX", s.Scale.X)); | ||
2134 | parameters.Add(_Database.CreateParameter("ScaleY", s.Scale.Y)); | ||
2135 | parameters.Add(_Database.CreateParameter("ScaleZ", s.Scale.Z)); | ||
2136 | // paths | ||
2137 | parameters.Add(_Database.CreateParameter("PCode", s.PCode)); | ||
2138 | parameters.Add(_Database.CreateParameter("PathBegin", s.PathBegin)); | ||
2139 | parameters.Add(_Database.CreateParameter("PathEnd", s.PathEnd)); | ||
2140 | parameters.Add(_Database.CreateParameter("PathScaleX", s.PathScaleX)); | ||
2141 | parameters.Add(_Database.CreateParameter("PathScaleY", s.PathScaleY)); | ||
2142 | parameters.Add(_Database.CreateParameter("PathShearX", s.PathShearX)); | ||
2143 | parameters.Add(_Database.CreateParameter("PathShearY", s.PathShearY)); | ||
2144 | parameters.Add(_Database.CreateParameter("PathSkew", s.PathSkew)); | ||
2145 | parameters.Add(_Database.CreateParameter("PathCurve", s.PathCurve)); | ||
2146 | parameters.Add(_Database.CreateParameter("PathRadiusOffset", s.PathRadiusOffset)); | ||
2147 | parameters.Add(_Database.CreateParameter("PathRevolutions", s.PathRevolutions)); | ||
2148 | parameters.Add(_Database.CreateParameter("PathTaperX", s.PathTaperX)); | ||
2149 | parameters.Add(_Database.CreateParameter("PathTaperY", s.PathTaperY)); | ||
2150 | parameters.Add(_Database.CreateParameter("PathTwist", s.PathTwist)); | ||
2151 | parameters.Add(_Database.CreateParameter("PathTwistBegin", s.PathTwistBegin)); | ||
2152 | // profile | ||
2153 | parameters.Add(_Database.CreateParameter("ProfileBegin", s.ProfileBegin)); | ||
2154 | parameters.Add(_Database.CreateParameter("ProfileEnd", s.ProfileEnd)); | ||
2155 | parameters.Add(_Database.CreateParameter("ProfileCurve", s.ProfileCurve)); | ||
2156 | parameters.Add(_Database.CreateParameter("ProfileHollow", s.ProfileHollow)); | ||
2157 | parameters.Add(_Database.CreateParameter("Texture", s.TextureEntry)); | ||
2158 | parameters.Add(_Database.CreateParameter("ExtraParams", s.ExtraParams)); | ||
2159 | parameters.Add(_Database.CreateParameter("State", s.State)); | ||
2160 | |||
2161 | if (null == s.Media) | ||
2162 | { | ||
2163 | parameters.Add(_Database.CreateParameter("Media", DBNull.Value)); | ||
2164 | } | ||
2165 | else | ||
2166 | { | ||
2167 | parameters.Add(_Database.CreateParameter("Media", s.Media.ToXml())); | ||
2168 | } | ||
2169 | |||
2170 | return parameters.ToArray(); | ||
2171 | } | ||
2172 | |||
2173 | #endregion | ||
2174 | |||
2175 | #endregion | ||
2176 | |||
2177 | private void LoadSpawnPoints(RegionSettings rs) | ||
2178 | { | ||
2179 | rs.ClearSpawnPoints(); | ||
2180 | |||
2181 | string sql = @"SELECT ""Yaw"", ""Pitch"", ""Distance"" FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID"; | ||
2182 | |||
2183 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
2184 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
2185 | { | ||
2186 | cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID)); | ||
2187 | conn.Open(); | ||
2188 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
2189 | { | ||
2190 | if (reader.Read()) | ||
2191 | { | ||
2192 | SpawnPoint sp = new SpawnPoint(); | ||
2193 | |||
2194 | sp.Yaw = (float)reader["Yaw"]; | ||
2195 | sp.Pitch = (float)reader["Pitch"]; | ||
2196 | sp.Distance = (float)reader["Distance"]; | ||
2197 | |||
2198 | rs.AddSpawnPoint(sp); | ||
2199 | } | ||
2200 | } | ||
2201 | } | ||
2202 | } | ||
2203 | |||
2204 | private void SaveSpawnPoints(RegionSettings rs) | ||
2205 | { | ||
2206 | string sql = @"DELETE FROM spawn_points WHERE ""RegionUUID"" = :RegionUUID"; | ||
2207 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
2208 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
2209 | { | ||
2210 | cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID)); | ||
2211 | conn.Open(); | ||
2212 | cmd.ExecuteNonQuery(); | ||
2213 | } | ||
2214 | foreach (SpawnPoint p in rs.SpawnPoints()) | ||
2215 | { | ||
2216 | sql = @"INSERT INTO spawn_points (""RegionUUID"", ""Yaw"", ""Pitch"", ""Distance"") VALUES (:RegionUUID, :Yaw, :Pitch, :Distance)"; | ||
2217 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
2218 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
2219 | { | ||
2220 | cmd.Parameters.Add(_Database.CreateParameter("RegionUUID", rs.RegionUUID)); | ||
2221 | cmd.Parameters.Add(_Database.CreateParameter("Yaw", p.Yaw)); | ||
2222 | cmd.Parameters.Add(_Database.CreateParameter("Pitch", p.Pitch)); | ||
2223 | cmd.Parameters.Add(_Database.CreateParameter("Distance", p.Distance)); | ||
2224 | conn.Open(); | ||
2225 | cmd.ExecuteNonQuery(); | ||
2226 | } | ||
2227 | } | ||
2228 | } | ||
2229 | |||
2230 | public void SaveExtra(UUID regionID, string name, string value) | ||
2231 | { | ||
2232 | } | ||
2233 | |||
2234 | public void RemoveExtra(UUID regionID, string name) | ||
2235 | { | ||
2236 | } | ||
2237 | |||
2238 | public Dictionary<string, string> GetExtra(UUID regionID) | ||
2239 | { | ||
2240 | return null; | ||
2241 | } | ||
2242 | } | ||
2243 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs new file mode 100644 index 0000000..0a68b23 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLUserAccountData.cs | |||
@@ -0,0 +1,329 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ''AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using System.Text; | ||
35 | using Npgsql; | ||
36 | using log4net; | ||
37 | using System.Reflection; | ||
38 | |||
39 | namespace OpenSim.Data.PGSQL | ||
40 | { | ||
41 | public class PGSQLUserAccountData : PGSQLGenericTableHandler<UserAccountData>,IUserAccountData | ||
42 | { | ||
43 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
44 | |||
45 | |||
46 | public PGSQLUserAccountData(string connectionString, string realm) : | ||
47 | base(connectionString, realm, "UserAccount") | ||
48 | { | ||
49 | } | ||
50 | |||
51 | /* | ||
52 | private string m_Realm; | ||
53 | private List<string> m_ColumnNames = null; | ||
54 | private PGSQLManager m_database; | ||
55 | |||
56 | public PGSQLUserAccountData(string connectionString, string realm) : | ||
57 | base(connectionString, realm, "UserAccount") | ||
58 | { | ||
59 | m_Realm = realm; | ||
60 | m_ConnectionString = connectionString; | ||
61 | m_database = new PGSQLManager(connectionString); | ||
62 | |||
63 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
64 | { | ||
65 | conn.Open(); | ||
66 | Migration m = new Migration(conn, GetType().Assembly, "UserAccount"); | ||
67 | m.Update(); | ||
68 | } | ||
69 | } | ||
70 | */ | ||
71 | /* | ||
72 | public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query) | ||
73 | { | ||
74 | return null; | ||
75 | } | ||
76 | */ | ||
77 | /* | ||
78 | public override UserAccountData[] Get(string[] fields, string[] keys) | ||
79 | { | ||
80 | UserAccountData[] retUA = base.Get(fields,keys); | ||
81 | |||
82 | if (retUA.Length > 0) | ||
83 | { | ||
84 | Dictionary<string, string> data = retUA[0].Data; | ||
85 | Dictionary<string, string> data2 = new Dictionary<string, string>(); | ||
86 | |||
87 | foreach (KeyValuePair<string,string> chave in data) | ||
88 | { | ||
89 | string s2 = chave.Key; | ||
90 | |||
91 | data2[s2] = chave.Value; | ||
92 | |||
93 | if (!m_FieldTypes.ContainsKey(chave.Key)) | ||
94 | { | ||
95 | string tipo = ""; | ||
96 | m_FieldTypes.TryGetValue(chave.Key, out tipo); | ||
97 | m_FieldTypes.Add(s2, tipo); | ||
98 | } | ||
99 | } | ||
100 | foreach (KeyValuePair<string, string> chave in data2) | ||
101 | { | ||
102 | if (!retUA[0].Data.ContainsKey(chave.Key)) | ||
103 | retUA[0].Data.Add(chave.Key, chave.Value); | ||
104 | } | ||
105 | } | ||
106 | |||
107 | return retUA; | ||
108 | } | ||
109 | */ | ||
110 | /* | ||
111 | public UserAccountData Get(UUID principalID, UUID scopeID) | ||
112 | { | ||
113 | UserAccountData ret = new UserAccountData(); | ||
114 | ret.Data = new Dictionary<string, string>(); | ||
115 | |||
116 | string sql = string.Format(@"select * from {0} where ""PrincipalID"" = :principalID", m_Realm); | ||
117 | if (scopeID != UUID.Zero) | ||
118 | sql += @" and ""ScopeID"" = :scopeID"; | ||
119 | |||
120 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
121 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
122 | { | ||
123 | cmd.Parameters.Add(m_database.CreateParameter("principalID", principalID)); | ||
124 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", scopeID)); | ||
125 | |||
126 | conn.Open(); | ||
127 | using (NpgsqlDataReader result = cmd.ExecuteReader()) | ||
128 | { | ||
129 | if (result.Read()) | ||
130 | { | ||
131 | ret.PrincipalID = principalID; | ||
132 | UUID scope; | ||
133 | UUID.TryParse(result["scopeid"].ToString(), out scope); | ||
134 | ret.ScopeID = scope; | ||
135 | |||
136 | if (m_ColumnNames == null) | ||
137 | { | ||
138 | m_ColumnNames = new List<string>(); | ||
139 | |||
140 | DataTable schemaTable = result.GetSchemaTable(); | ||
141 | foreach (DataRow row in schemaTable.Rows) | ||
142 | m_ColumnNames.Add(row["ColumnName"].ToString()); | ||
143 | } | ||
144 | |||
145 | foreach (string s in m_ColumnNames) | ||
146 | { | ||
147 | string s2 = s; | ||
148 | if (s2 == "uuid") | ||
149 | continue; | ||
150 | if (s2 == "scopeid") | ||
151 | continue; | ||
152 | |||
153 | ret.Data[s] = result[s].ToString(); | ||
154 | } | ||
155 | return ret; | ||
156 | } | ||
157 | } | ||
158 | } | ||
159 | return null; | ||
160 | } | ||
161 | |||
162 | |||
163 | public override bool Store(UserAccountData data) | ||
164 | { | ||
165 | if (data.Data.ContainsKey("PrincipalID")) | ||
166 | data.Data.Remove("PrincipalID"); | ||
167 | if (data.Data.ContainsKey("ScopeID")) | ||
168 | data.Data.Remove("ScopeID"); | ||
169 | |||
170 | string[] fields = new List<string>(data.Data.Keys).ToArray(); | ||
171 | |||
172 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
173 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
174 | { | ||
175 | m_log.DebugFormat("[USER]: Try to update user {0} {1}", data.FirstName, data.LastName); | ||
176 | |||
177 | StringBuilder updateBuilder = new StringBuilder(); | ||
178 | updateBuilder.AppendFormat("update {0} set ", m_Realm); | ||
179 | bool first = true; | ||
180 | foreach (string field in fields) | ||
181 | { | ||
182 | if (!first) | ||
183 | updateBuilder.Append(", "); | ||
184 | updateBuilder.AppendFormat("\"{0}\" = :{0}", field); | ||
185 | |||
186 | first = false; | ||
187 | if (m_FieldTypes.ContainsKey(field)) | ||
188 | cmd.Parameters.Add(m_database.CreateParameter("" + field, data.Data[field], m_FieldTypes[field])); | ||
189 | else | ||
190 | cmd.Parameters.Add(m_database.CreateParameter("" + field, data.Data[field])); | ||
191 | } | ||
192 | |||
193 | updateBuilder.Append(" where \"PrincipalID\" = :principalID"); | ||
194 | |||
195 | if (data.ScopeID != UUID.Zero) | ||
196 | updateBuilder.Append(" and \"ScopeID\" = :scopeID"); | ||
197 | |||
198 | cmd.CommandText = updateBuilder.ToString(); | ||
199 | cmd.Connection = conn; | ||
200 | cmd.Parameters.Add(m_database.CreateParameter("principalID", data.PrincipalID)); | ||
201 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", data.ScopeID)); | ||
202 | |||
203 | m_log.DebugFormat("[USER]: SQL update user {0} ", cmd.CommandText); | ||
204 | |||
205 | conn.Open(); | ||
206 | |||
207 | m_log.DebugFormat("[USER]: CON opened update user {0} ", cmd.CommandText); | ||
208 | |||
209 | int conta = 0; | ||
210 | try | ||
211 | { | ||
212 | conta = cmd.ExecuteNonQuery(); | ||
213 | } | ||
214 | catch (Exception e){ | ||
215 | m_log.ErrorFormat("[USER]: ERROR opened update user {0} ", e.Message); | ||
216 | } | ||
217 | |||
218 | |||
219 | if (conta < 1) | ||
220 | { | ||
221 | m_log.DebugFormat("[USER]: Try to insert user {0} {1}", data.FirstName, data.LastName); | ||
222 | |||
223 | StringBuilder insertBuilder = new StringBuilder(); | ||
224 | insertBuilder.AppendFormat(@"insert into {0} (""PrincipalID"", ""ScopeID"", ""FirstName"", ""LastName"", """, m_Realm); | ||
225 | insertBuilder.Append(String.Join(@""", """, fields)); | ||
226 | insertBuilder.Append(@""") values (:principalID, :scopeID, :FirstName, :LastName, :"); | ||
227 | insertBuilder.Append(String.Join(", :", fields)); | ||
228 | insertBuilder.Append(");"); | ||
229 | |||
230 | cmd.Parameters.Add(m_database.CreateParameter("FirstName", data.FirstName)); | ||
231 | cmd.Parameters.Add(m_database.CreateParameter("LastName", data.LastName)); | ||
232 | |||
233 | cmd.CommandText = insertBuilder.ToString(); | ||
234 | |||
235 | if (cmd.ExecuteNonQuery() < 1) | ||
236 | { | ||
237 | return false; | ||
238 | } | ||
239 | } | ||
240 | else | ||
241 | m_log.DebugFormat("[USER]: User {0} {1} exists", data.FirstName, data.LastName); | ||
242 | } | ||
243 | return true; | ||
244 | } | ||
245 | |||
246 | |||
247 | public bool Store(UserAccountData data, UUID principalID, string token) | ||
248 | { | ||
249 | return false; | ||
250 | } | ||
251 | |||
252 | |||
253 | public bool SetDataItem(UUID principalID, string item, string value) | ||
254 | { | ||
255 | string sql = string.Format(@"update {0} set {1} = :{1} where ""UUID"" = :UUID", m_Realm, item); | ||
256 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
257 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
258 | { | ||
259 | if (m_FieldTypes.ContainsKey(item)) | ||
260 | cmd.Parameters.Add(m_database.CreateParameter("" + item, value, m_FieldTypes[item])); | ||
261 | else | ||
262 | cmd.Parameters.Add(m_database.CreateParameter("" + item, value)); | ||
263 | |||
264 | cmd.Parameters.Add(m_database.CreateParameter("UUID", principalID)); | ||
265 | conn.Open(); | ||
266 | |||
267 | if (cmd.ExecuteNonQuery() > 0) | ||
268 | return true; | ||
269 | } | ||
270 | return false; | ||
271 | } | ||
272 | */ | ||
273 | /* | ||
274 | public UserAccountData[] Get(string[] keys, string[] vals) | ||
275 | { | ||
276 | return null; | ||
277 | } | ||
278 | */ | ||
279 | |||
280 | public UserAccountData[] GetUsers(UUID scopeID, string query) | ||
281 | { | ||
282 | string[] words = query.Split(new char[] { ' ' }); | ||
283 | |||
284 | for (int i = 0; i < words.Length; i++) | ||
285 | { | ||
286 | if (words[i].Length < 3) | ||
287 | { | ||
288 | if (i != words.Length - 1) | ||
289 | Array.Copy(words, i + 1, words, i, words.Length - i - 1); | ||
290 | Array.Resize(ref words, words.Length - 1); | ||
291 | } | ||
292 | } | ||
293 | |||
294 | if (words.Length == 0) | ||
295 | return new UserAccountData[0]; | ||
296 | |||
297 | if (words.Length > 2) | ||
298 | return new UserAccountData[0]; | ||
299 | |||
300 | string sql = ""; | ||
301 | UUID scope_id; | ||
302 | UUID.TryParse(scopeID.ToString(), out scope_id); | ||
303 | |||
304 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
305 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
306 | { | ||
307 | if (words.Length == 1) | ||
308 | { | ||
309 | sql = String.Format(@"select * from {0} where (""ScopeID""=:ScopeID or ""ScopeID""=:UUIDZero) and (""FirstName"" ilike :search or ""LastName"" ilike :search)", m_Realm); | ||
310 | cmd.Parameters.Add(m_database.CreateParameter("scopeID", (UUID)scope_id)); | ||
311 | cmd.Parameters.Add (m_database.CreateParameter("UUIDZero", (UUID)UUID.Zero)); | ||
312 | cmd.Parameters.Add(m_database.CreateParameter("search", "%" + words[0] + "%")); | ||
313 | } | ||
314 | else | ||
315 | { | ||
316 | sql = String.Format(@"select * from {0} where (""ScopeID""=:ScopeID or ""ScopeID""=:UUIDZero) and (""FirstName"" ilike :searchFirst or ""LastName"" ilike :searchLast)", m_Realm); | ||
317 | cmd.Parameters.Add(m_database.CreateParameter("searchFirst", "%" + words[0] + "%")); | ||
318 | cmd.Parameters.Add(m_database.CreateParameter("searchLast", "%" + words[1] + "%")); | ||
319 | cmd.Parameters.Add (m_database.CreateParameter("UUIDZero", (UUID)UUID.Zero)); | ||
320 | cmd.Parameters.Add(m_database.CreateParameter("ScopeID", (UUID)scope_id)); | ||
321 | } | ||
322 | cmd.Connection = conn; | ||
323 | cmd.CommandText = sql; | ||
324 | conn.Open(); | ||
325 | return DoQuery(cmd); | ||
326 | } | ||
327 | } | ||
328 | } | ||
329 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLUserProfilesData.cs b/OpenSim/Data/PGSQL/PGSQLUserProfilesData.cs new file mode 100644 index 0000000..f166976 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLUserProfilesData.cs | |||
@@ -0,0 +1,1064 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Data; | ||
30 | using System.Reflection; | ||
31 | using OpenSim.Data; | ||
32 | using OpenSim.Framework; | ||
33 | using OpenMetaverse; | ||
34 | using OpenMetaverse.StructuredData; | ||
35 | using log4net; | ||
36 | using Npgsql; | ||
37 | |||
38 | namespace OpenSim.Data.PGSQL | ||
39 | { | ||
40 | public class UserProfilesData : IProfilesData | ||
41 | { | ||
42 | static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
43 | |||
44 | protected PGSQLManager m_database; | ||
45 | |||
46 | #region Properites | ||
47 | string ConnectionString | ||
48 | { | ||
49 | get; | ||
50 | set; | ||
51 | } | ||
52 | |||
53 | protected virtual Assembly Assembly | ||
54 | { | ||
55 | get { return GetType().Assembly; } | ||
56 | } | ||
57 | |||
58 | #endregion Properties | ||
59 | |||
60 | #region class Member Functions | ||
61 | public UserProfilesData(string connectionString) | ||
62 | { | ||
63 | ConnectionString = connectionString; | ||
64 | Init(); | ||
65 | } | ||
66 | |||
67 | void Init() | ||
68 | { | ||
69 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
70 | { | ||
71 | dbcon.Open(); | ||
72 | |||
73 | Migration m = new Migration(dbcon, Assembly, "UserProfiles"); | ||
74 | m.Update(); | ||
75 | m_database = new PGSQLManager(ConnectionString); | ||
76 | } | ||
77 | } | ||
78 | #endregion Member Functions | ||
79 | |||
80 | #region Classifieds Queries | ||
81 | /// <summary> | ||
82 | /// Gets the classified records. | ||
83 | /// </summary> | ||
84 | /// <returns> | ||
85 | /// Array of classified records | ||
86 | /// </returns> | ||
87 | /// <param name='creatorId'> | ||
88 | /// Creator identifier. | ||
89 | /// </param> | ||
90 | public OSDArray GetClassifiedRecords(UUID creatorId) | ||
91 | { | ||
92 | OSDArray data = new OSDArray(); | ||
93 | |||
94 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
95 | { | ||
96 | string query = @"SELECT classifieduuid, name FROM classifieds WHERE creatoruuid = :Id"; | ||
97 | dbcon.Open(); | ||
98 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
99 | { | ||
100 | cmd.Parameters.Add(m_database.CreateParameter("Id", creatorId)); | ||
101 | using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.Default)) | ||
102 | { | ||
103 | if (reader.HasRows) | ||
104 | { | ||
105 | while (reader.Read()) | ||
106 | { | ||
107 | OSDMap n = new OSDMap(); | ||
108 | UUID Id = UUID.Zero; | ||
109 | |||
110 | string Name = null; | ||
111 | try | ||
112 | { | ||
113 | Id = DBGuid.FromDB(reader["classifieduuid"]); | ||
114 | Name = Convert.ToString(reader["name"]); | ||
115 | } | ||
116 | catch (Exception e) | ||
117 | { | ||
118 | m_log.Error("[PROFILES_DATA]: UserAccount exception ", e); | ||
119 | } | ||
120 | |||
121 | n.Add("classifieduuid", OSD.FromUUID(Id)); | ||
122 | n.Add("name", OSD.FromString(Name)); | ||
123 | data.Add(n); | ||
124 | } | ||
125 | } | ||
126 | } | ||
127 | } | ||
128 | } | ||
129 | return data; | ||
130 | } | ||
131 | |||
132 | public bool UpdateClassifiedRecord(UserClassifiedAdd ad, ref string result) | ||
133 | { | ||
134 | string query = string.Empty; | ||
135 | |||
136 | query = @"WITH upsert AS ( | ||
137 | UPDATE classifieds SET | ||
138 | classifieduuid = :ClassifiedId, creatoruuid = :CreatorId, creationdate = :CreatedDate, | ||
139 | expirationdate = :ExpirationDate,category =:Category, name = :Name, description = :Description, | ||
140 | parceluuid = :ParcelId, parentestate = :ParentEstate, snapshotuuid = :SnapshotId, | ||
141 | simname = :SimName, posglobal = :GlobalPos, parcelname = :ParcelName, classifiedflags = :Flags, | ||
142 | priceforlisting = :ListingPrice | ||
143 | RETURNING * ) | ||
144 | INSERT INTO classifieds (classifieduuid,creatoruuid,creationdate,expirationdate,category,name, | ||
145 | description,parceluuid,parentestate,snapshotuuid,simname,posglobal,parcelname,classifiedflags, | ||
146 | priceforlisting) | ||
147 | SELECT | ||
148 | :ClassifiedId,:CreatorId,:CreatedDate,:ExpirationDate,:Category,:Name,:Description, | ||
149 | :ParcelId,:ParentEstate,:SnapshotId,:SimName,:GlobalPos,:ParcelName,:Flags,:ListingPrice | ||
150 | WHERE NOT EXISTS ( | ||
151 | SELECT * FROM upsert )"; | ||
152 | |||
153 | if (string.IsNullOrEmpty(ad.ParcelName)) | ||
154 | ad.ParcelName = "Unknown"; | ||
155 | if (ad.ParcelId == null) | ||
156 | ad.ParcelId = UUID.Zero; | ||
157 | if (string.IsNullOrEmpty(ad.Description)) | ||
158 | ad.Description = "No Description"; | ||
159 | |||
160 | DateTime epoch = new DateTime(1970, 1, 1); | ||
161 | DateTime now = DateTime.Now; | ||
162 | TimeSpan epochnow = now - epoch; | ||
163 | TimeSpan duration; | ||
164 | DateTime expiration; | ||
165 | TimeSpan epochexp; | ||
166 | |||
167 | if (ad.Flags == 2) | ||
168 | { | ||
169 | duration = new TimeSpan(7, 0, 0, 0); | ||
170 | expiration = now.Add(duration); | ||
171 | epochexp = expiration - epoch; | ||
172 | } | ||
173 | else | ||
174 | { | ||
175 | duration = new TimeSpan(365, 0, 0, 0); | ||
176 | expiration = now.Add(duration); | ||
177 | epochexp = expiration - epoch; | ||
178 | } | ||
179 | ad.CreationDate = (int)epochnow.TotalSeconds; | ||
180 | ad.ExpirationDate = (int)epochexp.TotalSeconds; | ||
181 | |||
182 | try | ||
183 | { | ||
184 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
185 | { | ||
186 | dbcon.Open(); | ||
187 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
188 | { | ||
189 | cmd.Parameters.Add(m_database.CreateParameter("ClassifiedId", ad.ClassifiedId)); | ||
190 | cmd.Parameters.Add(m_database.CreateParameter("CreatorId", ad.CreatorId)); | ||
191 | cmd.Parameters.Add(m_database.CreateParameter("CreatedDate", (int)ad.CreationDate)); | ||
192 | cmd.Parameters.Add(m_database.CreateParameter("ExpirationDate", (int)ad.ExpirationDate)); | ||
193 | cmd.Parameters.Add(m_database.CreateParameter("Category", ad.Category.ToString())); | ||
194 | cmd.Parameters.Add(m_database.CreateParameter("Name", ad.Name.ToString())); | ||
195 | cmd.Parameters.Add(m_database.CreateParameter("Description", ad.Description.ToString())); | ||
196 | cmd.Parameters.Add(m_database.CreateParameter("ParcelId", ad.ParcelId)); | ||
197 | cmd.Parameters.Add(m_database.CreateParameter("ParentEstate", (int)ad.ParentEstate)); | ||
198 | cmd.Parameters.Add(m_database.CreateParameter("SnapshotId", ad.SnapshotId)); | ||
199 | cmd.Parameters.Add(m_database.CreateParameter("SimName", ad.SimName.ToString())); | ||
200 | cmd.Parameters.Add(m_database.CreateParameter("GlobalPos", ad.GlobalPos.ToString())); | ||
201 | cmd.Parameters.Add(m_database.CreateParameter("ParcelName", ad.ParcelName.ToString())); | ||
202 | cmd.Parameters.Add(m_database.CreateParameter("Flags", (int)Convert.ToInt32(ad.Flags))); | ||
203 | cmd.Parameters.Add(m_database.CreateParameter("ListingPrice", (int)Convert.ToInt32(ad.Price))); | ||
204 | |||
205 | cmd.ExecuteNonQuery(); | ||
206 | } | ||
207 | } | ||
208 | } | ||
209 | catch (Exception e) | ||
210 | { | ||
211 | m_log.Error("[PROFILES_DATA]: ClassifiedsUpdate exception ", e); | ||
212 | result = e.Message; | ||
213 | return false; | ||
214 | } | ||
215 | |||
216 | return true; | ||
217 | } | ||
218 | |||
219 | public bool DeleteClassifiedRecord(UUID recordId) | ||
220 | { | ||
221 | string query = string.Empty; | ||
222 | |||
223 | query = @"DELETE FROM classifieds WHERE classifieduuid = :ClassifiedId ;"; | ||
224 | |||
225 | try | ||
226 | { | ||
227 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
228 | { | ||
229 | dbcon.Open(); | ||
230 | |||
231 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
232 | { | ||
233 | cmd.Parameters.Add(m_database.CreateParameter("ClassifiedId", recordId)); | ||
234 | cmd.ExecuteNonQuery(); | ||
235 | } | ||
236 | } | ||
237 | } | ||
238 | catch (Exception e) | ||
239 | { | ||
240 | m_log.Error("[PROFILES_DATA]: DeleteClassifiedRecord exception ", e); | ||
241 | return false; | ||
242 | } | ||
243 | |||
244 | return true; | ||
245 | } | ||
246 | |||
247 | public bool GetClassifiedInfo(ref UserClassifiedAdd ad, ref string result) | ||
248 | { | ||
249 | string query = string.Empty; | ||
250 | |||
251 | query += "SELECT * FROM classifieds WHERE "; | ||
252 | query += "classifieduuid = :AdId"; | ||
253 | |||
254 | try | ||
255 | { | ||
256 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
257 | { | ||
258 | dbcon.Open(); | ||
259 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
260 | { | ||
261 | cmd.Parameters.Add(m_database.CreateParameter("AdId", ad.ClassifiedId)); | ||
262 | |||
263 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
264 | { | ||
265 | if (reader.Read()) | ||
266 | { | ||
267 | ad.CreatorId = DBGuid.FromDB(reader["creatoruuid"]); | ||
268 | ad.ParcelId = DBGuid.FromDB(reader["parceluuid"]); | ||
269 | ad.SnapshotId = DBGuid.FromDB(reader["snapshotuuid"]); | ||
270 | ad.CreationDate = Convert.ToInt32(reader["creationdate"]); | ||
271 | ad.ExpirationDate = Convert.ToInt32(reader["expirationdate"]); | ||
272 | ad.ParentEstate = Convert.ToInt32(reader["parentestate"]); | ||
273 | ad.Flags = (byte)Convert.ToInt16(reader["classifiedflags"]); | ||
274 | ad.Category = Convert.ToInt32(reader["category"]); | ||
275 | ad.Price = Convert.ToInt16(reader["priceforlisting"]); | ||
276 | ad.Name = reader["name"].ToString(); | ||
277 | ad.Description = reader["description"].ToString(); | ||
278 | ad.SimName = reader["simname"].ToString(); | ||
279 | ad.GlobalPos = reader["posglobal"].ToString(); | ||
280 | ad.ParcelName = reader["parcelname"].ToString(); | ||
281 | } | ||
282 | } | ||
283 | } | ||
284 | dbcon.Close(); | ||
285 | } | ||
286 | } | ||
287 | catch (Exception e) | ||
288 | { | ||
289 | m_log.Error("[PROFILES_DATA]: GetClassifiedInfo exception ", e); | ||
290 | } | ||
291 | |||
292 | return true; | ||
293 | } | ||
294 | |||
295 | public static UUID GetUUID(object uuidValue) | ||
296 | { | ||
297 | |||
298 | UUID ret = UUID.Zero; | ||
299 | |||
300 | UUID.TryParse(uuidValue.ToString(), out ret); | ||
301 | |||
302 | return ret; | ||
303 | } | ||
304 | |||
305 | #endregion Classifieds Queries | ||
306 | |||
307 | #region Picks Queries | ||
308 | public OSDArray GetAvatarPicks(UUID avatarId) | ||
309 | { | ||
310 | string query = string.Empty; | ||
311 | |||
312 | query += "SELECT pickuuid, name FROM userpicks WHERE "; | ||
313 | query += "creatoruuid = :Id"; | ||
314 | OSDArray data = new OSDArray(); | ||
315 | |||
316 | try | ||
317 | { | ||
318 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
319 | { | ||
320 | dbcon.Open(); | ||
321 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
322 | { | ||
323 | cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId)); | ||
324 | |||
325 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
326 | { | ||
327 | if (reader.HasRows) | ||
328 | { | ||
329 | while (reader.Read()) | ||
330 | { | ||
331 | OSDMap record = new OSDMap(); | ||
332 | |||
333 | record.Add("pickuuid", OSD.FromUUID(DBGuid.FromDB(reader["pickuuid"]))); | ||
334 | record.Add("name", OSD.FromString((string)reader["name"])); | ||
335 | data.Add(record); | ||
336 | } | ||
337 | } | ||
338 | } | ||
339 | } | ||
340 | } | ||
341 | } | ||
342 | catch (Exception e) | ||
343 | { | ||
344 | m_log.Error("[PROFILES_DATA]: GetAvatarPicks exception ", e); | ||
345 | } | ||
346 | |||
347 | return data; | ||
348 | } | ||
349 | |||
350 | public UserProfilePick GetPickInfo(UUID avatarId, UUID pickId) | ||
351 | { | ||
352 | string query = string.Empty; | ||
353 | UserProfilePick pick = new UserProfilePick(); | ||
354 | |||
355 | query += "SELECT * FROM userpicks WHERE "; | ||
356 | query += "creatoruuid = :CreatorId AND "; | ||
357 | query += "pickuuid = :PickId"; | ||
358 | |||
359 | try | ||
360 | { | ||
361 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
362 | { | ||
363 | dbcon.Open(); | ||
364 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
365 | { | ||
366 | cmd.Parameters.Add(m_database.CreateParameter("CreatorId", avatarId)); | ||
367 | cmd.Parameters.Add(m_database.CreateParameter("PickId", pickId)); | ||
368 | |||
369 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
370 | { | ||
371 | if (reader.HasRows) | ||
372 | { | ||
373 | reader.Read(); | ||
374 | |||
375 | string description = (string)reader["description"]; | ||
376 | |||
377 | if (string.IsNullOrEmpty(description)) | ||
378 | description = "No description given."; | ||
379 | |||
380 | pick.PickId = DBGuid.FromDB(reader["pickuuid"]); | ||
381 | pick.CreatorId = DBGuid.FromDB(reader["creatoruuid"]); | ||
382 | pick.ParcelId = DBGuid.FromDB(reader["parceluuid"]); | ||
383 | pick.SnapshotId = DBGuid.FromDB(reader["snapshotuuid"]); | ||
384 | pick.GlobalPos = (string)reader["posglobal"].ToString(); | ||
385 | pick.TopPick = Convert.ToBoolean(reader["toppick"]); | ||
386 | pick.Enabled = Convert.ToBoolean(reader["enabled"]); | ||
387 | pick.Name = reader["name"].ToString(); | ||
388 | pick.Desc = reader["description"].ToString(); | ||
389 | pick.ParcelName = reader["user"].ToString(); | ||
390 | pick.OriginalName = reader["originalname"].ToString(); | ||
391 | pick.SimName = reader["simname"].ToString(); | ||
392 | pick.SortOrder = (int)reader["sortorder"]; | ||
393 | } | ||
394 | } | ||
395 | } | ||
396 | dbcon.Close(); | ||
397 | } | ||
398 | } | ||
399 | catch (Exception e) | ||
400 | { | ||
401 | m_log.Error("[PROFILES_DATA]: GetPickInfo exception ", e); | ||
402 | } | ||
403 | |||
404 | return pick; | ||
405 | } | ||
406 | |||
407 | public bool UpdatePicksRecord(UserProfilePick pick) | ||
408 | { | ||
409 | string query = string.Empty; | ||
410 | |||
411 | |||
412 | query = @"WITH upsert AS ( | ||
413 | UPDATE userpicks SET | ||
414 | pickuuid = :PickId, creatoruuid = :CreatorId, toppick = :TopPick, parceluuid = :ParcelId, | ||
415 | name = :Name, description = :Desc, snapshotuuid = :SnapshotId, ""user"" = :User, | ||
416 | originalname = :Original, simname = :SimName, posglobal = :GlobalPos, | ||
417 | sortorder = :SortOrder, enabled = :Enabled | ||
418 | RETURNING * ) | ||
419 | INSERT INTO userpicks (pickuuid,creatoruuid,toppick,parceluuid,name,description, | ||
420 | snapshotuuid,""user"",originalname,simname,posglobal,sortorder,enabled) | ||
421 | SELECT | ||
422 | :PickId,:CreatorId,:TopPick,:ParcelId,:Name,:Desc,:SnapshotId,:User, | ||
423 | :Original,:SimName,:GlobalPos,:SortOrder,:Enabled | ||
424 | WHERE NOT EXISTS ( | ||
425 | SELECT * FROM upsert )"; | ||
426 | |||
427 | try | ||
428 | { | ||
429 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
430 | { | ||
431 | dbcon.Open(); | ||
432 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
433 | { | ||
434 | cmd.Parameters.Add(m_database.CreateParameter("PickId", pick.PickId)); | ||
435 | cmd.Parameters.Add(m_database.CreateParameter("CreatorId", pick.CreatorId)); | ||
436 | cmd.Parameters.Add(m_database.CreateParameter("TopPick", pick.TopPick)); | ||
437 | cmd.Parameters.Add(m_database.CreateParameter("ParcelId", pick.ParcelId)); | ||
438 | cmd.Parameters.Add(m_database.CreateParameter("Name", pick.Name)); | ||
439 | cmd.Parameters.Add(m_database.CreateParameter("Desc", pick.Desc)); | ||
440 | cmd.Parameters.Add(m_database.CreateParameter("SnapshotId", pick.SnapshotId)); | ||
441 | cmd.Parameters.Add(m_database.CreateParameter("User", pick.ParcelName)); | ||
442 | cmd.Parameters.Add(m_database.CreateParameter("Original", pick.OriginalName)); | ||
443 | cmd.Parameters.Add(m_database.CreateParameter("SimName", pick.SimName)); | ||
444 | cmd.Parameters.Add(m_database.CreateParameter("GlobalPos", pick.GlobalPos)); | ||
445 | cmd.Parameters.Add(m_database.CreateParameter("SortOrder", pick.SortOrder)); | ||
446 | cmd.Parameters.Add(m_database.CreateParameter("Enabled", pick.Enabled)); | ||
447 | |||
448 | cmd.ExecuteNonQuery(); | ||
449 | } | ||
450 | } | ||
451 | } | ||
452 | catch (Exception e) | ||
453 | { | ||
454 | m_log.Error("[PROFILES_DATA]: UpdateAvatarNotes exception ", e); | ||
455 | return false; | ||
456 | } | ||
457 | |||
458 | return true; | ||
459 | } | ||
460 | |||
461 | public bool DeletePicksRecord(UUID pickId) | ||
462 | { | ||
463 | string query = string.Empty; | ||
464 | |||
465 | query += "DELETE FROM userpicks WHERE "; | ||
466 | query += "pickuuid = :PickId"; | ||
467 | |||
468 | try | ||
469 | { | ||
470 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
471 | { | ||
472 | dbcon.Open(); | ||
473 | |||
474 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
475 | { | ||
476 | cmd.Parameters.Add(m_database.CreateParameter("PickId", pickId)); | ||
477 | |||
478 | cmd.ExecuteNonQuery(); | ||
479 | } | ||
480 | } | ||
481 | } | ||
482 | catch (Exception e) | ||
483 | { | ||
484 | m_log.Error("[PROFILES_DATA]: DeleteUserPickRecord exception ", e); | ||
485 | return false; | ||
486 | } | ||
487 | |||
488 | return true; | ||
489 | } | ||
490 | |||
491 | #endregion Picks Queries | ||
492 | |||
493 | #region Avatar Notes Queries | ||
494 | |||
495 | public bool GetAvatarNotes(ref UserProfileNotes notes) | ||
496 | { // WIP | ||
497 | string query = string.Empty; | ||
498 | |||
499 | query += "SELECT notes FROM usernotes WHERE "; | ||
500 | query += "useruuid = :Id AND "; | ||
501 | query += "targetuuid = :TargetId"; | ||
502 | OSDArray data = new OSDArray(); | ||
503 | |||
504 | try | ||
505 | { | ||
506 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
507 | { | ||
508 | dbcon.Open(); | ||
509 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
510 | { | ||
511 | cmd.Parameters.Add(m_database.CreateParameter("Id", notes.UserId)); | ||
512 | cmd.Parameters.Add(m_database.CreateParameter("TargetId", notes.TargetId)); | ||
513 | |||
514 | using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
515 | { | ||
516 | if (reader.HasRows) | ||
517 | { | ||
518 | reader.Read(); | ||
519 | notes.Notes = OSD.FromString((string)reader["notes"]); | ||
520 | } | ||
521 | } | ||
522 | } | ||
523 | } | ||
524 | } | ||
525 | catch (Exception e) | ||
526 | { | ||
527 | m_log.Error("[PROFILES_DATA]: GetAvatarNotes exception ", e); | ||
528 | } | ||
529 | |||
530 | return true; | ||
531 | } | ||
532 | |||
533 | public bool UpdateAvatarNotes(ref UserProfileNotes note, ref string result) | ||
534 | { | ||
535 | string query = string.Empty; | ||
536 | bool remove; | ||
537 | |||
538 | if (string.IsNullOrEmpty(note.Notes)) | ||
539 | { | ||
540 | remove = true; | ||
541 | query += "DELETE FROM usernotes WHERE "; | ||
542 | query += "useruuid=:UserId AND "; | ||
543 | query += "targetuuid=:TargetId"; | ||
544 | } | ||
545 | else | ||
546 | { | ||
547 | remove = false; | ||
548 | |||
549 | query = @"WITH upsert AS ( | ||
550 | UPDATE usernotes SET notes = :Notes, useruuid = :UserId, targetuuid = :TargetId RETURNING * ) | ||
551 | INSERT INTO usernotes (notes,useruuid,targetuuid) | ||
552 | SELECT :Notes,:UserId,:TargetId | ||
553 | WHERE NOT EXISTS ( | ||
554 | SELECT * FROM upsert | ||
555 | )"; | ||
556 | } | ||
557 | |||
558 | try | ||
559 | { | ||
560 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
561 | { | ||
562 | dbcon.Open(); | ||
563 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
564 | { | ||
565 | if (!remove) | ||
566 | cmd.Parameters.Add(m_database.CreateParameter("Notes", note.Notes)); | ||
567 | |||
568 | cmd.Parameters.Add(m_database.CreateParameter("TargetId", note.TargetId)); | ||
569 | cmd.Parameters.Add(m_database.CreateParameter("UserId", note.UserId)); | ||
570 | |||
571 | cmd.ExecuteNonQuery(); | ||
572 | } | ||
573 | } | ||
574 | } | ||
575 | catch (Exception e) | ||
576 | { | ||
577 | m_log.Error("[PROFILES_DATA]: UpdateAvatarNotes exception ", e); | ||
578 | return false; | ||
579 | } | ||
580 | |||
581 | return true; | ||
582 | } | ||
583 | |||
584 | #endregion Avatar Notes Queries | ||
585 | |||
586 | #region Avatar Properties | ||
587 | |||
588 | public bool GetAvatarProperties(ref UserProfileProperties props, ref string result) | ||
589 | { | ||
590 | string query = string.Empty; | ||
591 | |||
592 | query += "SELECT * FROM userprofile WHERE "; | ||
593 | query += "useruuid = :Id"; | ||
594 | |||
595 | try | ||
596 | { | ||
597 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
598 | { | ||
599 | dbcon.Open(); | ||
600 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
601 | { | ||
602 | cmd.Parameters.Add(m_database.CreateParameter("Id", props.UserId)); | ||
603 | |||
604 | using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
605 | { | ||
606 | if (reader.HasRows) | ||
607 | { | ||
608 | // m_log.DebugFormat("[PROFILES_DATA]" + | ||
609 | // ": Getting data for {0}.", props.UserId); | ||
610 | reader.Read(); | ||
611 | props.WebUrl = (string)reader["profileURL"].ToString(); | ||
612 | props.ImageId = DBGuid.FromDB(reader["profileImage"]); | ||
613 | props.AboutText = (string)reader["profileAboutText"]; | ||
614 | props.FirstLifeImageId = DBGuid.FromDB(reader["profileFirstImage"]); | ||
615 | props.FirstLifeText = (string)reader["profileFirstText"]; | ||
616 | props.PartnerId = DBGuid.FromDB(reader["profilePartner"]); | ||
617 | props.WantToMask = (int)reader["profileWantToMask"]; | ||
618 | props.WantToText = (string)reader["profileWantToText"]; | ||
619 | props.SkillsMask = (int)reader["profileSkillsMask"]; | ||
620 | props.SkillsText = (string)reader["profileSkillsText"]; | ||
621 | props.Language = (string)reader["profileLanguages"]; | ||
622 | } | ||
623 | else | ||
624 | { | ||
625 | //m_log.DebugFormat("[PROFILES_DATA]" + | ||
626 | // ": No data for {0}", props.UserId); | ||
627 | |||
628 | props.WebUrl = string.Empty; | ||
629 | props.ImageId = UUID.Zero; | ||
630 | props.AboutText = string.Empty; | ||
631 | props.FirstLifeImageId = UUID.Zero; | ||
632 | props.FirstLifeText = string.Empty; | ||
633 | props.PartnerId = UUID.Zero; | ||
634 | props.WantToMask = 0; | ||
635 | props.WantToText = string.Empty; | ||
636 | props.SkillsMask = 0; | ||
637 | props.SkillsText = string.Empty; | ||
638 | props.Language = string.Empty; | ||
639 | props.PublishProfile = false; | ||
640 | props.PublishMature = false; | ||
641 | |||
642 | query = "INSERT INTO userprofile ("; | ||
643 | query += "useruuid, "; | ||
644 | query += "\"profilePartner\", "; | ||
645 | query += "\"profileAllowPublish\", "; | ||
646 | query += "\"profileMaturePublish\", "; | ||
647 | query += "\"profileURL\", "; | ||
648 | query += "\"profileWantToMask\", "; | ||
649 | query += "\"profileWantToText\", "; | ||
650 | query += "\"profileSkillsMask\", "; | ||
651 | query += "\"profileSkillsText\", "; | ||
652 | query += "\"profileLanguages\", "; | ||
653 | query += "\"profileImage\", "; | ||
654 | query += "\"profileAboutText\", "; | ||
655 | query += "\"profileFirstImage\", "; | ||
656 | query += "\"profileFirstText\") VALUES ("; | ||
657 | query += ":userId, "; | ||
658 | query += ":profilePartner, "; | ||
659 | query += ":profileAllowPublish, "; | ||
660 | query += ":profileMaturePublish, "; | ||
661 | query += ":profileURL, "; | ||
662 | query += ":profileWantToMask, "; | ||
663 | query += ":profileWantToText, "; | ||
664 | query += ":profileSkillsMask, "; | ||
665 | query += ":profileSkillsText, "; | ||
666 | query += ":profileLanguages, "; | ||
667 | query += ":profileImage, "; | ||
668 | query += ":profileAboutText, "; | ||
669 | query += ":profileFirstImage, "; | ||
670 | query += ":profileFirstText)"; | ||
671 | |||
672 | dbcon.Close(); | ||
673 | dbcon.Open(); | ||
674 | |||
675 | using (NpgsqlCommand put = new NpgsqlCommand(query, dbcon)) | ||
676 | { | ||
677 | //m_log.DebugFormat("[PROFILES_DATA]" + | ||
678 | // ": Adding new data for {0}", props.UserId); | ||
679 | |||
680 | put.Parameters.Add(m_database.CreateParameter("userId", props.UserId)); | ||
681 | put.Parameters.Add(m_database.CreateParameter("profilePartner", props.PartnerId)); | ||
682 | put.Parameters.Add(m_database.CreateParameter("profileAllowPublish", props.PublishProfile)); | ||
683 | put.Parameters.Add(m_database.CreateParameter("profileMaturePublish", props.PublishMature)); | ||
684 | put.Parameters.Add(m_database.CreateParameter("profileURL", props.WebUrl)); | ||
685 | put.Parameters.Add(m_database.CreateParameter("profileWantToMask", props.WantToMask)); | ||
686 | put.Parameters.Add(m_database.CreateParameter("profileWantToText", props.WantToText)); | ||
687 | put.Parameters.Add(m_database.CreateParameter("profileSkillsMask", props.SkillsMask)); | ||
688 | put.Parameters.Add(m_database.CreateParameter("profileSkillsText", props.SkillsText)); | ||
689 | put.Parameters.Add(m_database.CreateParameter("profileLanguages", props.Language)); | ||
690 | put.Parameters.Add(m_database.CreateParameter("profileImage", props.ImageId)); | ||
691 | put.Parameters.Add(m_database.CreateParameter("profileAboutText", props.AboutText)); | ||
692 | put.Parameters.Add(m_database.CreateParameter("profileFirstImage", props.FirstLifeImageId)); | ||
693 | put.Parameters.Add(m_database.CreateParameter("profileFirstText", props.FirstLifeText)); | ||
694 | |||
695 | put.ExecuteNonQuery(); | ||
696 | } | ||
697 | } | ||
698 | } | ||
699 | } | ||
700 | } | ||
701 | } | ||
702 | catch (Exception e) | ||
703 | { | ||
704 | m_log.Error("[PROFILES_DATA]: GetAvatarProperties exception ", e); | ||
705 | result = e.Message; | ||
706 | return false; | ||
707 | } | ||
708 | |||
709 | return true; | ||
710 | } | ||
711 | |||
712 | public bool UpdateAvatarProperties(ref UserProfileProperties props, ref string result) | ||
713 | { | ||
714 | string query = string.Empty; | ||
715 | |||
716 | query += "UPDATE userprofile SET "; | ||
717 | query += "\"profileURL\"=:profileURL, "; | ||
718 | query += "\"profileImage\"=:image, "; | ||
719 | query += "\"profileAboutText\"=:abouttext,"; | ||
720 | query += "\"profileFirstImage\"=:firstlifeimage,"; | ||
721 | query += "\"profileFirstText\"=:firstlifetext "; | ||
722 | query += "WHERE \"useruuid\"=:uuid"; | ||
723 | |||
724 | try | ||
725 | { | ||
726 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
727 | { | ||
728 | dbcon.Open(); | ||
729 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
730 | { | ||
731 | cmd.Parameters.Add(m_database.CreateParameter("profileURL", props.WebUrl)); | ||
732 | cmd.Parameters.Add(m_database.CreateParameter("image", props.ImageId)); | ||
733 | cmd.Parameters.Add(m_database.CreateParameter("abouttext", props.AboutText)); | ||
734 | cmd.Parameters.Add(m_database.CreateParameter("firstlifeimage", props.FirstLifeImageId)); | ||
735 | cmd.Parameters.Add(m_database.CreateParameter("firstlifetext", props.FirstLifeText)); | ||
736 | cmd.Parameters.Add(m_database.CreateParameter("uuid", props.UserId)); | ||
737 | |||
738 | cmd.ExecuteNonQuery(); | ||
739 | } | ||
740 | } | ||
741 | } | ||
742 | catch (Exception e) | ||
743 | { | ||
744 | m_log.Error("[PROFILES_DATA]: AgentPropertiesUpdate exception ", e); | ||
745 | return false; | ||
746 | } | ||
747 | |||
748 | return true; | ||
749 | } | ||
750 | |||
751 | #endregion Avatar Properties | ||
752 | |||
753 | #region Avatar Interests | ||
754 | |||
755 | public bool UpdateAvatarInterests(UserProfileProperties up, ref string result) | ||
756 | { | ||
757 | string query = string.Empty; | ||
758 | |||
759 | query += "UPDATE userprofile SET "; | ||
760 | query += "\"profileWantToMask\"=:WantMask, "; | ||
761 | query += "\"profileWantToText\"=:WantText,"; | ||
762 | query += "\"profileSkillsMask\"=:SkillsMask,"; | ||
763 | query += "\"profileSkillsText\"=:SkillsText, "; | ||
764 | query += "\"profileLanguages\"=:Languages "; | ||
765 | query += "WHERE \"useruuid\"=:uuid"; | ||
766 | |||
767 | try | ||
768 | { | ||
769 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
770 | { | ||
771 | dbcon.Open(); | ||
772 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
773 | { | ||
774 | cmd.Parameters.Add(m_database.CreateParameter("WantMask", up.WantToMask)); | ||
775 | cmd.Parameters.Add(m_database.CreateParameter("WantText", up.WantToText)); | ||
776 | cmd.Parameters.Add(m_database.CreateParameter("SkillsMask", up.SkillsMask)); | ||
777 | cmd.Parameters.Add(m_database.CreateParameter("SkillsText", up.SkillsText)); | ||
778 | cmd.Parameters.Add(m_database.CreateParameter("Languages", up.Language)); | ||
779 | cmd.Parameters.Add(m_database.CreateParameter("uuid", up.UserId)); | ||
780 | |||
781 | cmd.ExecuteNonQuery(); | ||
782 | } | ||
783 | } | ||
784 | } | ||
785 | catch (Exception e) | ||
786 | { | ||
787 | m_log.Error("[PROFILES_DATA]: UpdateAvatarInterests exception ", e); | ||
788 | result = e.Message; | ||
789 | return false; | ||
790 | } | ||
791 | |||
792 | return true; | ||
793 | } | ||
794 | |||
795 | #endregion Avatar Interests | ||
796 | |||
797 | public OSDArray GetUserImageAssets(UUID avatarId) | ||
798 | { | ||
799 | OSDArray data = new OSDArray(); | ||
800 | string query = "SELECT \"snapshotuuid\" FROM {0} WHERE \"creatoruuid\" = :Id"; | ||
801 | |||
802 | try | ||
803 | { | ||
804 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
805 | { | ||
806 | dbcon.Open(); | ||
807 | |||
808 | using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format(query, "\"classifieds\""), dbcon)) | ||
809 | { | ||
810 | cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId)); | ||
811 | |||
812 | using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
813 | { | ||
814 | if (reader.HasRows) | ||
815 | { | ||
816 | while (reader.Read()) | ||
817 | { | ||
818 | data.Add(new OSDString(reader["snapshotuuid"].ToString())); | ||
819 | } | ||
820 | } | ||
821 | } | ||
822 | } | ||
823 | |||
824 | dbcon.Close(); | ||
825 | dbcon.Open(); | ||
826 | |||
827 | using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format(query, "\"userpicks\""), dbcon)) | ||
828 | { | ||
829 | cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId)); | ||
830 | |||
831 | using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
832 | { | ||
833 | if (reader.HasRows) | ||
834 | { | ||
835 | while (reader.Read()) | ||
836 | { | ||
837 | data.Add(new OSDString(reader["snapshotuuid"].ToString())); | ||
838 | } | ||
839 | } | ||
840 | } | ||
841 | } | ||
842 | |||
843 | dbcon.Close(); | ||
844 | dbcon.Open(); | ||
845 | |||
846 | query = "SELECT \"profileImage\", \"profileFirstImage\" FROM \"userprofile\" WHERE \"useruuid\" = :Id"; | ||
847 | |||
848 | using (NpgsqlCommand cmd = new NpgsqlCommand(string.Format(query, "\"userpicks\""), dbcon)) | ||
849 | { | ||
850 | cmd.Parameters.Add(m_database.CreateParameter("Id", avatarId)); | ||
851 | |||
852 | using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
853 | { | ||
854 | if (reader.HasRows) | ||
855 | { | ||
856 | while (reader.Read()) | ||
857 | { | ||
858 | data.Add(new OSDString(reader["profileImage"].ToString())); | ||
859 | data.Add(new OSDString(reader["profileFirstImage"].ToString())); | ||
860 | } | ||
861 | } | ||
862 | } | ||
863 | } | ||
864 | } | ||
865 | } | ||
866 | catch (Exception e) | ||
867 | { | ||
868 | m_log.Error("[PROFILES_DATA]: GetUserImageAssets exception ", e); | ||
869 | } | ||
870 | |||
871 | return data; | ||
872 | } | ||
873 | |||
874 | #region User Preferences | ||
875 | |||
876 | public bool GetUserPreferences(ref UserPreferences pref, ref string result) | ||
877 | { | ||
878 | string query = string.Empty; | ||
879 | |||
880 | query += "SELECT imviaemail::VARCHAR,visible::VARCHAR,email FROM "; | ||
881 | query += "usersettings WHERE "; | ||
882 | query += "useruuid = :Id"; | ||
883 | |||
884 | OSDArray data = new OSDArray(); | ||
885 | |||
886 | try | ||
887 | { | ||
888 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
889 | { | ||
890 | dbcon.Open(); | ||
891 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
892 | { | ||
893 | cmd.Parameters.Add(m_database.CreateParameter("Id", pref.UserId)); | ||
894 | |||
895 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
896 | { | ||
897 | if (reader.HasRows) | ||
898 | { | ||
899 | reader.Read(); | ||
900 | bool.TryParse((string)reader["imviaemail"], out pref.IMViaEmail); | ||
901 | bool.TryParse((string)reader["visible"], out pref.Visible); | ||
902 | pref.EMail = (string)reader["email"]; | ||
903 | } | ||
904 | else | ||
905 | { | ||
906 | using (NpgsqlCommand put = new NpgsqlCommand(query, dbcon)) | ||
907 | { | ||
908 | put.Parameters.Add(m_database.CreateParameter("Id", pref.UserId)); | ||
909 | query = "INSERT INTO usersettings VALUES "; | ||
910 | query += "(:Id,'false','false', '')"; | ||
911 | |||
912 | put.ExecuteNonQuery(); | ||
913 | } | ||
914 | } | ||
915 | } | ||
916 | } | ||
917 | } | ||
918 | } | ||
919 | catch (Exception e) | ||
920 | { | ||
921 | m_log.Error("[PROFILES_DATA]: GetUserPreferences exception ", e); | ||
922 | result = e.Message; | ||
923 | } | ||
924 | |||
925 | return true; | ||
926 | } | ||
927 | |||
928 | public bool UpdateUserPreferences(ref UserPreferences pref, ref string result) | ||
929 | { | ||
930 | string query = string.Empty; | ||
931 | |||
932 | query += "UPDATE usersettings SET "; | ||
933 | query += "imviaemail=:ImViaEmail, "; | ||
934 | query += "visible=:Visible, "; | ||
935 | query += "email=:Email "; | ||
936 | query += "WHERE useruuid=:uuid"; | ||
937 | |||
938 | try | ||
939 | { | ||
940 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
941 | { | ||
942 | dbcon.Open(); | ||
943 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
944 | { | ||
945 | cmd.Parameters.Add(m_database.CreateParameter("ImViaEmail", pref.IMViaEmail)); | ||
946 | cmd.Parameters.Add(m_database.CreateParameter("Visible", pref.Visible)); | ||
947 | cmd.Parameters.Add(m_database.CreateParameter("EMail", pref.EMail.ToString().ToLower())); | ||
948 | cmd.Parameters.Add(m_database.CreateParameter("uuid", pref.UserId)); | ||
949 | |||
950 | cmd.ExecuteNonQuery(); | ||
951 | } | ||
952 | } | ||
953 | } | ||
954 | catch (Exception e) | ||
955 | { | ||
956 | m_log.Error("[PROFILES_DATA]: UpdateUserPreferences exception ", e); | ||
957 | result = e.Message; | ||
958 | return false; | ||
959 | } | ||
960 | |||
961 | return true; | ||
962 | } | ||
963 | |||
964 | #endregion User Preferences | ||
965 | |||
966 | #region Integration | ||
967 | |||
968 | public bool GetUserAppData(ref UserAppData props, ref string result) | ||
969 | { | ||
970 | string query = string.Empty; | ||
971 | |||
972 | query += "SELECT * FROM userdata WHERE "; | ||
973 | query += "\"UserId\" = :Id AND "; | ||
974 | query += "\"TagId\" = :TagId"; | ||
975 | |||
976 | try | ||
977 | { | ||
978 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
979 | { | ||
980 | dbcon.Open(); | ||
981 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
982 | { | ||
983 | cmd.Parameters.Add(m_database.CreateParameter("Id", props.UserId)); | ||
984 | cmd.Parameters.Add(m_database.CreateParameter("TagId", props.TagId)); | ||
985 | |||
986 | using (NpgsqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
987 | { | ||
988 | if (reader.HasRows) | ||
989 | { | ||
990 | reader.Read(); | ||
991 | props.DataKey = (string)reader["DataKey"]; | ||
992 | props.DataVal = (string)reader["DataVal"]; | ||
993 | } | ||
994 | else | ||
995 | { | ||
996 | query += "INSERT INTO userdata VALUES ( "; | ||
997 | query += ":UserId,"; | ||
998 | query += ":TagId,"; | ||
999 | query += ":DataKey,"; | ||
1000 | query += ":DataVal) "; | ||
1001 | |||
1002 | using (NpgsqlCommand put = new NpgsqlCommand(query, dbcon)) | ||
1003 | { | ||
1004 | put.Parameters.Add(m_database.CreateParameter("UserId", props.UserId)); | ||
1005 | put.Parameters.Add(m_database.CreateParameter("TagId", props.TagId)); | ||
1006 | put.Parameters.Add(m_database.CreateParameter("DataKey", props.DataKey.ToString())); | ||
1007 | put.Parameters.Add(m_database.CreateParameter("DataVal", props.DataVal.ToString())); | ||
1008 | |||
1009 | put.ExecuteNonQuery(); | ||
1010 | } | ||
1011 | } | ||
1012 | } | ||
1013 | } | ||
1014 | } | ||
1015 | } | ||
1016 | catch (Exception e) | ||
1017 | { | ||
1018 | m_log.Error("[PROFILES_DATA]: GetUserAppData exception ", e); | ||
1019 | result = e.Message; | ||
1020 | return false; | ||
1021 | } | ||
1022 | |||
1023 | return true; | ||
1024 | } | ||
1025 | |||
1026 | public bool SetUserAppData(UserAppData props, ref string result) | ||
1027 | { | ||
1028 | string query = string.Empty; | ||
1029 | |||
1030 | query += "UPDATE userdata SET "; | ||
1031 | query += "\"TagId\" = :TagId, "; | ||
1032 | query += "\"DataKey\" = :DataKey, "; | ||
1033 | query += "\"DataVal\" = :DataVal WHERE "; | ||
1034 | query += "\"UserId\" = :UserId AND "; | ||
1035 | query += "\"TagId\" = :TagId"; | ||
1036 | |||
1037 | try | ||
1038 | { | ||
1039 | using (NpgsqlConnection dbcon = new NpgsqlConnection(ConnectionString)) | ||
1040 | { | ||
1041 | dbcon.Open(); | ||
1042 | using (NpgsqlCommand cmd = new NpgsqlCommand(query, dbcon)) | ||
1043 | { | ||
1044 | cmd.Parameters.Add(m_database.CreateParameter("UserId", props.UserId.ToString())); | ||
1045 | cmd.Parameters.Add(m_database.CreateParameter("TagId", props.TagId.ToString())); | ||
1046 | cmd.Parameters.Add(m_database.CreateParameter("DataKey", props.DataKey.ToString())); | ||
1047 | cmd.Parameters.Add(m_database.CreateParameter("DataVal", props.DataKey.ToString())); | ||
1048 | |||
1049 | cmd.ExecuteNonQuery(); | ||
1050 | } | ||
1051 | } | ||
1052 | } | ||
1053 | catch (Exception e) | ||
1054 | { | ||
1055 | m_log.Error("[PROFILES_DATA]: SetUserData exception ", e); | ||
1056 | return false; | ||
1057 | } | ||
1058 | |||
1059 | return true; | ||
1060 | } | ||
1061 | |||
1062 | #endregion Integration | ||
1063 | } | ||
1064 | } \ No newline at end of file | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLXAssetData.cs b/OpenSim/Data/PGSQL/PGSQLXAssetData.cs new file mode 100644 index 0000000..4f682f0 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLXAssetData.cs | |||
@@ -0,0 +1,587 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections.Generic; | ||
30 | using System.Data; | ||
31 | using System.IO; | ||
32 | using System.IO.Compression; | ||
33 | using System.Reflection; | ||
34 | using System.Security.Cryptography; | ||
35 | using System.Text; | ||
36 | using log4net; | ||
37 | using OpenMetaverse; | ||
38 | using OpenSim.Framework; | ||
39 | using OpenSim.Data; | ||
40 | using Npgsql; | ||
41 | |||
42 | namespace OpenSim.Data.PGSQL | ||
43 | { | ||
44 | public class PGSQLXAssetData : IXAssetDataPlugin | ||
45 | { | ||
46 | private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | ||
47 | |||
48 | protected virtual Assembly Assembly | ||
49 | { | ||
50 | get { return GetType().Assembly; } | ||
51 | } | ||
52 | |||
53 | /// <summary> | ||
54 | /// Number of days that must pass before we update the access time on an asset when it has been fetched. | ||
55 | /// </summary> | ||
56 | private const int DaysBetweenAccessTimeUpdates = 30; | ||
57 | |||
58 | private bool m_enableCompression = false; | ||
59 | private PGSQLManager m_database; | ||
60 | private string m_connectionString; | ||
61 | private object m_dbLock = new object(); | ||
62 | |||
63 | /// <summary> | ||
64 | /// We can reuse this for all hashing since all methods are single-threaded through m_dbBLock | ||
65 | /// </summary> | ||
66 | private HashAlgorithm hasher = new SHA256CryptoServiceProvider(); | ||
67 | |||
68 | #region IPlugin Members | ||
69 | |||
70 | public string Version { get { return "1.0.0.0"; } } | ||
71 | |||
72 | /// <summary> | ||
73 | /// <para>Initialises Asset interface</para> | ||
74 | /// <para> | ||
75 | /// <list type="bullet"> | ||
76 | /// <item>Loads and initialises the PGSQL storage plugin.</item> | ||
77 | /// <item>Warns and uses the obsolete pgsql_connection.ini if connect string is empty.</item> | ||
78 | /// <item>Check for migration</item> | ||
79 | /// </list> | ||
80 | /// </para> | ||
81 | /// </summary> | ||
82 | /// <param name="connect">connect string</param> | ||
83 | public void Initialise(string connect) | ||
84 | { | ||
85 | m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************"); | ||
86 | m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************"); | ||
87 | m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************"); | ||
88 | m_log.ErrorFormat("[PGSQL XASSETDATA]: THIS PLUGIN IS STRICTLY EXPERIMENTAL."); | ||
89 | m_log.ErrorFormat("[PGSQL XASSETDATA]: DO NOT USE FOR ANY DATA THAT YOU DO NOT MIND LOSING."); | ||
90 | m_log.ErrorFormat("[PGSQL XASSETDATA]: DATABASE TABLES CAN CHANGE AT ANY TIME, CAUSING EXISTING DATA TO BE LOST."); | ||
91 | m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************"); | ||
92 | m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************"); | ||
93 | m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************"); | ||
94 | |||
95 | m_connectionString = connect; | ||
96 | m_database = new PGSQLManager(m_connectionString); | ||
97 | |||
98 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
99 | { | ||
100 | dbcon.Open(); | ||
101 | Migration m = new Migration(dbcon, Assembly, "XAssetStore"); | ||
102 | m.Update(); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | public void Initialise() | ||
107 | { | ||
108 | throw new NotImplementedException(); | ||
109 | } | ||
110 | |||
111 | public void Dispose() { } | ||
112 | |||
113 | /// <summary> | ||
114 | /// The name of this DB provider | ||
115 | /// </summary> | ||
116 | public string Name | ||
117 | { | ||
118 | get { return "PGSQL XAsset storage engine"; } | ||
119 | } | ||
120 | |||
121 | #endregion | ||
122 | |||
123 | #region IAssetDataPlugin Members | ||
124 | |||
125 | /// <summary> | ||
126 | /// Fetch Asset <paramref name="assetID"/> from database | ||
127 | /// </summary> | ||
128 | /// <param name="assetID">Asset UUID to fetch</param> | ||
129 | /// <returns>Return the asset</returns> | ||
130 | /// <remarks>On failure : throw an exception and attempt to reconnect to database</remarks> | ||
131 | public AssetBase GetAsset(UUID assetID) | ||
132 | { | ||
133 | // m_log.DebugFormat("[PGSQL XASSET DATA]: Looking for asset {0}", assetID); | ||
134 | |||
135 | AssetBase asset = null; | ||
136 | lock (m_dbLock) | ||
137 | { | ||
138 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
139 | { | ||
140 | dbcon.Open(); | ||
141 | |||
142 | using (NpgsqlCommand cmd = new NpgsqlCommand( | ||
143 | @"SELECT name, description, access_time, ""AssetType"", local, temporary, asset_flags, creatorid, data | ||
144 | FROM XAssetsMeta | ||
145 | JOIN XAssetsData ON XAssetsMeta.hash = XAssetsData.Hash WHERE id=:ID", | ||
146 | dbcon)) | ||
147 | { | ||
148 | cmd.Parameters.Add(m_database.CreateParameter("ID", assetID)); | ||
149 | |||
150 | try | ||
151 | { | ||
152 | using (NpgsqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
153 | { | ||
154 | if (dbReader.Read()) | ||
155 | { | ||
156 | asset = new AssetBase( | ||
157 | assetID, | ||
158 | (string)dbReader["name"], | ||
159 | Convert.ToSByte(dbReader["AssetType"]), | ||
160 | dbReader["creatorid"].ToString()); | ||
161 | |||
162 | asset.Data = (byte[])dbReader["data"]; | ||
163 | asset.Description = (string)dbReader["description"]; | ||
164 | |||
165 | string local = dbReader["local"].ToString(); | ||
166 | if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase)) | ||
167 | asset.Local = true; | ||
168 | else | ||
169 | asset.Local = false; | ||
170 | |||
171 | asset.Temporary = Convert.ToBoolean(dbReader["temporary"]); | ||
172 | asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); | ||
173 | |||
174 | if (m_enableCompression) | ||
175 | { | ||
176 | using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress)) | ||
177 | { | ||
178 | MemoryStream outputStream = new MemoryStream(); | ||
179 | WebUtil.CopyStream(decompressionStream, outputStream, int.MaxValue); | ||
180 | // int compressedLength = asset.Data.Length; | ||
181 | asset.Data = outputStream.ToArray(); | ||
182 | |||
183 | // m_log.DebugFormat( | ||
184 | // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}", | ||
185 | // asset.ID, asset.Name, asset.Data.Length, compressedLength); | ||
186 | } | ||
187 | } | ||
188 | |||
189 | UpdateAccessTime(asset.Metadata, (int)dbReader["access_time"]); | ||
190 | } | ||
191 | } | ||
192 | } | ||
193 | catch (Exception e) | ||
194 | { | ||
195 | m_log.Error(string.Format("[PGSQL XASSET DATA]: Failure fetching asset {0}", assetID), e); | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | } | ||
200 | |||
201 | return asset; | ||
202 | } | ||
203 | |||
204 | /// <summary> | ||
205 | /// Create an asset in database, or update it if existing. | ||
206 | /// </summary> | ||
207 | /// <param name="asset">Asset UUID to create</param> | ||
208 | /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> | ||
209 | public void StoreAsset(AssetBase asset) | ||
210 | { | ||
211 | // m_log.DebugFormat("[XASSETS DB]: Storing asset {0} {1}", asset.Name, asset.ID); | ||
212 | |||
213 | lock (m_dbLock) | ||
214 | { | ||
215 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
216 | { | ||
217 | dbcon.Open(); | ||
218 | |||
219 | using (NpgsqlTransaction transaction = dbcon.BeginTransaction()) | ||
220 | { | ||
221 | string assetName = asset.Name; | ||
222 | if (asset.Name.Length > 64) | ||
223 | { | ||
224 | assetName = asset.Name.Substring(0, 64); | ||
225 | m_log.WarnFormat( | ||
226 | "[XASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
227 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); | ||
228 | } | ||
229 | |||
230 | string assetDescription = asset.Description; | ||
231 | if (asset.Description.Length > 64) | ||
232 | { | ||
233 | assetDescription = asset.Description.Substring(0, 64); | ||
234 | m_log.WarnFormat( | ||
235 | "[XASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
236 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); | ||
237 | } | ||
238 | |||
239 | if (m_enableCompression) | ||
240 | { | ||
241 | MemoryStream outputStream = new MemoryStream(); | ||
242 | |||
243 | using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false)) | ||
244 | { | ||
245 | // Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue)); | ||
246 | // We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream. | ||
247 | compressionStream.Close(); | ||
248 | byte[] compressedData = outputStream.ToArray(); | ||
249 | asset.Data = compressedData; | ||
250 | } | ||
251 | } | ||
252 | |||
253 | byte[] hash = hasher.ComputeHash(asset.Data); | ||
254 | |||
255 | UUID asset_id; | ||
256 | UUID.TryParse(asset.ID, out asset_id); | ||
257 | |||
258 | // m_log.DebugFormat( | ||
259 | // "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}", | ||
260 | // asset.ID, asset.Name, hash, compressedData.Length); | ||
261 | |||
262 | try | ||
263 | { | ||
264 | using (NpgsqlCommand cmd = | ||
265 | new NpgsqlCommand( | ||
266 | @"insert INTO XAssetsMeta(id, hash, name, description, ""AssetType"", local, temporary, create_time, access_time, asset_flags, creatorid) | ||
267 | Select :ID, :Hash, :Name, :Description, :AssetType, :Local, :Temporary, :CreateTime, :AccessTime, :AssetFlags, :CreatorID | ||
268 | where not exists( Select id from XAssetsMeta where id = :ID); | ||
269 | |||
270 | update XAssetsMeta | ||
271 | set id = :ID, hash = :Hash, name = :Name, description = :Description, | ||
272 | ""AssetType"" = :AssetType, local = :Local, temporary = :Temporary, create_time = :CreateTime, | ||
273 | access_time = :AccessTime, asset_flags = :AssetFlags, creatorid = :CreatorID | ||
274 | where id = :ID; | ||
275 | ", | ||
276 | dbcon)) | ||
277 | { | ||
278 | |||
279 | // create unix epoch time | ||
280 | int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); | ||
281 | cmd.Parameters.Add(m_database.CreateParameter("ID", asset_id)); | ||
282 | cmd.Parameters.Add(m_database.CreateParameter("Hash", hash)); | ||
283 | cmd.Parameters.Add(m_database.CreateParameter("Name", assetName)); | ||
284 | cmd.Parameters.Add(m_database.CreateParameter("Description", assetDescription)); | ||
285 | cmd.Parameters.Add(m_database.CreateParameter("AssetType", asset.Type)); | ||
286 | cmd.Parameters.Add(m_database.CreateParameter("Local", asset.Local)); | ||
287 | cmd.Parameters.Add(m_database.CreateParameter("Temporary", asset.Temporary)); | ||
288 | cmd.Parameters.Add(m_database.CreateParameter("CreateTime", now)); | ||
289 | cmd.Parameters.Add(m_database.CreateParameter("AccessTime", now)); | ||
290 | cmd.Parameters.Add(m_database.CreateParameter("CreatorID", asset.Metadata.CreatorID)); | ||
291 | cmd.Parameters.Add(m_database.CreateParameter("AssetFlags", (int)asset.Flags)); | ||
292 | |||
293 | cmd.ExecuteNonQuery(); | ||
294 | } | ||
295 | } | ||
296 | catch (Exception e) | ||
297 | { | ||
298 | m_log.ErrorFormat("[ASSET DB]: PGSQL failure creating asset metadata {0} with name \"{1}\". Error: {2}", | ||
299 | asset.FullID, asset.Name, e.Message); | ||
300 | |||
301 | transaction.Rollback(); | ||
302 | |||
303 | return; | ||
304 | } | ||
305 | |||
306 | if (!ExistsData(dbcon, transaction, hash)) | ||
307 | { | ||
308 | try | ||
309 | { | ||
310 | using (NpgsqlCommand cmd = | ||
311 | new NpgsqlCommand( | ||
312 | @"INSERT INTO XAssetsData(hash, data) VALUES(:Hash, :Data)", | ||
313 | dbcon)) | ||
314 | { | ||
315 | cmd.Parameters.Add(m_database.CreateParameter("Hash", hash)); | ||
316 | cmd.Parameters.Add(m_database.CreateParameter("Data", asset.Data)); | ||
317 | cmd.ExecuteNonQuery(); | ||
318 | } | ||
319 | } | ||
320 | catch (Exception e) | ||
321 | { | ||
322 | m_log.ErrorFormat("[XASSET DB]: PGSQL failure creating asset data {0} with name \"{1}\". Error: {2}", | ||
323 | asset.FullID, asset.Name, e.Message); | ||
324 | |||
325 | transaction.Rollback(); | ||
326 | |||
327 | return; | ||
328 | } | ||
329 | } | ||
330 | |||
331 | transaction.Commit(); | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | } | ||
336 | |||
337 | /// <summary> | ||
338 | /// Updates the access time of the asset if it was accessed above a given threshhold amount of time. | ||
339 | /// </summary> | ||
340 | /// <remarks> | ||
341 | /// This gives us some insight into assets which haven't ben accessed for a long period. This is only done | ||
342 | /// over the threshold time to avoid excessive database writes as assets are fetched. | ||
343 | /// </remarks> | ||
344 | /// <param name='asset'></param> | ||
345 | /// <param name='accessTime'></param> | ||
346 | private void UpdateAccessTime(AssetMetadata assetMetadata, int accessTime) | ||
347 | { | ||
348 | DateTime now = DateTime.UtcNow; | ||
349 | |||
350 | if ((now - Utils.UnixTimeToDateTime(accessTime)).TotalDays < DaysBetweenAccessTimeUpdates) | ||
351 | return; | ||
352 | |||
353 | lock (m_dbLock) | ||
354 | { | ||
355 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
356 | { | ||
357 | dbcon.Open(); | ||
358 | NpgsqlCommand cmd = | ||
359 | new NpgsqlCommand(@"update XAssetsMeta set access_time=:AccessTime where id=:ID", dbcon); | ||
360 | |||
361 | try | ||
362 | { | ||
363 | UUID asset_id; | ||
364 | UUID.TryParse(assetMetadata.ID, out asset_id); | ||
365 | |||
366 | using (cmd) | ||
367 | { | ||
368 | // create unix epoch time | ||
369 | cmd.Parameters.Add(m_database.CreateParameter("id", asset_id)); | ||
370 | cmd.Parameters.Add(m_database.CreateParameter("access_time", (int)Utils.DateTimeToUnixTime(now))); | ||
371 | cmd.ExecuteNonQuery(); | ||
372 | } | ||
373 | } | ||
374 | catch (Exception e) | ||
375 | { | ||
376 | m_log.ErrorFormat( | ||
377 | "[XASSET PGSQL DB]: Failure updating access_time for asset {0} with name {1} : {2}", | ||
378 | assetMetadata.ID, assetMetadata.Name, e.Message); | ||
379 | } | ||
380 | } | ||
381 | } | ||
382 | } | ||
383 | |||
384 | /// <summary> | ||
385 | /// We assume we already have the m_dbLock. | ||
386 | /// </summary> | ||
387 | /// TODO: need to actually use the transaction. | ||
388 | /// <param name="dbcon"></param> | ||
389 | /// <param name="transaction"></param> | ||
390 | /// <param name="hash"></param> | ||
391 | /// <returns></returns> | ||
392 | private bool ExistsData(NpgsqlConnection dbcon, NpgsqlTransaction transaction, byte[] hash) | ||
393 | { | ||
394 | // m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid); | ||
395 | |||
396 | bool exists = false; | ||
397 | |||
398 | using (NpgsqlCommand cmd = new NpgsqlCommand(@"SELECT hash FROM XAssetsData WHERE hash=:Hash", dbcon)) | ||
399 | { | ||
400 | cmd.Parameters.Add(m_database.CreateParameter("Hash", hash)); | ||
401 | |||
402 | try | ||
403 | { | ||
404 | using (NpgsqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
405 | { | ||
406 | if (dbReader.Read()) | ||
407 | { | ||
408 | // m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid); | ||
409 | exists = true; | ||
410 | } | ||
411 | } | ||
412 | } | ||
413 | catch (Exception e) | ||
414 | { | ||
415 | m_log.ErrorFormat( | ||
416 | "[XASSETS DB]: PGSql failure in ExistsData fetching hash {0}. Exception {1}{2}", | ||
417 | hash, e.Message, e.StackTrace); | ||
418 | } | ||
419 | } | ||
420 | |||
421 | return exists; | ||
422 | } | ||
423 | |||
424 | /// <summary> | ||
425 | /// Check if the assets exist in the database. | ||
426 | /// </summary> | ||
427 | /// <param name="uuids">The assets' IDs</param> | ||
428 | /// <returns>For each asset: true if it exists, false otherwise</returns> | ||
429 | public bool[] AssetsExist(UUID[] uuids) | ||
430 | { | ||
431 | if (uuids.Length == 0) | ||
432 | return new bool[0]; | ||
433 | |||
434 | HashSet<UUID> exist = new HashSet<UUID>(); | ||
435 | |||
436 | string ids = "'" + string.Join("','", uuids) + "'"; | ||
437 | string sql = string.Format(@"SELECT id FROM XAssetsMeta WHERE id IN ({0})", ids); | ||
438 | |||
439 | using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString)) | ||
440 | { | ||
441 | conn.Open(); | ||
442 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
443 | { | ||
444 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
445 | { | ||
446 | while (reader.Read()) | ||
447 | { | ||
448 | UUID id = DBGuid.FromDB(reader["id"]); | ||
449 | exist.Add(id); | ||
450 | } | ||
451 | } | ||
452 | } | ||
453 | } | ||
454 | |||
455 | bool[] results = new bool[uuids.Length]; | ||
456 | for (int i = 0; i < uuids.Length; i++) | ||
457 | results[i] = exist.Contains(uuids[i]); | ||
458 | return results; | ||
459 | } | ||
460 | |||
461 | /// <summary> | ||
462 | /// Check if the asset exists in the database | ||
463 | /// </summary> | ||
464 | /// <param name="uuid">The asset UUID</param> | ||
465 | /// <returns>true if it exists, false otherwise.</returns> | ||
466 | public bool ExistsAsset(UUID uuid) | ||
467 | { | ||
468 | // m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid); | ||
469 | |||
470 | bool assetExists = false; | ||
471 | |||
472 | lock (m_dbLock) | ||
473 | { | ||
474 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
475 | { | ||
476 | dbcon.Open(); | ||
477 | using (NpgsqlCommand cmd = new NpgsqlCommand(@"SELECT id FROM XAssetsMeta WHERE id=:ID", dbcon)) | ||
478 | { | ||
479 | cmd.Parameters.Add(m_database.CreateParameter("id", uuid)); | ||
480 | |||
481 | try | ||
482 | { | ||
483 | using (NpgsqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) | ||
484 | { | ||
485 | if (dbReader.Read()) | ||
486 | { | ||
487 | // m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid); | ||
488 | assetExists = true; | ||
489 | } | ||
490 | } | ||
491 | } | ||
492 | catch (Exception e) | ||
493 | { | ||
494 | m_log.Error(string.Format("[XASSETS DB]: PGSql failure fetching asset {0}", uuid), e); | ||
495 | } | ||
496 | } | ||
497 | } | ||
498 | } | ||
499 | |||
500 | return assetExists; | ||
501 | } | ||
502 | |||
503 | |||
504 | /// <summary> | ||
505 | /// Returns a list of AssetMetadata objects. The list is a subset of | ||
506 | /// the entire data set offset by <paramref name="start" /> containing | ||
507 | /// <paramref name="count" /> elements. | ||
508 | /// </summary> | ||
509 | /// <param name="start">The number of results to discard from the total data set.</param> | ||
510 | /// <param name="count">The number of rows the returned list should contain.</param> | ||
511 | /// <returns>A list of AssetMetadata objects.</returns> | ||
512 | public List<AssetMetadata> FetchAssetMetadataSet(int start, int count) | ||
513 | { | ||
514 | List<AssetMetadata> retList = new List<AssetMetadata>(count); | ||
515 | |||
516 | lock (m_dbLock) | ||
517 | { | ||
518 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
519 | { | ||
520 | dbcon.Open(); | ||
521 | NpgsqlCommand cmd = new NpgsqlCommand( @"SELECT name, description, access_time, ""AssetType"", temporary, id, asset_flags, creatorid | ||
522 | FROM XAssetsMeta | ||
523 | LIMIT :start, :count", dbcon); | ||
524 | cmd.Parameters.Add(m_database.CreateParameter("start", start)); | ||
525 | cmd.Parameters.Add(m_database.CreateParameter("count", count)); | ||
526 | |||
527 | try | ||
528 | { | ||
529 | using (NpgsqlDataReader dbReader = cmd.ExecuteReader()) | ||
530 | { | ||
531 | while (dbReader.Read()) | ||
532 | { | ||
533 | AssetMetadata metadata = new AssetMetadata(); | ||
534 | metadata.Name = (string)dbReader["name"]; | ||
535 | metadata.Description = (string)dbReader["description"]; | ||
536 | metadata.Type = Convert.ToSByte(dbReader["AssetType"]); | ||
537 | metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); | ||
538 | metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); | ||
539 | metadata.FullID = DBGuid.FromDB(dbReader["id"]); | ||
540 | metadata.CreatorID = dbReader["creatorid"].ToString(); | ||
541 | |||
542 | // We'll ignore this for now - it appears unused! | ||
543 | // metadata.SHA1 = dbReader["hash"]); | ||
544 | |||
545 | UpdateAccessTime(metadata, (int)dbReader["access_time"]); | ||
546 | |||
547 | retList.Add(metadata); | ||
548 | } | ||
549 | } | ||
550 | } | ||
551 | catch (Exception e) | ||
552 | { | ||
553 | m_log.Error("[XASSETS DB]: PGSql failure fetching asset set" + Environment.NewLine + e.ToString()); | ||
554 | } | ||
555 | } | ||
556 | } | ||
557 | |||
558 | return retList; | ||
559 | } | ||
560 | |||
561 | public bool Delete(string id) | ||
562 | { | ||
563 | // m_log.DebugFormat("[XASSETS DB]: Deleting asset {0}", id); | ||
564 | |||
565 | lock (m_dbLock) | ||
566 | { | ||
567 | using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString)) | ||
568 | { | ||
569 | dbcon.Open(); | ||
570 | |||
571 | using (NpgsqlCommand cmd = new NpgsqlCommand(@"delete from XAssetsMeta where id=:ID", dbcon)) | ||
572 | { | ||
573 | cmd.Parameters.Add(m_database.CreateParameter(id, id)); | ||
574 | cmd.ExecuteNonQuery(); | ||
575 | } | ||
576 | |||
577 | // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we | ||
578 | // keep a reference count (?) | ||
579 | } | ||
580 | } | ||
581 | |||
582 | return true; | ||
583 | } | ||
584 | |||
585 | #endregion | ||
586 | } | ||
587 | } | ||
diff --git a/OpenSim/Data/PGSQL/PGSQLXInventoryData.cs b/OpenSim/Data/PGSQL/PGSQLXInventoryData.cs new file mode 100644 index 0000000..a22b882 --- /dev/null +++ b/OpenSim/Data/PGSQL/PGSQLXInventoryData.cs | |||
@@ -0,0 +1,330 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ''AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System; | ||
29 | using System.Collections; | ||
30 | using System.Collections.Generic; | ||
31 | using System.Data; | ||
32 | using OpenMetaverse; | ||
33 | using OpenSim.Framework; | ||
34 | using System.Reflection; | ||
35 | using System.Text; | ||
36 | using log4net; | ||
37 | using Npgsql; | ||
38 | using NpgsqlTypes; | ||
39 | |||
40 | namespace OpenSim.Data.PGSQL | ||
41 | { | ||
42 | public class PGSQLXInventoryData : IXInventoryData | ||
43 | { | ||
44 | // private static readonly ILog m_log = LogManager.GetLogger( | ||
45 | // MethodBase.GetCurrentMethod().DeclaringType); | ||
46 | |||
47 | private PGSQLFolderHandler m_Folders; | ||
48 | private PGSQLItemHandler m_Items; | ||
49 | |||
50 | public PGSQLXInventoryData(string conn, string realm) | ||
51 | { | ||
52 | m_Folders = new PGSQLFolderHandler( | ||
53 | conn, "inventoryfolders", "InventoryStore"); | ||
54 | m_Items = new PGSQLItemHandler( | ||
55 | conn, "inventoryitems", String.Empty); | ||
56 | } | ||
57 | |||
58 | public static UUID str2UUID(string strUUID) | ||
59 | { | ||
60 | UUID newUUID = UUID.Zero; | ||
61 | |||
62 | UUID.TryParse(strUUID, out newUUID); | ||
63 | |||
64 | return newUUID; | ||
65 | } | ||
66 | |||
67 | public XInventoryFolder[] GetFolders(string[] fields, string[] vals) | ||
68 | { | ||
69 | return m_Folders.Get(fields, vals); | ||
70 | } | ||
71 | |||
72 | public XInventoryItem[] GetItems(string[] fields, string[] vals) | ||
73 | { | ||
74 | return m_Items.Get(fields, vals); | ||
75 | } | ||
76 | |||
77 | public bool StoreFolder(XInventoryFolder folder) | ||
78 | { | ||
79 | if (folder.folderName.Length > 64) | ||
80 | folder.folderName = folder.folderName.Substring(0, 64); | ||
81 | return m_Folders.Store(folder); | ||
82 | } | ||
83 | |||
84 | public bool StoreItem(XInventoryItem item) | ||
85 | { | ||
86 | if (item.inventoryName.Length > 64) | ||
87 | item.inventoryName = item.inventoryName.Substring(0, 64); | ||
88 | if (item.inventoryDescription.Length > 128) | ||
89 | item.inventoryDescription = item.inventoryDescription.Substring(0, 128); | ||
90 | |||
91 | return m_Items.Store(item); | ||
92 | } | ||
93 | |||
94 | public bool DeleteFolders(string field, string val) | ||
95 | { | ||
96 | return m_Folders.Delete(field, val); | ||
97 | } | ||
98 | |||
99 | public bool DeleteFolders(string[] fields, string[] vals) | ||
100 | { | ||
101 | return m_Folders.Delete(fields, vals); | ||
102 | } | ||
103 | |||
104 | public bool DeleteItems(string field, string val) | ||
105 | { | ||
106 | return m_Items.Delete(field, val); | ||
107 | } | ||
108 | |||
109 | public bool DeleteItems(string[] fields, string[] vals) | ||
110 | { | ||
111 | return m_Items.Delete(fields, vals); | ||
112 | } | ||
113 | |||
114 | public bool MoveItem(string id, string newParent) | ||
115 | { | ||
116 | return m_Items.MoveItem(id, newParent); | ||
117 | } | ||
118 | |||
119 | public bool MoveFolder(string id, string newParent) | ||
120 | { | ||
121 | return m_Folders.MoveFolder(id, newParent); | ||
122 | } | ||
123 | |||
124 | public XInventoryItem[] GetActiveGestures(UUID principalID) | ||
125 | { | ||
126 | return m_Items.GetActiveGestures(principalID.ToString()); | ||
127 | } | ||
128 | |||
129 | public int GetAssetPermissions(UUID principalID, UUID assetID) | ||
130 | { | ||
131 | return m_Items.GetAssetPermissions(principalID, assetID); | ||
132 | } | ||
133 | } | ||
134 | |||
135 | public class PGSQLItemHandler : PGSQLInventoryHandler<XInventoryItem> | ||
136 | { | ||
137 | public PGSQLItemHandler(string c, string t, string m) : | ||
138 | base(c, t, m) | ||
139 | { | ||
140 | } | ||
141 | |||
142 | public bool MoveItem(string id, string newParent) | ||
143 | { | ||
144 | XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id }); | ||
145 | if (retrievedItems.Length == 0) | ||
146 | return false; | ||
147 | |||
148 | UUID oldParent = retrievedItems[0].parentFolderID; | ||
149 | |||
150 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
151 | { | ||
152 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
153 | { | ||
154 | cmd.CommandText = String.Format(@"update {0} set ""parentFolderID"" = :ParentFolderID where ""inventoryID"" = :InventoryID", m_Realm); | ||
155 | cmd.Parameters.Add(m_database.CreateParameter("ParentFolderID", newParent)); | ||
156 | cmd.Parameters.Add(m_database.CreateParameter("InventoryID", id )); | ||
157 | cmd.Connection = conn; | ||
158 | conn.Open(); | ||
159 | |||
160 | if (cmd.ExecuteNonQuery() == 0) | ||
161 | return false; | ||
162 | } | ||
163 | } | ||
164 | |||
165 | IncrementFolderVersion(oldParent); | ||
166 | IncrementFolderVersion(newParent); | ||
167 | |||
168 | return true; | ||
169 | } | ||
170 | |||
171 | public XInventoryItem[] GetActiveGestures(string principalID) | ||
172 | { | ||
173 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
174 | { | ||
175 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
176 | { | ||
177 | cmd.CommandText = String.Format(@"select * from inventoryitems where ""avatarID"" = :uuid and ""assetType"" = :type and ""flags"" = 1", m_Realm); | ||
178 | |||
179 | UUID princID = UUID.Zero; | ||
180 | UUID.TryParse(principalID, out princID); | ||
181 | |||
182 | cmd.Parameters.Add(m_database.CreateParameter("uuid", principalID)); | ||
183 | cmd.Parameters.Add(m_database.CreateParameter("type", (int)AssetType.Gesture)); | ||
184 | cmd.Connection = conn; | ||
185 | conn.Open(); | ||
186 | return DoQuery(cmd); | ||
187 | } | ||
188 | } | ||
189 | } | ||
190 | |||
191 | public int GetAssetPermissions(UUID principalID, UUID assetID) | ||
192 | { | ||
193 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
194 | { | ||
195 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
196 | { | ||
197 | cmd.CommandText = String.Format(@"select bit_or(""inventoryCurrentPermissions"") as ""inventoryCurrentPermissions"" | ||
198 | from inventoryitems | ||
199 | where ""avatarID"" = :PrincipalID | ||
200 | and ""assetID"" = :AssetID | ||
201 | group by ""assetID"" ", m_Realm); | ||
202 | |||
203 | cmd.Parameters.Add(m_database.CreateParameter("PrincipalID", principalID)); | ||
204 | cmd.Parameters.Add(m_database.CreateParameter("AssetID", assetID)); | ||
205 | cmd.Connection = conn; | ||
206 | conn.Open(); | ||
207 | using (NpgsqlDataReader reader = cmd.ExecuteReader()) | ||
208 | { | ||
209 | |||
210 | int perms = 0; | ||
211 | |||
212 | if (reader.Read()) | ||
213 | { | ||
214 | perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]); | ||
215 | } | ||
216 | |||
217 | return perms; | ||
218 | } | ||
219 | |||
220 | } | ||
221 | } | ||
222 | } | ||
223 | |||
224 | public override bool Store(XInventoryItem item) | ||
225 | { | ||
226 | if (!base.Store(item)) | ||
227 | return false; | ||
228 | |||
229 | IncrementFolderVersion(item.parentFolderID); | ||
230 | |||
231 | return true; | ||
232 | } | ||
233 | } | ||
234 | |||
235 | public class PGSQLFolderHandler : PGSQLInventoryHandler<XInventoryFolder> | ||
236 | { | ||
237 | public PGSQLFolderHandler(string c, string t, string m) : | ||
238 | base(c, t, m) | ||
239 | { | ||
240 | } | ||
241 | |||
242 | public bool MoveFolder(string id, string newParentFolderID) | ||
243 | { | ||
244 | XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id }); | ||
245 | |||
246 | if (folders.Length == 0) | ||
247 | return false; | ||
248 | |||
249 | UUID oldParentFolderUUID = folders[0].parentFolderID; | ||
250 | |||
251 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
252 | { | ||
253 | using (NpgsqlCommand cmd = new NpgsqlCommand()) | ||
254 | { | ||
255 | UUID foldID = UUID.Zero; | ||
256 | UUID.TryParse(id, out foldID); | ||
257 | |||
258 | UUID newPar = UUID.Zero; | ||
259 | UUID.TryParse(newParentFolderID, out newPar); | ||
260 | |||
261 | cmd.CommandText = String.Format(@"update {0} set ""parentFolderID"" = :ParentFolderID where ""folderID"" = :folderID", m_Realm); | ||
262 | cmd.Parameters.Add(m_database.CreateParameter("ParentFolderID", newPar)); | ||
263 | cmd.Parameters.Add(m_database.CreateParameter("folderID", foldID)); | ||
264 | cmd.Connection = conn; | ||
265 | conn.Open(); | ||
266 | |||
267 | if (cmd.ExecuteNonQuery() == 0) | ||
268 | return false; | ||
269 | } | ||
270 | } | ||
271 | |||
272 | IncrementFolderVersion(oldParentFolderUUID); | ||
273 | IncrementFolderVersion(newParentFolderID); | ||
274 | |||
275 | return true; | ||
276 | } | ||
277 | |||
278 | public override bool Store(XInventoryFolder folder) | ||
279 | { | ||
280 | if (!base.Store(folder)) | ||
281 | return false; | ||
282 | |||
283 | IncrementFolderVersion(folder.parentFolderID); | ||
284 | |||
285 | return true; | ||
286 | } | ||
287 | } | ||
288 | |||
289 | public class PGSQLInventoryHandler<T> : PGSQLGenericTableHandler<T> where T: class, new() | ||
290 | { | ||
291 | public PGSQLInventoryHandler(string c, string t, string m) : base(c, t, m) {} | ||
292 | |||
293 | protected bool IncrementFolderVersion(UUID folderID) | ||
294 | { | ||
295 | return IncrementFolderVersion(folderID.ToString()); | ||
296 | } | ||
297 | |||
298 | protected bool IncrementFolderVersion(string folderID) | ||
299 | { | ||
300 | // m_log.DebugFormat("[PGSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); | ||
301 | // Util.PrintCallStack(); | ||
302 | |||
303 | string sql = @"update inventoryfolders set version=version+1 where ""folderID"" = :folderID"; | ||
304 | |||
305 | using (NpgsqlConnection conn = new NpgsqlConnection(m_ConnectionString)) | ||
306 | { | ||
307 | using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn)) | ||
308 | { | ||
309 | UUID foldID = UUID.Zero; | ||
310 | UUID.TryParse(folderID, out foldID); | ||
311 | |||
312 | conn.Open(); | ||
313 | |||
314 | cmd.Parameters.Add( m_database.CreateParameter("folderID", foldID) ); | ||
315 | |||
316 | try | ||
317 | { | ||
318 | cmd.ExecuteNonQuery(); | ||
319 | } | ||
320 | catch (Exception) | ||
321 | { | ||
322 | return false; | ||
323 | } | ||
324 | } | ||
325 | } | ||
326 | |||
327 | return true; | ||
328 | } | ||
329 | } | ||
330 | } | ||
diff --git a/OpenSim/Data/PGSQL/Properties/AssemblyInfo.cs b/OpenSim/Data/PGSQL/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..1e88b2c --- /dev/null +++ b/OpenSim/Data/PGSQL/Properties/AssemblyInfo.cs | |||
@@ -0,0 +1,65 @@ | |||
1 | /* | ||
2 | * Copyright (c) Contributors, http://opensimulator.org/ | ||
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions are met: | ||
7 | * * Redistributions of source code must retain the above copyright | ||
8 | * notice, this list of conditions and the following disclaimer. | ||
9 | * * Redistributions in binary form must reproduce the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer in the | ||
11 | * documentation and/or other materials provided with the distribution. | ||
12 | * * Neither the name of the OpenSimulator Project nor the | ||
13 | * names of its contributors may be used to endorse or promote products | ||
14 | * derived from this software without specific prior written permission. | ||
15 | * | ||
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY | ||
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | ||
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | ||
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
26 | */ | ||
27 | |||
28 | using System.Reflection; | ||
29 | using System.Runtime.InteropServices; | ||
30 | |||
31 | // General information about an assembly is controlled through the following | ||
32 | // set of attributes. Change these attribute values to modify the information | ||
33 | // associated with an assembly. | ||
34 | |||
35 | [assembly : AssemblyTitle("OpenSim.Data.PGSQL")] | ||
36 | [assembly : AssemblyDescription("")] | ||
37 | [assembly : AssemblyConfiguration("")] | ||
38 | [assembly : AssemblyCompany("http://opensimulator.org")] | ||
39 | [assembly : AssemblyProduct("OpenSim.Data.PGSQL")] | ||
40 | [assembly : AssemblyCopyright("Copyright (c) OpenSimulator.org Developers 2007-2009")] | ||
41 | [assembly : AssemblyTrademark("")] | ||
42 | [assembly : AssemblyCulture("")] | ||
43 | |||
44 | // Setting ComVisible to false makes the types in this assembly not visible | ||
45 | // to COM components. If you need to access a type in this assembly from | ||
46 | // COM, set the ComVisible attribute to true on that type. | ||
47 | |||
48 | [assembly : ComVisible(false)] | ||
49 | |||
50 | // The following GUID is for the ID of the typelib if this project is exposed to COM | ||
51 | |||
52 | [assembly : Guid("0e1c1ca4-2cf2-4315-b0e7-432c02feea8a")] | ||
53 | |||
54 | // Version information for an assembly consists of the following four values: | ||
55 | // | ||
56 | // Major Version | ||
57 | // Minor Version | ||
58 | // Build Number | ||
59 | // Revision | ||
60 | // | ||
61 | // You can specify all the values or you can default the Revision and Build Numbers | ||
62 | // by using the '*' as shown below: | ||
63 | |||
64 | [assembly : AssemblyVersion("0.8.2.*")] | ||
65 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/AssetStore.migrations b/OpenSim/Data/PGSQL/Resources/AssetStore.migrations new file mode 100644 index 0000000..7a858b4 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/AssetStore.migrations | |||
@@ -0,0 +1,99 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | CREATE TABLE assets ( | ||
4 | "id" varchar(36) NOT NULL PRIMARY KEY, | ||
5 | "name" varchar(64) NOT NULL, | ||
6 | "description" varchar(64) NOT NULL, | ||
7 | "assetType" smallint NOT NULL, | ||
8 | "local" smallint NOT NULL, | ||
9 | "temporary" smallint NOT NULL, | ||
10 | "data" bytea NOT NULL | ||
11 | ) ; | ||
12 | |||
13 | :VERSION 2 | ||
14 | |||
15 | BEGIN TRANSACTION; | ||
16 | |||
17 | CREATE TABLE Tmp_assets | ||
18 | ( | ||
19 | "id" varchar(36) NOT NULL, | ||
20 | "name" varchar(64) NOT NULL, | ||
21 | "description" varchar(64) NOT NULL, | ||
22 | "assetType" smallint NOT NULL, | ||
23 | "local" boolean NOT NULL, | ||
24 | "temporary" boolean NOT NULL, | ||
25 | "data" bytea NOT NULL | ||
26 | ) ; | ||
27 | |||
28 | INSERT INTO Tmp_assets ("id", "name", "description", "assetType", "local", "temporary", "data") | ||
29 | SELECT "id", "name", "description", "assetType", case when "local" = 1 then true else false end, case when "temporary" = 1 then true else false end, "data" | ||
30 | FROM assets ; | ||
31 | |||
32 | DROP TABLE assets; | ||
33 | |||
34 | Alter table Tmp_assets | ||
35 | rename to assets; | ||
36 | |||
37 | ALTER TABLE assets ADD PRIMARY KEY ("id"); | ||
38 | |||
39 | COMMIT; | ||
40 | |||
41 | |||
42 | :VERSION 3 | ||
43 | |||
44 | BEGIN TRANSACTION; | ||
45 | |||
46 | ALTER TABLE assets add "create_time" integer default 0; | ||
47 | ALTER TABLE assets add "access_time" integer default 0; | ||
48 | |||
49 | COMMIT; | ||
50 | |||
51 | |||
52 | :VERSION 4 | ||
53 | |||
54 | BEGIN TRANSACTION; | ||
55 | |||
56 | CREATE TABLE Tmp_assets | ||
57 | ( | ||
58 | "id" uuid NOT NULL, | ||
59 | "name" varchar(64) NOT NULL, | ||
60 | "description" varchar(64) NOT NULL, | ||
61 | "assetType" smallint NOT NULL, | ||
62 | "local" boolean NOT NULL, | ||
63 | "temporary" boolean NOT NULL, | ||
64 | "data" bytea NOT NULL, | ||
65 | "create_time" int NULL, | ||
66 | "access_time" int NULL | ||
67 | ) ; | ||
68 | |||
69 | |||
70 | INSERT INTO Tmp_assets ("id", "name", "description", "assetType", "local", "temporary", "data", "create_time", "access_time") | ||
71 | SELECT cast("id" as uuid), "name", "description", "assetType", "local", "temporary", "data", "create_time", "access_time" | ||
72 | FROM assets ; | ||
73 | |||
74 | DROP TABLE assets; | ||
75 | |||
76 | Alter table Tmp_assets | ||
77 | rename to assets; | ||
78 | |||
79 | ALTER TABLE assets ADD PRIMARY KEY ("id"); | ||
80 | |||
81 | COMMIT; | ||
82 | |||
83 | |||
84 | :VERSION 5 | ||
85 | |||
86 | DELETE FROM assets WHERE "id" = 'dc4b9f0b-d008-45c6-96a4-01dd947ac621'; | ||
87 | |||
88 | :VERSION 6 | ||
89 | |||
90 | ALTER TABLE assets ADD "asset_flags" INTEGER NOT NULL DEFAULT 0; | ||
91 | |||
92 | :VERSION 7 | ||
93 | |||
94 | alter table assets add "creatorid" varchar(36) not null default ''; | ||
95 | |||
96 | :VERSION 8 | ||
97 | |||
98 | BEGIN TRANSACTION; | ||
99 | COMMIT; | ||
diff --git a/OpenSim/Data/PGSQL/Resources/AuthStore.migrations b/OpenSim/Data/PGSQL/Resources/AuthStore.migrations new file mode 100644 index 0000000..a1f5b61 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/AuthStore.migrations | |||
@@ -0,0 +1,32 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE auth ( | ||
6 | uuid uuid NOT NULL default '00000000-0000-0000-0000-000000000000', | ||
7 | "passwordHash" varchar(32) NOT NULL, | ||
8 | "passwordSalt" varchar(32) NOT NULL, | ||
9 | "webLoginKey" varchar(255) NOT NULL, | ||
10 | "accountType" VARCHAR(32) NOT NULL DEFAULT 'UserAccount' | ||
11 | ) ; | ||
12 | |||
13 | CREATE TABLE tokens ( | ||
14 | uuid uuid NOT NULL default '00000000-0000-0000-0000-000000000000', | ||
15 | token varchar(255) NOT NULL, | ||
16 | validity TIMESTAMP NOT NULL ) | ||
17 | ; | ||
18 | |||
19 | COMMIT; | ||
20 | |||
21 | :VERSION 2 | ||
22 | |||
23 | BEGIN TRANSACTION; | ||
24 | |||
25 | INSERT INTO auth (uuid, "passwordHash", "passwordSalt", "webLoginKey", "accountType") | ||
26 | SELECT uuid AS UUID, passwordHash AS passwordHash, passwordSalt AS passwordSalt, webLoginKey AS webLoginKey, 'UserAccount' as accountType | ||
27 | FROM users | ||
28 | where exists ( Select * from information_schema.tables where table_name = 'users' ) | ||
29 | ; | ||
30 | |||
31 | COMMIT; | ||
32 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/Avatar.migrations b/OpenSim/Data/PGSQL/Resources/Avatar.migrations new file mode 100644 index 0000000..160086d --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/Avatar.migrations | |||
@@ -0,0 +1,59 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE Avatars ( | ||
6 | "PrincipalID" uuid NOT NULL PRIMARY KEY, | ||
7 | "Name" varchar(32) NOT NULL, | ||
8 | "Value" varchar(255) NOT NULL DEFAULT '' | ||
9 | ); | ||
10 | |||
11 | |||
12 | COMMIT; | ||
13 | |||
14 | :VERSION 2 | ||
15 | |||
16 | BEGIN TRANSACTION; | ||
17 | |||
18 | CREATE TABLE Tmp_Avatars | ||
19 | ( | ||
20 | "PrincipalID" uuid NOT NULL, | ||
21 | "Name" varchar(32) NOT NULL, | ||
22 | "Value" text NOT NULL DEFAULT '' | ||
23 | ) ; | ||
24 | |||
25 | INSERT INTO Tmp_Avatars ("PrincipalID", "Name", "Value") | ||
26 | SELECT "PrincipalID", cast("Name" as text), "Value" | ||
27 | FROM Avatars ; | ||
28 | |||
29 | DROP TABLE Avatars; | ||
30 | |||
31 | Alter table Tmp_Avatars | ||
32 | rename to Avatars; | ||
33 | |||
34 | COMMIT; | ||
35 | |||
36 | :VERSION 3 | ||
37 | |||
38 | BEGIN TRANSACTION; | ||
39 | |||
40 | CREATE TABLE Tmp_Avatars | ||
41 | ( | ||
42 | "PrincipalID" uuid NOT NULL, | ||
43 | "Name" varchar(32) NOT NULL, | ||
44 | "Value" text NOT NULL DEFAULT '' | ||
45 | ); | ||
46 | |||
47 | ALTER TABLE Tmp_Avatars ADD PRIMARY KEY ("PrincipalID", "Name"); | ||
48 | |||
49 | |||
50 | INSERT INTO Tmp_Avatars ("PrincipalID", "Name", "Value") | ||
51 | SELECT "PrincipalID", "Name", cast("Value" as text) FROM Avatars ; | ||
52 | |||
53 | DROP TABLE Avatars; | ||
54 | |||
55 | Alter table Tmp_Avatars | ||
56 | rename to Avatars; | ||
57 | |||
58 | COMMIT; | ||
59 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/EstateStore.migrations b/OpenSim/Data/PGSQL/Resources/EstateStore.migrations new file mode 100644 index 0000000..59270f8 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/EstateStore.migrations | |||
@@ -0,0 +1,307 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE estate_managers( | ||
6 | "EstateID" int NOT NULL Primary Key, | ||
7 | uuid varchar(36) NOT NULL | ||
8 | ); | ||
9 | |||
10 | CREATE TABLE estate_groups( | ||
11 | "EstateID" int NOT NULL, | ||
12 | uuid varchar(36) NOT NULL | ||
13 | ); | ||
14 | |||
15 | |||
16 | CREATE TABLE estate_users( | ||
17 | "EstateID" int NOT NULL, | ||
18 | uuid varchar(36) NOT NULL | ||
19 | ); | ||
20 | |||
21 | |||
22 | CREATE TABLE estateban( | ||
23 | "EstateID" int NOT NULL, | ||
24 | "bannedUUID" varchar(36) NOT NULL, | ||
25 | "bannedIp" varchar(16) NOT NULL, | ||
26 | "bannedIpHostMask" varchar(16) NOT NULL, | ||
27 | "bannedNameMask" varchar(64) NULL DEFAULT NULL | ||
28 | ); | ||
29 | |||
30 | Create Sequence estate_settings_id increment by 100 start with 100; | ||
31 | |||
32 | CREATE TABLE estate_settings( | ||
33 | "EstateID" integer DEFAULT nextval('estate_settings_id') NOT NULL, | ||
34 | "EstateName" varchar(64) NULL DEFAULT (NULL), | ||
35 | "AbuseEmailToEstateOwner" boolean NOT NULL, | ||
36 | "DenyAnonymous" boolean NOT NULL, | ||
37 | "ResetHomeOnTeleport" boolean NOT NULL, | ||
38 | "FixedSun" boolean NOT NULL, | ||
39 | "DenyTransacted" boolean NOT NULL, | ||
40 | "BlockDwell" boolean NOT NULL, | ||
41 | "DenyIdentified" boolean NOT NULL, | ||
42 | "AllowVoice" boolean NOT NULL, | ||
43 | "UseGlobalTime" boolean NOT NULL, | ||
44 | "PricePerMeter" int NOT NULL, | ||
45 | "TaxFree" boolean NOT NULL, | ||
46 | "AllowDirectTeleport" boolean NOT NULL, | ||
47 | "RedirectGridX" int NOT NULL, | ||
48 | "RedirectGridY" int NOT NULL, | ||
49 | "ParentEstateID" int NOT NULL, | ||
50 | "SunPosition" double precision NOT NULL, | ||
51 | "EstateSkipScripts" boolean NOT NULL, | ||
52 | "BillableFactor" double precision NOT NULL, | ||
53 | "PublicAccess" boolean NOT NULL, | ||
54 | "AbuseEmail" varchar(255) NOT NULL, | ||
55 | "EstateOwner" varchar(36) NOT NULL, | ||
56 | "DenyMinors" boolean NOT NULL | ||
57 | ); | ||
58 | |||
59 | |||
60 | CREATE TABLE estate_map( | ||
61 | "RegionID" varchar(36) NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
62 | "EstateID" int NOT NULL | ||
63 | ); | ||
64 | |||
65 | COMMIT; | ||
66 | |||
67 | :VERSION 2 | ||
68 | |||
69 | BEGIN TRANSACTION; | ||
70 | |||
71 | CREATE INDEX IX_estate_managers ON estate_managers | ||
72 | ( | ||
73 | "EstateID" | ||
74 | ); | ||
75 | |||
76 | |||
77 | CREATE INDEX IX_estate_groups ON estate_groups | ||
78 | ( | ||
79 | "EstateID" | ||
80 | ); | ||
81 | |||
82 | |||
83 | CREATE INDEX IX_estate_users ON estate_users | ||
84 | ( | ||
85 | "EstateID" | ||
86 | ); | ||
87 | |||
88 | COMMIT; | ||
89 | |||
90 | :VERSION 3 | ||
91 | |||
92 | BEGIN TRANSACTION; | ||
93 | |||
94 | CREATE TABLE Tmp_estateban | ||
95 | ( | ||
96 | "EstateID" int NOT NULL, | ||
97 | "bannedUUID" varchar(36) NOT NULL, | ||
98 | "bannedIp" varchar(16) NULL, | ||
99 | "bannedIpHostMask" varchar(16) NULL, | ||
100 | "bannedNameMask" varchar(64) NULL | ||
101 | ); | ||
102 | |||
103 | INSERT INTO Tmp_estateban ("EstateID", "bannedUUID", "bannedIp", "bannedIpHostMask", "bannedNameMask") | ||
104 | SELECT "EstateID", "bannedUUID", "bannedIp", "bannedIpHostMask", "bannedNameMask" FROM estateban; | ||
105 | |||
106 | DROP TABLE estateban; | ||
107 | |||
108 | Alter table Tmp_estateban | ||
109 | rename to estateban; | ||
110 | |||
111 | CREATE INDEX IX_estateban ON estateban | ||
112 | ( | ||
113 | "EstateID" | ||
114 | ); | ||
115 | |||
116 | COMMIT; | ||
117 | |||
118 | |||
119 | :VERSION 4 | ||
120 | |||
121 | BEGIN TRANSACTION; | ||
122 | |||
123 | CREATE TABLE Tmp_estate_managers | ||
124 | ( | ||
125 | "EstateID" int NOT NULL, | ||
126 | uuid uuid NOT NULL | ||
127 | ); | ||
128 | |||
129 | INSERT INTO Tmp_estate_managers ("EstateID", uuid) | ||
130 | SELECT "EstateID", cast(uuid as uuid) FROM estate_managers; | ||
131 | |||
132 | DROP TABLE estate_managers; | ||
133 | |||
134 | Alter table Tmp_estate_managers | ||
135 | rename to estate_managers; | ||
136 | |||
137 | CREATE INDEX IX_estate_managers ON estate_managers | ||
138 | ( | ||
139 | "EstateID" | ||
140 | ); | ||
141 | |||
142 | COMMIT; | ||
143 | |||
144 | |||
145 | :VERSION 5 | ||
146 | |||
147 | BEGIN TRANSACTION; | ||
148 | |||
149 | CREATE TABLE Tmp_estate_groups | ||
150 | ( | ||
151 | "EstateID" int NOT NULL, | ||
152 | uuid uuid NOT NULL | ||
153 | ) ; | ||
154 | |||
155 | INSERT INTO Tmp_estate_groups ("EstateID", uuid) | ||
156 | SELECT "EstateID", cast(uuid as uuid) FROM estate_groups; | ||
157 | |||
158 | DROP TABLE estate_groups; | ||
159 | |||
160 | Alter table Tmp_estate_groups | ||
161 | rename to estate_groups; | ||
162 | |||
163 | CREATE INDEX IX_estate_groups ON estate_groups | ||
164 | ( | ||
165 | "EstateID" | ||
166 | ); | ||
167 | |||
168 | COMMIT; | ||
169 | |||
170 | |||
171 | :VERSION 6 | ||
172 | |||
173 | BEGIN TRANSACTION; | ||
174 | |||
175 | CREATE TABLE Tmp_estate_users | ||
176 | ( | ||
177 | "EstateID" int NOT NULL, | ||
178 | uuid uuid NOT NULL | ||
179 | ); | ||
180 | |||
181 | INSERT INTO Tmp_estate_users ("EstateID", uuid) | ||
182 | SELECT "EstateID", cast(uuid as uuid) FROM estate_users ; | ||
183 | |||
184 | DROP TABLE estate_users; | ||
185 | |||
186 | Alter table Tmp_estate_users | ||
187 | rename to estate_users; | ||
188 | |||
189 | CREATE INDEX IX_estate_users ON estate_users | ||
190 | ( | ||
191 | "EstateID" | ||
192 | ); | ||
193 | |||
194 | COMMIT; | ||
195 | |||
196 | |||
197 | :VERSION 7 | ||
198 | |||
199 | BEGIN TRANSACTION; | ||
200 | |||
201 | CREATE TABLE Tmp_estateban | ||
202 | ( | ||
203 | "EstateID" int NOT NULL, | ||
204 | "bannedUUID" uuid NOT NULL, | ||
205 | "bannedIp" varchar(16) NULL, | ||
206 | "bannedIpHostMask" varchar(16) NULL, | ||
207 | "bannedNameMask" varchar(64) NULL | ||
208 | ); | ||
209 | |||
210 | INSERT INTO Tmp_estateban ("EstateID", "bannedUUID", "bannedIp", "bannedIpHostMask", "bannedNameMask") | ||
211 | SELECT "EstateID", cast("bannedUUID" as uuid), "bannedIp", "bannedIpHostMask", "bannedNameMask" FROM estateban ; | ||
212 | |||
213 | DROP TABLE estateban; | ||
214 | |||
215 | Alter table Tmp_estateban | ||
216 | rename to estateban; | ||
217 | |||
218 | CREATE INDEX IX_estateban ON estateban | ||
219 | ( | ||
220 | "EstateID" | ||
221 | ); | ||
222 | |||
223 | COMMIT; | ||
224 | |||
225 | |||
226 | :VERSION 8 | ||
227 | |||
228 | BEGIN TRANSACTION; | ||
229 | |||
230 | CREATE TABLE Tmp_estate_settings | ||
231 | ( | ||
232 | "EstateID" integer default nextval('estate_settings_id') NOT NULL, | ||
233 | "EstateName" varchar(64) NULL DEFAULT (NULL), | ||
234 | "AbuseEmailToEstateOwner" boolean NOT NULL, | ||
235 | "DenyAnonymous" boolean NOT NULL, | ||
236 | "ResetHomeOnTeleport" boolean NOT NULL, | ||
237 | "FixedSun" boolean NOT NULL, | ||
238 | "DenyTransacted" boolean NOT NULL, | ||
239 | "BlockDwell" boolean NOT NULL, | ||
240 | "DenyIdentified" boolean NOT NULL, | ||
241 | "AllowVoice" boolean NOT NULL, | ||
242 | "UseGlobalTime" boolean NOT NULL, | ||
243 | "PricePerMeter" int NOT NULL, | ||
244 | "TaxFree" boolean NOT NULL, | ||
245 | "AllowDirectTeleport" boolean NOT NULL, | ||
246 | "RedirectGridX" int NOT NULL, | ||
247 | "RedirectGridY" int NOT NULL, | ||
248 | "ParentEstateID" int NOT NULL, | ||
249 | "SunPosition" double precision NOT NULL, | ||
250 | "EstateSkipScripts" boolean NOT NULL, | ||
251 | "BillableFactor" double precision NOT NULL, | ||
252 | "PublicAccess" boolean NOT NULL, | ||
253 | "AbuseEmail" varchar(255) NOT NULL, | ||
254 | "EstateOwner" uuid NOT NULL, | ||
255 | "DenyMinors" boolean NOT NULL | ||
256 | ); | ||
257 | |||
258 | INSERT INTO Tmp_estate_settings ("EstateID", "EstateName", "AbuseEmailToEstateOwner", "DenyAnonymous", "ResetHomeOnTeleport", "FixedSun", "DenyTransacted", "BlockDwell", "DenyIdentified", "AllowVoice", "UseGlobalTime", "PricePerMeter", "TaxFree", "AllowDirectTeleport", "RedirectGridX", "RedirectGridY", "ParentEstateID", "SunPosition", "EstateSkipScripts", "BillableFactor", "PublicAccess", "AbuseEmail", "EstateOwner", "DenyMinors") | ||
259 | SELECT "EstateID", "EstateName", "AbuseEmailToEstateOwner", "DenyAnonymous", "ResetHomeOnTeleport", "FixedSun", "DenyTransacted", "BlockDwell", "DenyIdentified", "AllowVoice", "UseGlobalTime", "PricePerMeter", "TaxFree", "AllowDirectTeleport", "RedirectGridX", "RedirectGridY", "ParentEstateID", "SunPosition", "EstateSkipScripts", "BillableFactor", "PublicAccess", "AbuseEmail", cast("EstateOwner" as uuid), "DenyMinors" FROM estate_settings ; | ||
260 | |||
261 | DROP TABLE estate_settings; | ||
262 | |||
263 | |||
264 | Alter table Tmp_estate_settings | ||
265 | rename to estate_settings; | ||
266 | |||
267 | |||
268 | Create index on estate_settings (lower("EstateName")); | ||
269 | |||
270 | COMMIT; | ||
271 | |||
272 | |||
273 | :VERSION 9 | ||
274 | |||
275 | BEGIN TRANSACTION; | ||
276 | |||
277 | CREATE TABLE Tmp_estate_map | ||
278 | ( | ||
279 | "RegionID" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
280 | "EstateID" int NOT NULL | ||
281 | ); | ||
282 | |||
283 | INSERT INTO Tmp_estate_map ("RegionID", "EstateID") | ||
284 | SELECT cast("RegionID" as uuid), "EstateID" FROM estate_map ; | ||
285 | |||
286 | DROP TABLE estate_map; | ||
287 | |||
288 | Alter table Tmp_estate_map | ||
289 | rename to estate_map; | ||
290 | |||
291 | COMMIT; | ||
292 | |||
293 | :VERSION 10 | ||
294 | |||
295 | BEGIN TRANSACTION; | ||
296 | ALTER TABLE estate_settings ADD COLUMN "AllowLandmark" boolean NOT NULL default true; | ||
297 | ALTER TABLE estate_settings ADD COLUMN "AllowParcelChanges" boolean NOT NULL default true; | ||
298 | ALTER TABLE estate_settings ADD COLUMN "AllowSetHome" boolean NOT NULL default true; | ||
299 | COMMIT; | ||
300 | |||
301 | :VERSION 11 | ||
302 | |||
303 | Begin transaction; | ||
304 | |||
305 | |||
306 | Commit; | ||
307 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/FriendsStore.migrations b/OpenSim/Data/PGSQL/Resources/FriendsStore.migrations new file mode 100644 index 0000000..a87199b --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/FriendsStore.migrations | |||
@@ -0,0 +1,44 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE Friends ( | ||
6 | "PrincipalID" uuid NOT NULL, | ||
7 | "Friend" varchar(255) NOT NULL, | ||
8 | "Flags" char(16) NOT NULL DEFAULT '0', | ||
9 | "Offered" varchar(32) NOT NULL DEFAULT 0); | ||
10 | |||
11 | |||
12 | COMMIT; | ||
13 | |||
14 | :VERSION 2 | ||
15 | |||
16 | BEGIN TRANSACTION; | ||
17 | |||
18 | INSERT INTO Friends ("PrincipalID", "Friend", "Flags", "Offered") | ||
19 | SELECT "ownerID", "friendID", "friendPerms", 0 FROM userfriends; | ||
20 | |||
21 | COMMIT; | ||
22 | |||
23 | :VERSION 3 | ||
24 | |||
25 | BEGIN TRANSACTION; | ||
26 | |||
27 | CREATE TABLE Tmp_Friends | ||
28 | ("PrincipalID" varchar(255) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
29 | "Friend" varchar(255) NOT NULL, | ||
30 | "Flags" char(16) NOT NULL DEFAULT '0', | ||
31 | "Offered" varchar(32) NOT NULL DEFAULT 0) ; | ||
32 | |||
33 | INSERT INTO Tmp_Friends ("PrincipalID", "Friend", "Flags", "Offered") | ||
34 | SELECT cast("PrincipalID" as varchar(255)), "Friend", "Flags", "Offered" FROM Friends ; | ||
35 | |||
36 | DROP TABLE Friends; | ||
37 | |||
38 | Alter table Tmp_Friends | ||
39 | rename to Friends; | ||
40 | |||
41 | ALTER TABLE Friends ADD PRIMARY KEY("PrincipalID", "Friend"); | ||
42 | |||
43 | |||
44 | COMMIT; | ||
diff --git a/OpenSim/Data/PGSQL/Resources/GridStore.migrations b/OpenSim/Data/PGSQL/Resources/GridStore.migrations new file mode 100644 index 0000000..0ab8d2b --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/GridStore.migrations | |||
@@ -0,0 +1,242 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE regions( | ||
6 | "regionHandle" varchar(255) NULL, | ||
7 | "regionName" varchar(255) NULL, | ||
8 | uuid varchar(255) NOT NULL PRIMARY KEY, | ||
9 | "regionRecvKey" varchar(255) NULL, | ||
10 | "regionSecret" varchar(255) NULL, | ||
11 | "regionSendKey" varchar(255) NULL, | ||
12 | "regionDataURI" varchar(255) NULL, | ||
13 | "serverIP" varchar(255) NULL, | ||
14 | "serverPort" varchar(255) NULL, | ||
15 | "serverURI" varchar(255) NULL, | ||
16 | "locX" varchar(255) NULL, | ||
17 | "locY" varchar(255) NULL, | ||
18 | "locZ" varchar(255) NULL, | ||
19 | "eastOverrideHandle" varchar(255) NULL, | ||
20 | "westOverrideHandle" varchar(255) NULL, | ||
21 | "southOverrideHandle" varchar(255) NULL, | ||
22 | "northOverrideHandle" varchar(255) NULL, | ||
23 | "regionAssetURI" varchar(255) NULL, | ||
24 | "regionAssetRecvKey" varchar(255) NULL, | ||
25 | "regionAssetSendKey" varchar(255) NULL, | ||
26 | "regionUserURI" varchar(255) NULL, | ||
27 | "regionUserRecvKey" varchar(255) NULL, | ||
28 | "regionUserSendKey" varchar(255) NULL, | ||
29 | "regionMapTexture" varchar(255) NULL, | ||
30 | "serverHttpPort" varchar(255) NULL, | ||
31 | "serverRemotingPort" varchar(255) NULL, | ||
32 | "owner_uuid" varchar(36) NULL | ||
33 | ); | ||
34 | |||
35 | COMMIT; | ||
36 | |||
37 | |||
38 | :VERSION 2 | ||
39 | |||
40 | BEGIN TRANSACTION; | ||
41 | |||
42 | CREATE TABLE Tmp_regions | ||
43 | ( | ||
44 | uuid varchar(36) NOT NULL, | ||
45 | "regionHandle" bigint NULL, | ||
46 | "regionName" varchar(20) NULL, | ||
47 | "regionRecvKey" varchar(128) NULL, | ||
48 | "regionSendKey" varchar(128) NULL, | ||
49 | "regionSecret" varchar(128) NULL, | ||
50 | "regionDataURI" varchar(128) NULL, | ||
51 | "serverIP" varchar(64) NULL, | ||
52 | "serverPort" int NULL, | ||
53 | "serverURI" varchar(255) NULL, | ||
54 | "locX" int NULL, | ||
55 | "locY" int NULL, | ||
56 | "locZ" int NULL, | ||
57 | "eastOverrideHandle" bigint NULL, | ||
58 | "westOverrideHandle" bigint NULL, | ||
59 | "southOverrideHandle" bigint NULL, | ||
60 | "northOverrideHandle" bigint NULL, | ||
61 | "regionAssetURI" varchar(255) NULL, | ||
62 | "regionAssetRecvKey" varchar(128) NULL, | ||
63 | "regionAssetSendKey" varchar(128) NULL, | ||
64 | "regionUserURI" varchar(255) NULL, | ||
65 | "regionUserRecvKey" varchar(128) NULL, | ||
66 | "regionUserSendKey" varchar(128) NULL, | ||
67 | "regionMapTexture" varchar(36) NULL, | ||
68 | "serverHttpPort" int NULL, | ||
69 | "serverRemotingPort" int NULL, | ||
70 | "owner_uuid" varchar(36) NULL, | ||
71 | "originUUID" varchar(36) NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000') | ||
72 | ); | ||
73 | |||
74 | INSERT INTO Tmp_regions (uuid, "regionHandle", "regionName", "regionRecvKey", "regionSendKey", "regionSecret", "regionDataURI", "serverIP", "serverPort", "serverURI", "locX", "locY", "locZ", "eastOverrideHandle", "westOverrideHandle", "southOverrideHandle", "northOverrideHandle", "regionAssetURI", "regionAssetRecvKey", "regionAssetSendKey", "regionUserURI", "regionUserRecvKey", "regionUserSendKey", "regionMapTexture", "serverHttpPort", "serverRemotingPort", "owner_uuid") | ||
75 | SELECT cast(uuid as varchar(36)), cast("regionHandle" as bigint), cast("regionName" as varchar(20)), cast("regionRecvKey" as varchar(128)), cast("regionSendKey" as varchar(128)), cast("regionSecret" as varchar(128)), cast("regionDataURI" as varchar(128)), cast("serverIP" as varchar(64)), cast("serverPort" as int), "serverURI", cast("locX" as int), cast("locY" as int), cast("locZ" as int), cast("eastOverrideHandle" as bigint), cast("westOverrideHandle" as bigint), | ||
76 | cast("southOverrideHandle" as bigint), cast("northOverrideHandle" as bigint), "regionAssetURI", cast("regionAssetRecvKey" as varchar(128)), cast("regionAssetSendKey" as varchar(128)), "regionUserURI", cast("regionUserRecvKey" as varchar(128)), cast("regionUserSendKey" as varchar(128)), cast("regionMapTexture" as varchar(36)), | ||
77 | cast("serverHttpPort" as int), cast("serverRemotingPort" as int), "owner_uuid" | ||
78 | FROM regions; | ||
79 | |||
80 | DROP TABLE regions; | ||
81 | |||
82 | alter table Tmp_regions | ||
83 | rename to regions; | ||
84 | |||
85 | COMMIT; | ||
86 | |||
87 | :VERSION 3 | ||
88 | |||
89 | BEGIN TRANSACTION; | ||
90 | |||
91 | CREATE INDEX IX_regions_name ON regions | ||
92 | ( | ||
93 | "regionName" | ||
94 | ); | ||
95 | |||
96 | CREATE INDEX IX_regions_handle ON regions | ||
97 | ( | ||
98 | "regionHandle" | ||
99 | ); | ||
100 | |||
101 | |||
102 | CREATE INDEX IX_regions_override ON regions | ||
103 | ( | ||
104 | "eastOverrideHandle", | ||
105 | "westOverrideHandle", | ||
106 | "southOverrideHandle", | ||
107 | "northOverrideHandle" | ||
108 | ); | ||
109 | |||
110 | COMMIT; | ||
111 | |||
112 | |||
113 | :VERSION 4 | ||
114 | |||
115 | /* To prevent any potential data loss issues, you should review this script in detail before running it outside the cotext of the database designer.*/ | ||
116 | BEGIN TRANSACTION; | ||
117 | |||
118 | CREATE TABLE Tmp_regions | ||
119 | ( | ||
120 | uuid uuid NOT NULL, | ||
121 | "regionHandle" bigint NULL, | ||
122 | "regionName" varchar(20) NULL, | ||
123 | "regionRecvKey" varchar(128) NULL, | ||
124 | "regionSendKey" varchar(128) NULL, | ||
125 | "regionSecret" varchar(128) NULL, | ||
126 | "regionDataURI" varchar(128) NULL, | ||
127 | "serverIP" varchar(64) NULL, | ||
128 | "serverPort" int NULL, | ||
129 | "serverURI" varchar(255) NULL, | ||
130 | "locX" int NULL, | ||
131 | "locY" int NULL, | ||
132 | "locZ" int NULL, | ||
133 | "eastOverrideHandle" bigint NULL, | ||
134 | "westOverrideHandle" bigint NULL, | ||
135 | "southOverrideHandle" bigint NULL, | ||
136 | "northOverrideHandle" bigint NULL, | ||
137 | "regionAssetURI" varchar(255) NULL, | ||
138 | "regionAssetRecvKey" varchar(128) NULL, | ||
139 | "regionAssetSendKey" varchar(128) NULL, | ||
140 | "regionUserURI" varchar(255) NULL, | ||
141 | "regionUserRecvKey" varchar(128) NULL, | ||
142 | "regionUserSendKey" varchar(128) NULL, | ||
143 | "regionMapTexture" uuid NULL, | ||
144 | "serverHttpPort" int NULL, | ||
145 | "serverRemotingPort" int NULL, | ||
146 | "owner_uuid" uuid NOT NULL, | ||
147 | "originUUID" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000') | ||
148 | ); | ||
149 | |||
150 | |||
151 | INSERT INTO Tmp_regions (uuid, "regionHandle", "regionName", "regionRecvKey", "regionSendKey", "regionSecret", "regionDataURI", "serverIP", "serverPort", "serverURI", "locX", "locY", "locZ", "eastOverrideHandle", "westOverrideHandle", "southOverrideHandle", "northOverrideHandle", "regionAssetURI", "regionAssetRecvKey", "regionAssetSendKey", "regionUserURI", "regionUserRecvKey", "regionUserSendKey", "regionMapTexture", "serverHttpPort", "serverRemotingPort", "owner_uuid", "originUUID") | ||
152 | SELECT cast(uuid as uuid), "regionHandle", "regionName", "regionRecvKey", "regionSendKey", "regionSecret", "regionDataURI", "serverIP", "serverPort", "serverURI", "locX", "locY", "locZ", "eastOverrideHandle", "westOverrideHandle", "southOverrideHandle", "northOverrideHandle", "regionAssetURI", "regionAssetRecvKey", "regionAssetSendKey", "regionUserURI", "regionUserRecvKey", "regionUserSendKey", cast("regionMapTexture" as uuid), "serverHttpPort", "serverRemotingPort", cast( "owner_uuid" as uuid), cast("originUUID" as uuid) FROM regions ; | ||
153 | |||
154 | |||
155 | DROP TABLE regions; | ||
156 | |||
157 | alter table Tmp_regions rename to regions; | ||
158 | |||
159 | ALTER TABLE regions ADD CONSTRAINT | ||
160 | PK__regions__uuid PRIMARY KEY | ||
161 | ( | ||
162 | uuid | ||
163 | ); | ||
164 | |||
165 | CREATE INDEX IX_regions_name ON regions | ||
166 | ( | ||
167 | "regionName" | ||
168 | ); | ||
169 | |||
170 | CREATE INDEX IX_regions_handle ON regions | ||
171 | ( | ||
172 | "regionHandle" | ||
173 | ); | ||
174 | |||
175 | CREATE INDEX IX_regions_override ON regions | ||
176 | ( | ||
177 | "eastOverrideHandle", | ||
178 | "westOverrideHandle", | ||
179 | "southOverrideHandle", | ||
180 | "northOverrideHandle" | ||
181 | ); | ||
182 | |||
183 | COMMIT; | ||
184 | |||
185 | |||
186 | :VERSION 5 | ||
187 | |||
188 | BEGIN TRANSACTION; | ||
189 | |||
190 | ALTER TABLE regions ADD access int default 0; | ||
191 | |||
192 | COMMIT; | ||
193 | |||
194 | |||
195 | :VERSION 6 | ||
196 | |||
197 | BEGIN TRANSACTION; | ||
198 | |||
199 | ALTER TABLE regions ADD "ScopeID" uuid default '00000000-0000-0000-0000-000000000000'; | ||
200 | ALTER TABLE regions alter column "owner_uuid" set DEFAULT ('00000000-0000-0000-0000-000000000000'); | ||
201 | ALTER TABLE regions ADD "sizeX" integer not null default 0; | ||
202 | ALTER TABLE regions ADD "sizeY" integer not null default 0; | ||
203 | |||
204 | COMMIT; | ||
205 | |||
206 | |||
207 | :VERSION 7 | ||
208 | |||
209 | BEGIN TRANSACTION; | ||
210 | |||
211 | ALTER TABLE regions ADD "flags" integer NOT NULL DEFAULT 0; | ||
212 | CREATE INDEX flags ON regions("flags"); | ||
213 | ALTER TABLE regions ADD "last_seen" integer NOT NULL DEFAULT 0; | ||
214 | ALTER TABLE regions ADD "PrincipalID" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; | ||
215 | ALTER TABLE regions ADD "Token" varchar(255) NOT NULL DEFAULT 0; | ||
216 | |||
217 | COMMIT; | ||
218 | |||
219 | :VERSION 8 | ||
220 | |||
221 | BEGIN TRANSACTION; | ||
222 | ALTER TABLE regions ALTER COLUMN "regionName" type VarChar(128) ; | ||
223 | |||
224 | DROP INDEX IX_regions_name; | ||
225 | ALTER TABLE regions ALTER COLUMN "regionName" type VarChar(128), | ||
226 | ALTER COLUMN "regionName" SET NOT NULL; | ||
227 | |||
228 | CREATE INDEX IX_regions_name ON regions | ||
229 | ( | ||
230 | "regionName" | ||
231 | ); | ||
232 | |||
233 | COMMIT; | ||
234 | |||
235 | :VERSION 9 | ||
236 | |||
237 | BEGIN TRANSACTION; | ||
238 | |||
239 | ALTER TABLE regions ADD "parcelMapTexture" uuid NULL; | ||
240 | |||
241 | COMMIT; | ||
242 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/GridUserStore.migrations b/OpenSim/Data/PGSQL/Resources/GridUserStore.migrations new file mode 100644 index 0000000..d37c4f6d --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/GridUserStore.migrations | |||
@@ -0,0 +1,60 @@ | |||
1 | :VERSION 1 # -------------------------- | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE GridUser ( | ||
6 | "UserID" VARCHAR(255) NOT NULL Primary Key, | ||
7 | "HomeRegionID" CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
8 | "HomePosition" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
9 | "HomeLookAt" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
10 | "LastRegionID" CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
11 | "LastPosition" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
12 | "LastLookAt" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
13 | "Online" CHAR(5) NOT NULL DEFAULT 'false', | ||
14 | "Login" CHAR(16) NOT NULL DEFAULT '0', | ||
15 | "Logout" CHAR(16) NOT NULL DEFAULT '0' | ||
16 | ) ; | ||
17 | |||
18 | COMMIT; | ||
19 | |||
20 | :VERSION 2 # -------------------------- | ||
21 | |||
22 | BEGIN TRANSACTION; | ||
23 | |||
24 | CREATE TABLE GridUser_tmp ( | ||
25 | "UserID" VARCHAR(255) NOT NULL PRIMARY KEY, | ||
26 | "HomeRegionID" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
27 | "HomePosition" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
28 | "HomeLookAt" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
29 | "LastRegionID" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
30 | "LastPosition" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
31 | "LastLookAt" CHAR(64) NOT NULL DEFAULT '<0,0,0>', | ||
32 | "Online" CHAR(5) NOT NULL DEFAULT 'false', | ||
33 | "Login" CHAR(16) NOT NULL DEFAULT '0', | ||
34 | "Logout" CHAR(16) NOT NULL DEFAULT '0' | ||
35 | ); | ||
36 | |||
37 | COMMIT; | ||
38 | |||
39 | |||
40 | INSERT INTO GridUser_tmp ("UserID" | ||
41 | ,"HomeRegionID" | ||
42 | ,"HomePosition" | ||
43 | ,"HomeLookAt" | ||
44 | ,"LastRegionID" | ||
45 | ,"LastPosition" | ||
46 | ,"LastLookAt" | ||
47 | ,"Online" | ||
48 | ,"Login" | ||
49 | ,"Logout") | ||
50 | SELECT "UserID", cast("HomeRegionID" as uuid), "HomePosition" ,"HomeLookAt" , cast("LastRegionID" as uuid), | ||
51 | "LastPosition" | ||
52 | ,"LastLookAt" | ||
53 | ,"Online" | ||
54 | ,"Login" | ||
55 | ,"Logout" FROM GridUser; | ||
56 | |||
57 | DROP TABLE GridUser; | ||
58 | |||
59 | alter table GridUser_tmp rename to GridUser; | ||
60 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/HGTravelStore.migrations b/OpenSim/Data/PGSQL/Resources/HGTravelStore.migrations new file mode 100644 index 0000000..adf126d --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/HGTravelStore.migrations | |||
@@ -0,0 +1,17 @@ | |||
1 | :VERSION 1 # -------------------------- | ||
2 | |||
3 | BEGIN; | ||
4 | |||
5 | CREATE TABLE hg_traveling_data ( | ||
6 | "SessionID" VARCHAR(36) NOT NULL Primary Key, | ||
7 | "UserID" VARCHAR(36) NOT NULL, | ||
8 | "GridExternalName" VARCHAR(255) NOT NULL DEFAULT '', | ||
9 | "ServiceToken" VARCHAR(255) NOT NULL DEFAULT '', | ||
10 | "ClientIPAddress" VARCHAR(16) NOT NULL DEFAULT '', | ||
11 | "MyIPAddress" VARCHAR(16) NOT NULL DEFAULT '', | ||
12 | "TMStamp" timestamp NOT NULL default now() | ||
13 | ); | ||
14 | |||
15 | |||
16 | COMMIT; | ||
17 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/IM_Store.migrations b/OpenSim/Data/PGSQL/Resources/IM_Store.migrations new file mode 100644 index 0000000..eb97824 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/IM_Store.migrations | |||
@@ -0,0 +1,45 @@ | |||
1 | :VERSION 1 # -------------------------- | ||
2 | |||
3 | BEGIN Transaction; | ||
4 | |||
5 | Create Sequence im_offiline_id increment by 1 start with 1; | ||
6 | |||
7 | CREATE TABLE im_offline ( | ||
8 | "ID" integer PRIMARY KEY NOT NULL DEFAULT nextval('im_offiline_id') , | ||
9 | "PrincipalID" char(36) NOT NULL default '', | ||
10 | "Message" text NOT NULL, | ||
11 | "TMStamp" timestamp NOT NULL default now() | ||
12 | ); | ||
13 | |||
14 | COMMIT; | ||
15 | |||
16 | :VERSION 2 # -------------------------- | ||
17 | |||
18 | BEGIN; | ||
19 | |||
20 | /* | ||
21 | INSERT INTO `im_offline` SELECT * from `diva_im_offline`; | ||
22 | DROP TABLE `diva_im_offline`; | ||
23 | DELETE FROM `migrations` WHERE name='diva_im_Store'; | ||
24 | */ | ||
25 | |||
26 | COMMIT; | ||
27 | |||
28 | :VERSION 3 # -------------------------- | ||
29 | |||
30 | BEGIN; | ||
31 | |||
32 | -- dropping the table here as there most likely is only one record in the table at the time of migration | ||
33 | |||
34 | DROP TABLE IF EXISTS "public"."im_offline"; | ||
35 | CREATE TABLE "public"."im_offline" ( | ||
36 | "ID" serial, | ||
37 | "PrincipalID" uuid NOT NULL, | ||
38 | "Message" text NOT NULL COLLATE "default", | ||
39 | "TMStamp" timestamp(6) NOT NULL DEFAULT clock_timestamp(), | ||
40 | "FromID" uuid NOT NULL | ||
41 | ) | ||
42 | WITH (OIDS=FALSE); | ||
43 | ALTER TABLE "public"."im_offline" ADD PRIMARY KEY ("ID","PrincipalID","FromID") NOT DEFERRABLE INITIALLY IMMEDIATE; | ||
44 | |||
45 | COMMIT; \ No newline at end of file | ||
diff --git a/OpenSim/Data/PGSQL/Resources/InventoryStore.migrations b/OpenSim/Data/PGSQL/Resources/InventoryStore.migrations new file mode 100644 index 0000000..8f7982a --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/InventoryStore.migrations | |||
@@ -0,0 +1,220 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE inventoryfolders ( | ||
6 | "folderID" varchar(36) NOT NULL default '' PRIMARY KEY, | ||
7 | "agentID" varchar(36) default NULL, | ||
8 | "parentFolderID" varchar(36) default NULL, | ||
9 | "folderName" varchar(64) default NULL, | ||
10 | "type" smallint NOT NULL default 0, | ||
11 | "version" int NOT NULL default 0 | ||
12 | ); | ||
13 | |||
14 | |||
15 | CREATE INDEX owner ON inventoryfolders | ||
16 | ( | ||
17 | "agentID" ASC | ||
18 | ); | ||
19 | |||
20 | CREATE INDEX parent ON inventoryfolders | ||
21 | ( | ||
22 | "parentFolderID" ASC | ||
23 | ); | ||
24 | |||
25 | |||
26 | CREATE TABLE inventoryitems ( | ||
27 | "inventoryID" varchar(36) NOT NULL default '' Primary Key, | ||
28 | "assetID" varchar(36) default NULL, | ||
29 | "assetType" int default NULL, | ||
30 | "parentFolderID" varchar(36) default NULL, | ||
31 | "avatarID" varchar(36) default NULL, | ||
32 | "inventoryName" varchar(64) default NULL, | ||
33 | "inventoryDescription" varchar(128) default NULL, | ||
34 | "inventoryNextPermissions" int default NULL, | ||
35 | "inventoryCurrentPermissions" int default NULL, | ||
36 | "invType" int default NULL, | ||
37 | "creatorID" varchar(36) default NULL, | ||
38 | "inventoryBasePermissions" int NOT NULL default 0, | ||
39 | "inventoryEveryOnePermissions" int NOT NULL default 0, | ||
40 | "salePrice" int default NULL, | ||
41 | "saleType" smallint default NULL, | ||
42 | "creationDate" int default NULL, | ||
43 | "groupID" varchar(36) default NULL, | ||
44 | "groupOwned" boolean default NULL, | ||
45 | "flags" int default NULL | ||
46 | ); | ||
47 | |||
48 | |||
49 | CREATE INDEX ii_owner ON inventoryitems | ||
50 | ( | ||
51 | "avatarID" ASC | ||
52 | ); | ||
53 | |||
54 | CREATE INDEX ii_folder ON inventoryitems | ||
55 | ( | ||
56 | "parentFolderID" ASC | ||
57 | ); | ||
58 | |||
59 | COMMIT; | ||
60 | |||
61 | |||
62 | :VERSION 2 | ||
63 | |||
64 | BEGIN TRANSACTION; | ||
65 | |||
66 | ALTER TABLE inventoryitems ADD "inventoryGroupPermissions" INTEGER NOT NULL default 0; | ||
67 | |||
68 | COMMIT; | ||
69 | |||
70 | :VERSION 3 | ||
71 | |||
72 | /* To prevent any potential data loss issues, you should review this script in detail before running it outside the cotext of the database designer.*/ | ||
73 | BEGIN TRANSACTION; | ||
74 | |||
75 | CREATE TABLE Tmp_inventoryfolders | ||
76 | ( | ||
77 | "folderID" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
78 | "agentID" uuid NULL DEFAULT (NULL), | ||
79 | "parentFolderID" uuid NULL DEFAULT (NULL), | ||
80 | "folderName" varchar(64) NULL DEFAULT (NULL), | ||
81 | "type" smallint NOT NULL DEFAULT ((0)), | ||
82 | "version" int NOT NULL DEFAULT ((0)) | ||
83 | ); | ||
84 | |||
85 | INSERT INTO Tmp_inventoryfolders ("folderID", "agentID", "parentFolderID", "folderName", type, version) | ||
86 | SELECT cast("folderID" as uuid), cast("agentID" as uuid), cast("parentFolderID" as uuid), "folderName", "type", "version" | ||
87 | FROM inventoryfolders; | ||
88 | |||
89 | DROP TABLE inventoryfolders; | ||
90 | |||
91 | alter table Tmp_inventoryfolders rename to inventoryfolders; | ||
92 | |||
93 | ALTER TABLE inventoryfolders ADD CONSTRAINT | ||
94 | PK__inventor__C2FABFB3173876EA PRIMARY KEY | ||
95 | ( | ||
96 | "folderID" | ||
97 | ); | ||
98 | |||
99 | CREATE INDEX owner ON inventoryfolders | ||
100 | ( | ||
101 | "agentID" | ||
102 | ); | ||
103 | |||
104 | CREATE INDEX parent ON inventoryfolders | ||
105 | ( | ||
106 | "parentFolderID" | ||
107 | ); | ||
108 | |||
109 | COMMIT; | ||
110 | |||
111 | |||
112 | :VERSION 4 | ||
113 | |||
114 | BEGIN TRANSACTION; | ||
115 | |||
116 | CREATE TABLE Tmp_inventoryitems | ||
117 | ( | ||
118 | "inventoryID" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
119 | "assetID" uuid NULL DEFAULT (NULL), | ||
120 | "assetType" int NULL DEFAULT (NULL), | ||
121 | "parentFolderID" uuid NULL DEFAULT (NULL), | ||
122 | "avatarID" uuid NULL DEFAULT (NULL), | ||
123 | "inventoryName" varchar(64) NULL DEFAULT (NULL), | ||
124 | "inventoryDescription" varchar(128) NULL DEFAULT (NULL), | ||
125 | "inventoryNextPermissions" int NULL DEFAULT (NULL), | ||
126 | "inventoryCurrentPermissions" int NULL DEFAULT (NULL), | ||
127 | "invType" int NULL DEFAULT (NULL), | ||
128 | "creatorID" uuid NULL DEFAULT (NULL), | ||
129 | "inventoryBasePermissions" int NOT NULL DEFAULT ((0)), | ||
130 | "inventoryEveryOnePermissions" int NOT NULL DEFAULT ((0)), | ||
131 | "salePrice" int NULL DEFAULT (NULL), | ||
132 | "SaleType" smallint NULL DEFAULT (NULL), | ||
133 | "creationDate" int NULL DEFAULT (NULL), | ||
134 | "groupID" uuid NULL DEFAULT (NULL), | ||
135 | "groupOwned" boolean NULL DEFAULT (NULL), | ||
136 | "flags" int NULL DEFAULT (NULL), | ||
137 | "inventoryGroupPermissions" int NOT NULL DEFAULT ((0)) | ||
138 | ); | ||
139 | |||
140 | |||
141 | INSERT INTO Tmp_inventoryitems ("inventoryID", "assetID", "assetType", "parentFolderID", "avatarID", "inventoryName", "inventoryDescription", "inventoryNextPermissions", "inventoryCurrentPermissions", "invType", "creatorID", "inventoryBasePermissions", "inventoryEveryOnePermissions", "salePrice", "SaleType", "creationDate", "groupID", "groupOwned", "flags", "inventoryGroupPermissions") | ||
142 | SELECT cast("inventoryID" as uuid), cast("assetID" as uuid), "assetType", cast("parentFolderID" as uuid), cast("avatarID" as uuid), "inventoryName", "inventoryDescription", "inventoryNextPermissions", "inventoryCurrentPermissions", "invType", cast("creatorID" as uuid), "inventoryBasePermissions", "inventoryEveryOnePermissions", "salePrice", "SaleType", "creationDate", cast("groupID" as uuid), "groupOwned", "flags", "inventoryGroupPermissions" | ||
143 | FROM inventoryitems ; | ||
144 | |||
145 | DROP TABLE inventoryitems; | ||
146 | |||
147 | alter table Tmp_inventoryitems rename to inventoryitems; | ||
148 | |||
149 | ALTER TABLE inventoryitems ADD CONSTRAINT | ||
150 | PK__inventor__C4B7BC2220C1E124 PRIMARY KEY | ||
151 | ( | ||
152 | "inventoryID" | ||
153 | ); | ||
154 | |||
155 | |||
156 | CREATE INDEX ii2_owner ON inventoryitems | ||
157 | ( | ||
158 | "avatarID" | ||
159 | ); | ||
160 | |||
161 | CREATE INDEX ii2_folder ON inventoryitems | ||
162 | ( | ||
163 | "parentFolderID" | ||
164 | ); | ||
165 | |||
166 | COMMIT; | ||
167 | |||
168 | :VERSION 5 | ||
169 | |||
170 | |||
171 | BEGIN TRANSACTION; | ||
172 | |||
173 | -- # Restoring defaults: | ||
174 | -- # NOTE: "inventoryID" does NOT need one: it's NOT NULL PK and a unique Guid must be provided every time anyway! | ||
175 | |||
176 | alter table inventoryitems | ||
177 | alter column "inventoryBasePermissions" set default 0; | ||
178 | alter table inventoryitems | ||
179 | alter column "inventoryEveryOnePermissions" set default 0; | ||
180 | alter table inventoryitems | ||
181 | alter column "inventoryGroupPermissions" set default 0 ; | ||
182 | |||
183 | COMMIT ; | ||
184 | |||
185 | :VERSION 7 | ||
186 | |||
187 | BEGIN TRANSACTION; | ||
188 | |||
189 | -- # "creatorID" goes back to VARCHAR(36) (???) | ||
190 | |||
191 | alter table inventoryitems | ||
192 | alter column "creatorID" type varchar(36); | ||
193 | |||
194 | COMMIT ; | ||
195 | |||
196 | :VERSION 8 | ||
197 | |||
198 | ALTER TABLE inventoryitems | ||
199 | alter column "creatorID" set DEFAULT '00000000-0000-0000-0000-000000000000'; | ||
200 | |||
201 | |||
202 | :VERSION 9 | ||
203 | |||
204 | BEGIN TRANSACTION; | ||
205 | |||
206 | --# "creatorID" goes up to VARCHAR(255) | ||
207 | |||
208 | alter table inventoryitems | ||
209 | alter column "creatorID" type varchar(255); | ||
210 | |||
211 | Commit; | ||
212 | |||
213 | :VERSION 10 | ||
214 | |||
215 | BEGIN TRANSACTION; | ||
216 | |||
217 | Alter table inventoryitems Rename Column "SaleType" to "saleType"; | ||
218 | |||
219 | Commit; | ||
220 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/LogStore.migrations b/OpenSim/Data/PGSQL/Resources/LogStore.migrations new file mode 100644 index 0000000..83727c6 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/LogStore.migrations | |||
@@ -0,0 +1,16 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE logs ( | ||
6 | "logID" int NOT NULL Primary Key, | ||
7 | "target" varchar(36) default NULL, | ||
8 | "server" varchar(64) default NULL, | ||
9 | "method" varchar(64) default NULL, | ||
10 | "arguments" varchar(255) default NULL, | ||
11 | "priority" int default NULL, | ||
12 | "message" text | ||
13 | ); | ||
14 | |||
15 | COMMIT; | ||
16 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/Presence.migrations b/OpenSim/Data/PGSQL/Resources/Presence.migrations new file mode 100755 index 0000000..5184034 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/Presence.migrations | |||
@@ -0,0 +1,42 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | BEGIN TRANSACTION; | ||
4 | |||
5 | CREATE TABLE Presence ( | ||
6 | "UserID" varchar(255) NOT NULL, | ||
7 | "RegionID" uuid NOT NULL, | ||
8 | "SessionID" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000', | ||
9 | "SecureSessionID" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000' | ||
10 | ); | ||
11 | |||
12 | |||
13 | COMMIT; | ||
14 | |||
15 | :VERSION 2 | ||
16 | |||
17 | BEGIN TRANSACTION; | ||
18 | |||
19 | CREATE UNIQUE INDEX SessionID ON Presence("SessionID"); | ||
20 | CREATE INDEX UserID ON Presence("UserID"); | ||
21 | |||
22 | ALTER TABLE Presence ADD "LastSeen" Timestamp; | ||
23 | |||
24 | COMMIT; | ||
25 | |||
26 | :VERSION 3 # -------------------------- | ||
27 | |||
28 | BEGIN; | ||
29 | |||
30 | CREATE INDEX RegionID ON Presence("RegionID"); | ||
31 | |||
32 | COMMIT; | ||
33 | |||
34 | :VERSION 4 # Making sure LastSeen is actually defined in the table as it most likely erred in the double version 2 migration above | ||
35 | |||
36 | BEGIN; | ||
37 | |||
38 | ALTER TABLE Presence | ||
39 | DROP COLUMN IF EXISTS "LastSeen", | ||
40 | ADD COLUMN "LastSeen" Timestamp; | ||
41 | |||
42 | COMMIT; \ No newline at end of file | ||
diff --git a/OpenSim/Data/PGSQL/Resources/RegionStore.migrations b/OpenSim/Data/PGSQL/Resources/RegionStore.migrations new file mode 100644 index 0000000..1284ce0 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/RegionStore.migrations | |||
@@ -0,0 +1,1162 @@ | |||
1 | begin transaction ; | ||
2 | :VERSION 1 | ||
3 | |||
4 | CREATE TABLE prims( | ||
5 | "UUID" varchar(255) NOT NULL Primary key, | ||
6 | "RegionUUID" varchar(255) NULL, | ||
7 | "ParentID" int NULL, | ||
8 | "CreationDate" int NULL, | ||
9 | "Name" varchar(255) NULL, | ||
10 | "SceneGroupID" varchar(255) NULL, | ||
11 | "Text" varchar(255) NULL, | ||
12 | "Description" varchar(255) NULL, | ||
13 | "SitName" varchar(255) NULL, | ||
14 | "TouchName" varchar(255) NULL, | ||
15 | "ObjectFlags" int NULL, | ||
16 | "CreatorID" varchar(255) NULL, | ||
17 | "OwnerID" varchar(255) NULL, | ||
18 | "GroupID" varchar(255) NULL, | ||
19 | "LastOwnerID" varchar(255) NULL, | ||
20 | "OwnerMask" int NULL, | ||
21 | "NextOwnerMask" int NULL, | ||
22 | "GroupMask" int NULL, | ||
23 | "EveryoneMask" int NULL, | ||
24 | "BaseMask" int NULL, | ||
25 | "PositionX" double precision NULL, | ||
26 | "PositionY" double precision NULL, | ||
27 | "PositionZ" double precision NULL, | ||
28 | "GroupPositionX" double precision NULL, | ||
29 | "GroupPositionY" double precision NULL, | ||
30 | "GroupPositionZ" double precision NULL, | ||
31 | "VelocityX" double precision NULL, | ||
32 | "VelocityY" double precision NULL, | ||
33 | "VelocityZ" double precision NULL, | ||
34 | "AngularVelocityX" double precision NULL, | ||
35 | "AngularVelocityY" double precision NULL, | ||
36 | "AngularVelocityZ" double precision NULL, | ||
37 | "AccelerationX" double precision NULL, | ||
38 | "AccelerationY" double precision NULL, | ||
39 | "AccelerationZ" double precision NULL, | ||
40 | "RotationX" double precision NULL, | ||
41 | "RotationY" double precision NULL, | ||
42 | "RotationZ" double precision NULL, | ||
43 | "RotationW" double precision NULL, | ||
44 | "SitTargetOffsetX" double precision NULL, | ||
45 | "SitTargetOffsetY" double precision NULL, | ||
46 | "SitTargetOffsetZ" double precision NULL, | ||
47 | "SitTargetOrientW" double precision NULL, | ||
48 | "SitTargetOrientX" double precision NULL, | ||
49 | "SitTargetOrientY" double precision NULL, | ||
50 | "SitTargetOrientZ" double precision NULL | ||
51 | ); | ||
52 | |||
53 | CREATE TABLE primshapes( | ||
54 | "UUID" varchar(255) NOT NULL primary key, | ||
55 | "Shape" int NULL, | ||
56 | "ScaleX" double precision NULL, | ||
57 | "ScaleY" double precision NULL, | ||
58 | "ScaleZ" double precision NULL, | ||
59 | "PCode" int NULL, | ||
60 | "PathBegin" int NULL, | ||
61 | "PathEnd" int NULL, | ||
62 | "PathScaleX" int NULL, | ||
63 | "PathScaleY" int NULL, | ||
64 | "PathShearX" int NULL, | ||
65 | "PathShearY" int NULL, | ||
66 | "PathSkew" int NULL, | ||
67 | "PathCurve" int NULL, | ||
68 | "PathRadiusOffset" int NULL, | ||
69 | "PathRevolutions" int NULL, | ||
70 | "PathTaperX" int NULL, | ||
71 | "PathTaperY" int NULL, | ||
72 | "PathTwist" int NULL, | ||
73 | "PathTwistBegin" int NULL, | ||
74 | "ProfileBegin" int NULL, | ||
75 | "ProfileEnd" int NULL, | ||
76 | "ProfileCurve" int NULL, | ||
77 | "ProfileHollow" int NULL, | ||
78 | "State" int NULL, | ||
79 | "Texture" bytea NULL, | ||
80 | "ExtraParams" bytea NULL | ||
81 | ); | ||
82 | |||
83 | CREATE TABLE primitems( | ||
84 | "itemID" varchar(255) NOT NULL primary key, | ||
85 | "primID" varchar(255) NULL, | ||
86 | "assetID" varchar(255) NULL, | ||
87 | "parentFolderID" varchar(255) NULL, | ||
88 | "invType" int NULL, | ||
89 | "assetType" int NULL, | ||
90 | "name" varchar(255) NULL, | ||
91 | "description" varchar(255) NULL, | ||
92 | "creationDate" varchar(255) NULL, | ||
93 | "creatorID" varchar(255) NULL, | ||
94 | "ownerID" varchar(255) NULL, | ||
95 | "lastOwnerID" varchar(255) NULL, | ||
96 | "groupID" varchar(255) NULL, | ||
97 | "nextPermissions" int NULL, | ||
98 | "currentPermissions" int NULL, | ||
99 | "basePermissions" int NULL, | ||
100 | "everyonePermissions" int NULL, | ||
101 | "groupPermissions" int NULL | ||
102 | ); | ||
103 | |||
104 | CREATE TABLE terrain( | ||
105 | "RegionUUID" varchar(255) NULL, | ||
106 | "Revision" int NULL, | ||
107 | "Heightfield" bytea NULL | ||
108 | ); | ||
109 | |||
110 | |||
111 | CREATE TABLE land( | ||
112 | "UUID" varchar(255) NOT NULL primary key, | ||
113 | "RegionUUID" varchar(255) NULL, | ||
114 | "LocalLandID" int NULL, | ||
115 | "Bitmap" bytea NULL, | ||
116 | "Name" varchar(255) NULL, | ||
117 | "Description" varchar(255) NULL, | ||
118 | "OwnerUUID" varchar(255) NULL, | ||
119 | "IsGroupOwned" boolean NULL, | ||
120 | "Area" int NULL, | ||
121 | "AuctionID" int NULL, | ||
122 | "Category" int NULL, | ||
123 | "ClaimDate" int NULL, | ||
124 | "ClaimPrice" int NULL, | ||
125 | "GroupUUID" varchar(255) NULL, | ||
126 | "SalePrice" int NULL, | ||
127 | "LandStatus" int NULL, | ||
128 | "LandFlags" int NULL, | ||
129 | "LandingType" int NULL, | ||
130 | "MediaAutoScale" int NULL, | ||
131 | "MediaTextureUUID" varchar(255) NULL, | ||
132 | "MediaURL" varchar(255) NULL, | ||
133 | "MusicURL" varchar(255) NULL, | ||
134 | "PassHours" double precision NULL, | ||
135 | "PassPrice" int NULL, | ||
136 | "SnapshotUUID" varchar(255) NULL, | ||
137 | "UserLocationX" double precision NULL, | ||
138 | "UserLocationY" double precision NULL, | ||
139 | "UserLocationZ" double precision NULL, | ||
140 | "UserLookAtX" double precision NULL, | ||
141 | "UserLookAtY" double precision NULL, | ||
142 | "UserLookAtZ" double precision NULL | ||
143 | ); | ||
144 | |||
145 | Create index on land (lower("Name")); | ||
146 | |||
147 | CREATE TABLE landaccesslist( | ||
148 | "LandUUID" varchar(255) NULL, | ||
149 | "AccessUUID" varchar(255) NULL, | ||
150 | "Flags" int NULL | ||
151 | ); | ||
152 | |||
153 | COMMIT; | ||
154 | |||
155 | :VERSION 2 | ||
156 | |||
157 | BEGIN TRANSACTION; | ||
158 | |||
159 | CREATE TABLE regionban ( | ||
160 | "regionUUID" VARCHAR(36) NOT NULL, | ||
161 | "bannedUUID" VARCHAR(36) NOT NULL, | ||
162 | "bannedIp" VARCHAR(16) NOT NULL, | ||
163 | "bannedIpHostMask" VARCHAR(16) NOT NULL | ||
164 | ); | ||
165 | |||
166 | create table regionsettings ( | ||
167 | "regionUUID" varchar(36) not null primary key, | ||
168 | "block_terraform" boolean not null, | ||
169 | "block_fly" boolean not null, | ||
170 | "allow_damage" boolean not null, | ||
171 | "restrict_pushing" boolean not null, | ||
172 | "allow_land_resell" boolean not null, | ||
173 | "allow_land_join_divide" boolean not null, | ||
174 | "block_show_in_search" boolean not null, | ||
175 | "agent_limit" int not null, | ||
176 | "object_bonus" double precision not null, | ||
177 | "maturity" int not null, | ||
178 | "disable_scripts" boolean not null, | ||
179 | "disable_collisions" boolean not null, | ||
180 | "disable_physics" boolean not null, | ||
181 | "terrain_texture_1" varchar(36) not null, | ||
182 | "terrain_texture_2" varchar(36) not null, | ||
183 | "terrain_texture_3" varchar(36) not null, | ||
184 | "terrain_texture_4" varchar(36) not null, | ||
185 | "elevation_1_nw" double precision not null, | ||
186 | "elevation_2_nw" double precision not null, | ||
187 | "elevation_1_ne" double precision not null, | ||
188 | "elevation_2_ne" double precision not null, | ||
189 | "elevation_1_se" double precision not null, | ||
190 | "elevation_2_se" double precision not null, | ||
191 | "elevation_1_sw" double precision not null, | ||
192 | "elevation_2_sw" double precision not null, | ||
193 | "water_height" double precision not null, | ||
194 | "terrain_raise_limit" double precision not null, | ||
195 | "terrain_lower_limit" double precision not null, | ||
196 | "use_estate_sun" boolean not null, | ||
197 | "fixed_sun" boolean not null, | ||
198 | "sun_position" double precision not null, | ||
199 | "covenant" varchar(36) default NULL, | ||
200 | "Sandbox" boolean NOT NULL | ||
201 | ); | ||
202 | |||
203 | COMMIT; | ||
204 | |||
205 | :VERSION 3 | ||
206 | |||
207 | BEGIN TRANSACTION; | ||
208 | |||
209 | CREATE TABLE Tmp_prims | ||
210 | ( | ||
211 | "UUID" varchar(36) NOT NULL , | ||
212 | "RegionUUID" varchar(36) NULL, | ||
213 | "ParentID" int NULL, | ||
214 | "CreationDate" int NULL, | ||
215 | "Name" varchar(255) NULL, | ||
216 | "SceneGroupID" varchar(36) NULL, | ||
217 | "Text" varchar(255) NULL, | ||
218 | "Description" varchar(255) NULL, | ||
219 | "SitName" varchar(255) NULL, | ||
220 | "TouchName" varchar(255) NULL, | ||
221 | "ObjectFlags" int NULL, | ||
222 | "CreatorID" varchar(36) NULL, | ||
223 | "OwnerID" varchar(36) NULL, | ||
224 | "GroupID" varchar(36) NULL, | ||
225 | "LastOwnerID" varchar(36) NULL, | ||
226 | "OwnerMask" int NULL, | ||
227 | "NextOwnerMask" int NULL, | ||
228 | "GroupMask" int NULL, | ||
229 | "EveryoneMask" int NULL, | ||
230 | "BaseMask" int NULL, | ||
231 | "PositionX" double precision NULL, | ||
232 | "PositionY" double precision NULL, | ||
233 | "PositionZ" double precision NULL, | ||
234 | "GroupPositionX" double precision NULL, | ||
235 | "GroupPositionY" double precision NULL, | ||
236 | "GroupPositionZ" double precision NULL, | ||
237 | "VelocityX" double precision NULL, | ||
238 | "VelocityY" double precision NULL, | ||
239 | "VelocityZ" double precision NULL, | ||
240 | "AngularVelocityX" double precision NULL, | ||
241 | "AngularVelocityY" double precision NULL, | ||
242 | "AngularVelocityZ" double precision NULL, | ||
243 | "AccelerationX" double precision NULL, | ||
244 | "AccelerationY" double precision NULL, | ||
245 | "AccelerationZ" double precision NULL, | ||
246 | "RotationX" double precision NULL, | ||
247 | "RotationY" double precision NULL, | ||
248 | "RotationZ" double precision NULL, | ||
249 | "RotationW" double precision NULL, | ||
250 | "SitTargetOffsetX" double precision NULL, | ||
251 | "SitTargetOffsetY" double precision NULL, | ||
252 | "SitTargetOffsetZ" double precision NULL, | ||
253 | "SitTargetOrientW" double precision NULL, | ||
254 | "SitTargetOrientX" double precision NULL, | ||
255 | "SitTargetOrientY" double precision NULL, | ||
256 | "SitTargetOrientZ" double precision NULL | ||
257 | ); | ||
258 | |||
259 | INSERT INTO Tmp_prims ("UUID", "RegionUUID", "ParentID", "CreationDate", "Name", "SceneGroupID", "Text", "Description", "SitName", "TouchName", "ObjectFlags", "CreatorID", "OwnerID", "GroupID", "LastOwnerID", "OwnerMask", "NextOwnerMask", "GroupMask", "EveryoneMask", "BaseMask", "PositionX", "PositionY", "PositionZ", "GroupPositionX", "GroupPositionY", "GroupPositionZ", "VelocityX", "VelocityY", "VelocityZ", "AngularVelocityX", "AngularVelocityY", "AngularVelocityZ", "AccelerationX", "AccelerationY", "AccelerationZ", "RotationX", "RotationY", "RotationZ", "RotationW", "SitTargetOffsetX", "SitTargetOffsetY", "SitTargetOffsetZ", "SitTargetOrientW", "SitTargetOrientX", "SitTargetOrientY", "SitTargetOrientZ") | ||
260 | SELECT cast("UUID" as varchar(36)), cast("RegionUUID" as varchar(36)), "ParentID", "CreationDate", "Name", cast("SceneGroupID" as varchar(36)), "Text", "Description", "SitName", "TouchName", "ObjectFlags", cast("CreatorID" as varchar(36)), cast("OwnerID" as varchar(36)), cast( "GroupID" as varchar(36)), cast("LastOwnerID" as varchar(36)), "OwnerMask", "NextOwnerMask", "GroupMask", "EveryoneMask", "BaseMask", "PositionX", "PositionY", "PositionZ", "GroupPositionX", "GroupPositionY", "GroupPositionZ", "VelocityX", "VelocityY", "VelocityZ", "AngularVelocityX", "AngularVelocityY", "AngularVelocityZ", "AccelerationX", "AccelerationY", "AccelerationZ", "RotationX", "RotationY", "RotationZ", "RotationW", "SitTargetOffsetX", "SitTargetOffsetY", "SitTargetOffsetZ", "SitTargetOrientW", "SitTargetOrientX", "SitTargetOrientY", "SitTargetOrientZ" | ||
261 | FROM prims ; | ||
262 | |||
263 | DROP TABLE prims; | ||
264 | |||
265 | alter table Tmp_prims rename to prims; | ||
266 | |||
267 | |||
268 | ALTER TABLE prims ADD CONSTRAINT | ||
269 | PK__prims__10566F31 PRIMARY KEY | ||
270 | ( | ||
271 | "UUID" | ||
272 | ); | ||
273 | |||
274 | COMMIT; | ||
275 | |||
276 | :VERSION 4 | ||
277 | |||
278 | BEGIN TRANSACTION; | ||
279 | |||
280 | CREATE TABLE Tmp_primitems | ||
281 | ( | ||
282 | "itemID" varchar(36) NOT NULL, | ||
283 | "primID" varchar(36) NULL, | ||
284 | "assetID" varchar(36) NULL, | ||
285 | "parentFolderID" varchar(36) NULL, | ||
286 | "invType" int NULL, | ||
287 | "assetType" int NULL, | ||
288 | "name" varchar(255) NULL, | ||
289 | "description" varchar(255) NULL, | ||
290 | "creationDate" varchar(255) NULL, | ||
291 | "creatorID" varchar(36) NULL, | ||
292 | "ownerID" varchar(36) NULL, | ||
293 | "lastOwnerID" varchar(36) NULL, | ||
294 | "groupID" varchar(36) NULL, | ||
295 | "nextPermissions" int NULL, | ||
296 | "currentPermissions" int NULL, | ||
297 | "basePermissions" int NULL, | ||
298 | "everyonePermissions" int NULL, | ||
299 | "groupPermissions" int NULL | ||
300 | ); | ||
301 | |||
302 | INSERT INTO Tmp_primitems ("itemID", "primID", "assetID", "parentFolderID", "invType", "assetType", "name", "description", "creationDate", "creatorID", "ownerID", "lastOwnerID", "groupID", "nextPermissions", "currentPermissions", "basePermissions", "everyonePermissions", "groupPermissions") | ||
303 | SELECT cast("itemID" as varchar(36)), cast("primID" as varchar(36)), cast("assetID" as varchar(36)), cast( "parentFolderID" as varchar(36)), "invType", "assetType", "name", "description", "creationDate", cast( "creatorID" as varchar(36)), cast("ownerID" as varchar(36)), cast("lastOwnerID" as varchar(36)), cast("groupID" as varchar(36)), "nextPermissions", "currentPermissions", "basePermissions", "everyonePermissions", "groupPermissions" | ||
304 | from primitems; | ||
305 | |||
306 | DROP TABLE primitems; | ||
307 | |||
308 | alter table Tmp_primitems rename to primitems; | ||
309 | |||
310 | ALTER TABLE primitems ADD CONSTRAINT | ||
311 | PK__primitems__0A688BB1 PRIMARY KEY | ||
312 | ( | ||
313 | "itemID" | ||
314 | ); | ||
315 | |||
316 | |||
317 | COMMIT; | ||
318 | |||
319 | |||
320 | :VERSION 5 | ||
321 | |||
322 | BEGIN TRANSACTION; | ||
323 | |||
324 | CREATE TABLE Tmp_primshapes | ||
325 | ( | ||
326 | "UUID" varchar(36) NOT NULL, | ||
327 | "Shape" int NULL, | ||
328 | "ScaleX" double precision NULL, | ||
329 | "ScaleY" double precision NULL, | ||
330 | "ScaleZ" double precision NULL, | ||
331 | "PCode" int NULL, | ||
332 | "PathBegin" int NULL, | ||
333 | "PathEnd" int NULL, | ||
334 | "PathScaleX" int NULL, | ||
335 | "PathScaleY" int NULL, | ||
336 | "PathShearX" int NULL, | ||
337 | "PathShearY" int NULL, | ||
338 | "PathSkew" int NULL, | ||
339 | "PathCurve" int NULL, | ||
340 | "PathRadiusOffset" int NULL, | ||
341 | "PathRevolutions" int NULL, | ||
342 | "PathTaperX" int NULL, | ||
343 | "PathTaperY" int NULL, | ||
344 | "PathTwist" int NULL, | ||
345 | "PathTwistBegin" int NULL, | ||
346 | "ProfileBegin" int NULL, | ||
347 | "ProfileEnd" int NULL, | ||
348 | "ProfileCurve" int NULL, | ||
349 | "ProfileHollow" int NULL, | ||
350 | "State" int NULL, | ||
351 | "Texture" bytea NULL, | ||
352 | "ExtraParams" bytea NULL | ||
353 | ) ; | ||
354 | |||
355 | INSERT INTO Tmp_primshapes ("UUID", "Shape", "ScaleX", "ScaleY", "ScaleZ", "PCode", "PathBegin", "PathEnd", "PathScaleX", "PathScaleY", "PathShearX", "PathShearY", "PathSkew", "PathCurve", "PathRadiusOffset", "PathRevolutions", "PathTaperX", "PathTaperY", "PathTwist", "PathTwistBegin", "ProfileBegin", "ProfileEnd", "ProfileCurve", "ProfileHollow", "State", "Texture", "ExtraParams") | ||
356 | SELECT cast("UUID" as varchar(36)), "Shape", "ScaleX", "ScaleY", "ScaleZ", "PCode", "PathBegin", "PathEnd", "PathScaleX", "PathScaleY", "PathShearX", "PathShearY", "PathSkew", "PathCurve", "PathRadiusOffset", "PathRevolutions", "PathTaperX", "PathTaperY", "PathTwist", "PathTwistBegin", "ProfileBegin", "ProfileEnd", "ProfileCurve", "ProfileHollow", "State", "Texture", "ExtraParams" | ||
357 | FROM primshapes; | ||
358 | |||
359 | DROP TABLE primshapes; | ||
360 | |||
361 | alter table Tmp_primshapes rename to primshapes; | ||
362 | |||
363 | ALTER TABLE primshapes ADD CONSTRAINT | ||
364 | PK__primshapes__0880433F PRIMARY KEY | ||
365 | ( | ||
366 | "UUID" | ||
367 | ) ; | ||
368 | |||
369 | COMMIT; | ||
370 | |||
371 | |||
372 | :VERSION 6 | ||
373 | |||
374 | BEGIN TRANSACTION; | ||
375 | |||
376 | ALTER TABLE prims ADD "PayPrice" int not null default 0; | ||
377 | ALTER TABLE prims ADD "PayButton1" int not null default 0; | ||
378 | ALTER TABLE prims ADD "PayButton2" int not null default 0; | ||
379 | ALTER TABLE prims ADD "PayButton3" int not null default 0; | ||
380 | ALTER TABLE prims ADD "PayButton4" int not null default 0; | ||
381 | ALTER TABLE prims ADD "LoopedSound" varchar(36) not null default '00000000-0000-0000-0000-000000000000'; | ||
382 | ALTER TABLE prims ADD "LoopedSoundGain" double precision not null default 0.0; | ||
383 | ALTER TABLE prims ADD "TextureAnimation" bytea; | ||
384 | ALTER TABLE prims ADD "OmegaX" double precision not null default 0.0; | ||
385 | ALTER TABLE prims ADD "OmegaY" double precision not null default 0.0; | ||
386 | ALTER TABLE prims ADD "OmegaZ" double precision not null default 0.0; | ||
387 | ALTER TABLE prims ADD "CameraEyeOffsetX" double precision not null default 0.0; | ||
388 | ALTER TABLE prims ADD "CameraEyeOffsetY" double precision not null default 0.0; | ||
389 | ALTER TABLE prims ADD "CameraEyeOffsetZ" double precision not null default 0.0; | ||
390 | ALTER TABLE prims ADD "CameraAtOffsetX" double precision not null default 0.0; | ||
391 | ALTER TABLE prims ADD "CameraAtOffsetY" double precision not null default 0.0; | ||
392 | ALTER TABLE prims ADD "CameraAtOffsetZ" double precision not null default 0.0; | ||
393 | ALTER TABLE prims ADD "ForceMouselook" smallint not null default 0; | ||
394 | ALTER TABLE prims ADD "ScriptAccessPin" int not null default 0; | ||
395 | ALTER TABLE prims ADD "AllowedDrop" smallint not null default 0; | ||
396 | ALTER TABLE prims ADD "DieAtEdge" smallint not null default 0; | ||
397 | ALTER TABLE prims ADD "SalePrice" int not null default 10; | ||
398 | ALTER TABLE prims ADD "SaleType" smallint not null default 0; | ||
399 | |||
400 | ALTER TABLE primitems add "flags" integer not null default 0; | ||
401 | |||
402 | ALTER TABLE land ADD "AuthbuyerID" varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000'; | ||
403 | |||
404 | CREATE index prims_regionuuid on prims("RegionUUID"); | ||
405 | CREATE index prims_parentid on prims("ParentID"); | ||
406 | |||
407 | CREATE index primitems_primid on primitems("primID"); | ||
408 | |||
409 | COMMIT; | ||
410 | |||
411 | |||
412 | :VERSION 7 | ||
413 | |||
414 | BEGIN TRANSACTION; | ||
415 | |||
416 | ALTER TABLE prims ADD "ColorR" int not null default 0; | ||
417 | ALTER TABLE prims ADD "ColorG" int not null default 0; | ||
418 | ALTER TABLE prims ADD "ColorB" int not null default 0; | ||
419 | ALTER TABLE prims ADD "ColorA" int not null default 0; | ||
420 | ALTER TABLE prims ADD "ParticleSystem" bytea; | ||
421 | ALTER TABLE prims ADD "ClickAction" smallint NOT NULL default 0; | ||
422 | |||
423 | COMMIT; | ||
424 | |||
425 | |||
426 | :VERSION 8 | ||
427 | |||
428 | BEGIN TRANSACTION; | ||
429 | |||
430 | ALTER TABLE land ADD "OtherCleanTime" integer NOT NULL default 0; | ||
431 | ALTER TABLE land ADD "Dwell" integer NOT NULL default 0; | ||
432 | |||
433 | COMMIT; | ||
434 | |||
435 | :VERSION 9 | ||
436 | |||
437 | BEGIN TRANSACTION; | ||
438 | |||
439 | ALTER TABLE prims ADD "Material" smallint NOT NULL default 3; | ||
440 | |||
441 | COMMIT; | ||
442 | |||
443 | |||
444 | :VERSION 10 | ||
445 | |||
446 | BEGIN TRANSACTION; | ||
447 | |||
448 | ALTER TABLE regionsettings ADD "sunvectorx" double precision NOT NULL default 0; | ||
449 | ALTER TABLE regionsettings ADD "sunvectory" double precision NOT NULL default 0; | ||
450 | ALTER TABLE regionsettings ADD "sunvectorz" double precision NOT NULL default 0; | ||
451 | |||
452 | COMMIT; | ||
453 | |||
454 | |||
455 | :VERSION 11 | ||
456 | |||
457 | BEGIN TRANSACTION; | ||
458 | |||
459 | ALTER TABLE prims ADD "CollisionSound" char(36) not null default '00000000-0000-0000-0000-000000000000'; | ||
460 | ALTER TABLE prims ADD "CollisionSoundVolume" double precision not null default 0.0; | ||
461 | |||
462 | COMMIT; | ||
463 | |||
464 | |||
465 | :VERSION 12 | ||
466 | |||
467 | BEGIN TRANSACTION; | ||
468 | |||
469 | ALTER TABLE prims ADD "LinkNumber" integer not null default 0; | ||
470 | |||
471 | COMMIT; | ||
472 | |||
473 | |||
474 | :VERSION 13 | ||
475 | |||
476 | BEGIN TRANSACTION; | ||
477 | |||
478 | CREATE TABLE Tmp_prims | ||
479 | ( | ||
480 | "UUID" uuid NOT NULL, | ||
481 | "RegionUUID" uuid NULL, | ||
482 | "ParentID" int NULL, | ||
483 | "CreationDate" int NULL, | ||
484 | "Name" varchar(255) NULL, | ||
485 | "SceneGroupID" uuid NULL, | ||
486 | "Text" varchar(255) NULL, | ||
487 | "Description" varchar(255) NULL, | ||
488 | "SitName" varchar(255) NULL, | ||
489 | "TouchName" varchar(255) NULL, | ||
490 | "ObjectFlags" int NULL, | ||
491 | "CreatorID" uuid NULL, | ||
492 | "OwnerID" uuid NULL, | ||
493 | "GroupID" uuid NULL, | ||
494 | "LastOwnerID" uuid NULL, | ||
495 | "OwnerMask" int NULL, | ||
496 | "NextOwnerMask" int NULL, | ||
497 | "GroupMask" int NULL, | ||
498 | "EveryoneMask" int NULL, | ||
499 | "BaseMask" int NULL, | ||
500 | "PositionX" double precision NULL, | ||
501 | "PositionY" double precision NULL, | ||
502 | "PositionZ" double precision NULL, | ||
503 | "GroupPositionX" double precision NULL, | ||
504 | "GroupPositionY" double precision NULL, | ||
505 | "GroupPositionZ" double precision NULL, | ||
506 | "VelocityX" double precision NULL, | ||
507 | "VelocityY" double precision NULL, | ||
508 | "VelocityZ" double precision NULL, | ||
509 | "AngularVelocityX" double precision NULL, | ||
510 | "AngularVelocityY" double precision NULL, | ||
511 | "AngularVelocityZ" double precision NULL, | ||
512 | "AccelerationX" double precision NULL, | ||
513 | "AccelerationY" double precision NULL, | ||
514 | "AccelerationZ" double precision NULL, | ||
515 | "RotationX" double precision NULL, | ||
516 | "RotationY" double precision NULL, | ||
517 | "RotationZ" double precision NULL, | ||
518 | "RotationW" double precision NULL, | ||
519 | "SitTargetOffsetX" double precision NULL, | ||
520 | "SitTargetOffsetY" double precision NULL, | ||
521 | "SitTargetOffsetZ" double precision NULL, | ||
522 | "SitTargetOrientW" double precision NULL, | ||
523 | "SitTargetOrientX" double precision NULL, | ||
524 | "SitTargetOrientY" double precision NULL, | ||
525 | "SitTargetOrientZ" double precision NULL, | ||
526 | "PayPrice" int NOT NULL DEFAULT ((0)), | ||
527 | "PayButton1" int NOT NULL DEFAULT ((0)), | ||
528 | "PayButton2" int NOT NULL DEFAULT ((0)), | ||
529 | "PayButton3" int NOT NULL DEFAULT ((0)), | ||
530 | "PayButton4" int NOT NULL DEFAULT ((0)), | ||
531 | "LoopedSound" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
532 | "LoopedSoundGain" double precision NOT NULL DEFAULT ((0.0)), | ||
533 | "TextureAnimation" bytea NULL, | ||
534 | "OmegaX" double precision NOT NULL DEFAULT ((0.0)), | ||
535 | "OmegaY" double precision NOT NULL DEFAULT ((0.0)), | ||
536 | "OmegaZ" double precision NOT NULL DEFAULT ((0.0)), | ||
537 | "CameraEyeOffsetX" double precision NOT NULL DEFAULT ((0.0)), | ||
538 | "CameraEyeOffsetY" double precision NOT NULL DEFAULT ((0.0)), | ||
539 | "CameraEyeOffsetZ" double precision NOT NULL DEFAULT ((0.0)), | ||
540 | "CameraAtOffsetX" double precision NOT NULL DEFAULT ((0.0)), | ||
541 | "CameraAtOffsetY" double precision NOT NULL DEFAULT ((0.0)), | ||
542 | "CameraAtOffsetZ" double precision NOT NULL DEFAULT ((0.0)), | ||
543 | "ForceMouselook" smallint NOT NULL DEFAULT ((0)), | ||
544 | "ScriptAccessPin" int NOT NULL DEFAULT ((0)), | ||
545 | "AllowedDrop" smallint NOT NULL DEFAULT ((0)), | ||
546 | "DieAtEdge" smallint NOT NULL DEFAULT ((0)), | ||
547 | "SalePrice" int NOT NULL DEFAULT ((10)), | ||
548 | "SaleType" smallint NOT NULL DEFAULT ((0)), | ||
549 | "ColorR" int NOT NULL DEFAULT ((0)), | ||
550 | "ColorG" int NOT NULL DEFAULT ((0)), | ||
551 | "ColorB" int NOT NULL DEFAULT ((0)), | ||
552 | "ColorA" int NOT NULL DEFAULT ((0)), | ||
553 | "ParticleSystem" bytea NULL, | ||
554 | "ClickAction" smallint NOT NULL DEFAULT ((0)), | ||
555 | "Material" smallint NOT NULL DEFAULT ((3)), | ||
556 | "CollisionSound" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
557 | "CollisionSoundVolume" double precision NOT NULL DEFAULT ((0.0)), | ||
558 | "LinkNumber" int NOT NULL DEFAULT ((0)) | ||
559 | ); | ||
560 | |||
561 | INSERT INTO Tmp_prims ("UUID", "RegionUUID", "ParentID", "CreationDate", "Name", "SceneGroupID", "Text", "Description", "SitName", "TouchName", "ObjectFlags", "CreatorID", "OwnerID", "GroupID", "LastOwnerID", "OwnerMask", "NextOwnerMask", "GroupMask", "EveryoneMask", "BaseMask", "PositionX", "PositionY", "PositionZ", "GroupPositionX", "GroupPositionY", "GroupPositionZ", "VelocityX", "VelocityY", "VelocityZ", "AngularVelocityX", "AngularVelocityY", "AngularVelocityZ", "AccelerationX", "AccelerationY", "AccelerationZ", "RotationX", "RotationY", "RotationZ", "RotationW", "SitTargetOffsetX", "SitTargetOffsetY", "SitTargetOffsetZ", "SitTargetOrientW", "SitTargetOrientX", "SitTargetOrientY", "SitTargetOrientZ", "PayPrice", "PayButton1", "PayButton2", "PayButton3", "PayButton4", "LoopedSound", "LoopedSoundGain", "TextureAnimation", "OmegaX", "OmegaY", "OmegaZ", "CameraEyeOffsetX", "CameraEyeOffsetY", "CameraEyeOffsetZ", "CameraAtOffsetX", "CameraAtOffsetY", "CameraAtOffsetZ", "ForceMouselook", "ScriptAccessPin", "AllowedDrop", "DieAtEdge", "SalePrice", "SaleType", "ColorR", "ColorG", "ColorB", "ColorA", "ParticleSystem", "ClickAction", "Material", "CollisionSound", "CollisionSoundVolume", "LinkNumber") | ||
562 | SELECT cast("UUID" as uuid), cast("RegionUUID" as uuid), "ParentID", "CreationDate", "Name", cast("SceneGroupID" as uuid), "Text", "Description", "SitName", "TouchName", "ObjectFlags", cast("CreatorID" as uuid), cast("OwnerID" as uuid), cast("GroupID" as uuid), cast("LastOwnerID" as uuid), "OwnerMask", "NextOwnerMask", "GroupMask", "EveryoneMask", "BaseMask", "PositionX", "PositionY", "PositionZ", "GroupPositionX", "GroupPositionY", "GroupPositionZ", "VelocityX", "VelocityY", "VelocityZ", "AngularVelocityX", "AngularVelocityY", "AngularVelocityZ", "AccelerationX", "AccelerationY", "AccelerationZ", "RotationX", "RotationY", "RotationZ", "RotationW", "SitTargetOffsetX", "SitTargetOffsetY", "SitTargetOffsetZ", "SitTargetOrientW", "SitTargetOrientX", "SitTargetOrientY", "SitTargetOrientZ", "PayPrice", "PayButton1", "PayButton2", "PayButton3", "PayButton4", cast("LoopedSound" as uuid), "LoopedSoundGain", "TextureAnimation", "OmegaX", "OmegaY", "OmegaZ", "CameraEyeOffsetX", "CameraEyeOffsetY", "CameraEyeOffsetZ", "CameraAtOffsetX", "CameraAtOffsetY", "CameraAtOffsetZ", "ForceMouselook", "ScriptAccessPin", "AllowedDrop", "DieAtEdge", "SalePrice", "SaleType", "ColorR", "ColorG", "ColorB", "ColorA", "ParticleSystem", "ClickAction", "Material", cast("CollisionSound" as uuid), "CollisionSoundVolume", "LinkNumber" | ||
563 | FROM prims ; | ||
564 | |||
565 | DROP TABLE prims; | ||
566 | |||
567 | alter table Tmp_prims rename to prims; | ||
568 | |||
569 | ALTER TABLE prims ADD CONSTRAINT | ||
570 | PK__prims__10566F31 PRIMARY KEY | ||
571 | ( | ||
572 | "UUID" | ||
573 | ); | ||
574 | |||
575 | |||
576 | CREATE INDEX prims_regionuuid ON prims | ||
577 | ( | ||
578 | "RegionUUID" | ||
579 | ); | ||
580 | |||
581 | CREATE INDEX prims_parentid ON prims | ||
582 | ( | ||
583 | "ParentID" | ||
584 | ); | ||
585 | |||
586 | COMMIT; | ||
587 | |||
588 | |||
589 | :VERSION 14 | ||
590 | |||
591 | BEGIN TRANSACTION; | ||
592 | |||
593 | CREATE TABLE Tmp_primshapes | ||
594 | ( | ||
595 | "UUID" uuid NOT NULL, | ||
596 | "Shape" int NULL, | ||
597 | "ScaleX" double precision NULL, | ||
598 | "ScaleY" double precision NULL, | ||
599 | "ScaleZ" double precision NULL, | ||
600 | "PCode" int NULL, | ||
601 | "PathBegin" int NULL, | ||
602 | "PathEnd" int NULL, | ||
603 | "PathScaleX" int NULL, | ||
604 | "PathScaleY" int NULL, | ||
605 | "PathShearX" int NULL, | ||
606 | "PathShearY" int NULL, | ||
607 | "PathSkew" int NULL, | ||
608 | "PathCurve" int NULL, | ||
609 | "PathRadiusOffset" int NULL, | ||
610 | "PathRevolutions" int NULL, | ||
611 | "PathTaperX" int NULL, | ||
612 | "PathTaperY" int NULL, | ||
613 | "PathTwist" int NULL, | ||
614 | "PathTwistBegin" int NULL, | ||
615 | "ProfileBegin" int NULL, | ||
616 | "ProfileEnd" int NULL, | ||
617 | "ProfileCurve" int NULL, | ||
618 | "ProfileHollow" int NULL, | ||
619 | "State" int NULL, | ||
620 | "Texture" bytea NULL, | ||
621 | "ExtraParams" bytea NULL | ||
622 | ); | ||
623 | |||
624 | INSERT INTO Tmp_primshapes ("UUID", "Shape", "ScaleX", "ScaleY", "ScaleZ", "PCode", "PathBegin", "PathEnd", "PathScaleX", "PathScaleY", "PathShearX", "PathShearY", "PathSkew", "PathCurve", "PathRadiusOffset", "PathRevolutions", "PathTaperX", "PathTaperY", "PathTwist", "PathTwistBegin", "ProfileBegin", "ProfileEnd", "ProfileCurve", "ProfileHollow", "State", "Texture", "ExtraParams") | ||
625 | SELECT cast("UUID" as uuid), "Shape", "ScaleX", "ScaleY", "ScaleZ", "PCode", "PathBegin", "PathEnd", "PathScaleX", "PathScaleY", "PathShearX", "PathShearY", "PathSkew", "PathCurve", "PathRadiusOffset", "PathRevolutions", "PathTaperX", "PathTaperY", "PathTwist", "PathTwistBegin", "ProfileBegin", "ProfileEnd", "ProfileCurve", "ProfileHollow", "State", "Texture", "ExtraParams" | ||
626 | FROM primshapes; | ||
627 | |||
628 | DROP TABLE primshapes; | ||
629 | |||
630 | alter table Tmp_primshapes rename to primshapes; | ||
631 | |||
632 | ALTER TABLE primshapes ADD CONSTRAINT | ||
633 | PK__primshapes__0880433F PRIMARY KEY | ||
634 | ( | ||
635 | "UUID" | ||
636 | ); | ||
637 | |||
638 | COMMIT; | ||
639 | |||
640 | |||
641 | :VERSION 15 | ||
642 | |||
643 | BEGIN TRANSACTION; | ||
644 | |||
645 | CREATE TABLE Tmp_primitems | ||
646 | ( | ||
647 | "itemID" uuid NOT NULL, | ||
648 | "primID" uuid NULL, | ||
649 | "assetID" uuid NULL, | ||
650 | "parentFolderID" uuid NULL, | ||
651 | "invType" int NULL, | ||
652 | "assetType" int NULL, | ||
653 | "name" varchar(255) NULL, | ||
654 | "description" varchar(255) NULL, | ||
655 | "creationDate" varchar(255) NULL, | ||
656 | "creatorID" uuid NULL, | ||
657 | "ownerID" uuid NULL, | ||
658 | "lastOwnerID" uuid NULL, | ||
659 | "groupID" uuid NULL, | ||
660 | "nextPermissions" int NULL, | ||
661 | "currentPermissions" int NULL, | ||
662 | "basePermissions" int NULL, | ||
663 | "everyonePermissions" int NULL, | ||
664 | "groupPermissions" int NULL, | ||
665 | flags int NOT NULL DEFAULT ((0)) | ||
666 | ); | ||
667 | |||
668 | INSERT INTO Tmp_primitems ("itemID", "primID", "assetID", "parentFolderID", "invType", "assetType", "name", "description", "creationDate", "creatorID", "ownerID", "lastOwnerID", "groupID", "nextPermissions", "currentPermissions", "basePermissions", "everyonePermissions", "groupPermissions", flags) | ||
669 | SELECT cast("itemID" as uuid), cast("primID" as uuid), cast("assetID" as uuid), cast("parentFolderID" as uuid), "invType", "assetType", "name", "description", "creationDate", cast("creatorID" as uuid), cast("ownerID" as uuid), cast("lastOwnerID" as uuid), cast("groupID" as uuid), "nextPermissions", "currentPermissions", "basePermissions", "everyonePermissions", "groupPermissions", flags | ||
670 | FROM primitems ; | ||
671 | |||
672 | DROP TABLE primitems; | ||
673 | |||
674 | alter table Tmp_primitems rename to primitems; | ||
675 | |||
676 | ALTER TABLE primitems ADD CONSTRAINT | ||
677 | PK__primitems__0A688BB1 PRIMARY KEY | ||
678 | ( | ||
679 | "itemID" | ||
680 | ); | ||
681 | |||
682 | CREATE INDEX primitems_primid ON primitems | ||
683 | ( | ||
684 | "primID" | ||
685 | ) ; | ||
686 | |||
687 | COMMIT; | ||
688 | |||
689 | |||
690 | :VERSION 16 | ||
691 | |||
692 | |||
693 | BEGIN TRANSACTION; | ||
694 | |||
695 | CREATE TABLE Tmp_terrain | ||
696 | ( | ||
697 | "RegionUUID" uuid NULL, | ||
698 | "Revision" int NULL, | ||
699 | "Heightfield" bytea NULL | ||
700 | ); | ||
701 | |||
702 | INSERT INTO Tmp_terrain ("RegionUUID", "Revision", "Heightfield") | ||
703 | SELECT cast("RegionUUID" as uuid), "Revision", "Heightfield" | ||
704 | FROM terrain ; | ||
705 | |||
706 | DROP TABLE terrain; | ||
707 | |||
708 | alter table Tmp_terrain rename to terrain; | ||
709 | |||
710 | COMMIT; | ||
711 | |||
712 | |||
713 | :VERSION 17 | ||
714 | |||
715 | BEGIN TRANSACTION; | ||
716 | |||
717 | CREATE TABLE Tmp_land | ||
718 | ( | ||
719 | "UUID" uuid NOT NULL, | ||
720 | "RegionUUID" uuid NULL, | ||
721 | "LocalLandID" int NULL, | ||
722 | "Bitmap" bytea NULL, | ||
723 | "Name" varchar(255) NULL, | ||
724 | "Description" varchar(255) NULL, | ||
725 | "OwnerUUID" uuid NULL, | ||
726 | "IsGroupOwned" boolean NULL, | ||
727 | "Area" int NULL, | ||
728 | "AuctionID" int NULL, | ||
729 | "Category" int NULL, | ||
730 | "ClaimDate" int NULL, | ||
731 | "ClaimPrice" int NULL, | ||
732 | "GroupUUID" uuid NULL, | ||
733 | "SalePrice" int NULL, | ||
734 | "LandStatus" int NULL, | ||
735 | "LandFlags" int NULL, | ||
736 | "LandingType" int NULL, | ||
737 | "MediaAutoScale" int NULL, | ||
738 | "MediaTextureUUID" uuid NULL, | ||
739 | "MediaURL" varchar(255) NULL, | ||
740 | "MusicURL" varchar(255) NULL, | ||
741 | "PassHours" double precision NULL, | ||
742 | "PassPrice" int NULL, | ||
743 | "SnapshotUUID" uuid NULL, | ||
744 | "UserLocationX" double precision NULL, | ||
745 | "UserLocationY" double precision NULL, | ||
746 | "UserLocationZ" double precision NULL, | ||
747 | "UserLookAtX" double precision NULL, | ||
748 | "UserLookAtY" double precision NULL, | ||
749 | "UserLookAtZ" double precision NULL, | ||
750 | "AuthbuyerID" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
751 | "OtherCleanTime" int NOT NULL DEFAULT ((0)), | ||
752 | "Dwell" int NOT NULL DEFAULT ((0)) | ||
753 | ); | ||
754 | |||
755 | INSERT INTO Tmp_land ("UUID", "RegionUUID", "LocalLandID", "Bitmap", "Name", "Description", "OwnerUUID", "IsGroupOwned", "Area", "AuctionID", "Category", "ClaimDate", "ClaimPrice", "GroupUUID", "SalePrice", "LandStatus", "LandFlags", "LandingType", "MediaAutoScale", "MediaTextureUUID", "MediaURL", "MusicURL", "PassHours", "PassPrice", "SnapshotUUID", "UserLocationX", "UserLocationY", "UserLocationZ", "UserLookAtX", "UserLookAtY", "UserLookAtZ", "AuthbuyerID", "OtherCleanTime", "Dwell") | ||
756 | SELECT cast("UUID" as uuid), cast("RegionUUID" as uuid), "LocalLandID", "Bitmap", "Name", "Description", cast("OwnerUUID" as uuid), "IsGroupOwned", "Area", "AuctionID", "Category", "ClaimDate", "ClaimPrice", cast("GroupUUID" as uuid), "SalePrice", "LandStatus", "LandFlags", "LandingType", "MediaAutoScale", cast("MediaTextureUUID" as uuid), "MediaURL", "MusicURL", "PassHours", "PassPrice", cast("SnapshotUUID" as uuid), "UserLocationX", "UserLocationY", "UserLocationZ", "UserLookAtX", "UserLookAtY", "UserLookAtZ", cast("AuthbuyerID" as uuid), "OtherCleanTime", "Dwell" | ||
757 | FROM land ; | ||
758 | |||
759 | DROP TABLE land; | ||
760 | |||
761 | alter table Tmp_land rename to land; | ||
762 | |||
763 | ALTER TABLE land ADD CONSTRAINT | ||
764 | PK__land__65A475E71BFD2C07 PRIMARY KEY | ||
765 | ( | ||
766 | "UUID" | ||
767 | ); | ||
768 | |||
769 | Create index on land (lower("Name")); | ||
770 | |||
771 | COMMIT; | ||
772 | |||
773 | |||
774 | |||
775 | :VERSION 18 | ||
776 | |||
777 | BEGIN TRANSACTION; | ||
778 | |||
779 | CREATE TABLE Tmp_landaccesslist | ||
780 | ( | ||
781 | "LandUUID" uuid NULL, | ||
782 | "AccessUUID" uuid NULL, | ||
783 | "Flags" int NULL | ||
784 | ); | ||
785 | |||
786 | INSERT INTO Tmp_landaccesslist ("LandUUID", "AccessUUID", "Flags") | ||
787 | SELECT cast("LandUUID" as uuid), cast("AccessUUID" as uuid), "Flags" | ||
788 | FROM landaccesslist ; | ||
789 | |||
790 | DROP TABLE landaccesslist; | ||
791 | |||
792 | alter table Tmp_landaccesslist rename to landaccesslist; | ||
793 | |||
794 | COMMIT; | ||
795 | |||
796 | |||
797 | |||
798 | :VERSION 19 | ||
799 | |||
800 | BEGIN TRANSACTION; | ||
801 | |||
802 | CREATE TABLE Tmp_regionban | ||
803 | ( | ||
804 | "regionUUID" uuid NOT NULL, | ||
805 | "bannedUUID" uuid NOT NULL, | ||
806 | "bannedIp" varchar(16) NOT NULL, | ||
807 | "bannedIpHostMask" varchar(16) NOT NULL | ||
808 | ); | ||
809 | |||
810 | INSERT INTO Tmp_regionban ("regionUUID", "bannedUUID", "bannedIp", "bannedIpHostMask") | ||
811 | SELECT cast("regionUUID" as uuid), cast("bannedUUID" as uuid), "bannedIp", "bannedIpHostMask" | ||
812 | FROM regionban ; | ||
813 | |||
814 | DROP TABLE regionban; | ||
815 | |||
816 | alter table Tmp_regionban rename to regionban; | ||
817 | |||
818 | COMMIT; | ||
819 | |||
820 | |||
821 | :VERSION 20 | ||
822 | |||
823 | BEGIN TRANSACTION; | ||
824 | |||
825 | CREATE TABLE Tmp_regionsettings | ||
826 | ( | ||
827 | "regionUUID" uuid NOT NULL, | ||
828 | "block_terraform" boolean NOT NULL, | ||
829 | "block_fly" boolean NOT NULL, | ||
830 | "allow_damage" boolean NOT NULL, | ||
831 | "restrict_pushing" boolean NOT NULL, | ||
832 | "allow_land_resell" boolean NOT NULL, | ||
833 | "allow_land_join_divide" boolean NOT NULL, | ||
834 | "block_show_in_search" boolean NOT NULL, | ||
835 | "agent_limit" int NOT NULL, | ||
836 | "object_bonus" double precision NOT NULL, | ||
837 | "maturity" int NOT NULL, | ||
838 | "disable_scripts" boolean NOT NULL, | ||
839 | "disable_collisions" boolean NOT NULL, | ||
840 | "disable_physics" boolean NOT NULL, | ||
841 | "terrain_texture_1" uuid NOT NULL, | ||
842 | "terrain_texture_2" uuid NOT NULL, | ||
843 | "terrain_texture_3" uuid NOT NULL, | ||
844 | "terrain_texture_4" uuid NOT NULL, | ||
845 | "elevation_1_nw" double precision NOT NULL, | ||
846 | "elevation_2_nw" double precision NOT NULL, | ||
847 | "elevation_1_ne" double precision NOT NULL, | ||
848 | "elevation_2_ne" double precision NOT NULL, | ||
849 | "elevation_1_se" double precision NOT NULL, | ||
850 | "elevation_2_se" double precision NOT NULL, | ||
851 | "elevation_1_sw" double precision NOT NULL, | ||
852 | "elevation_2_sw" double precision NOT NULL, | ||
853 | "water_height" double precision NOT NULL, | ||
854 | "terrain_raise_limit" double precision NOT NULL, | ||
855 | "terrain_lower_limit" double precision NOT NULL, | ||
856 | "use_estate_sun" boolean NOT NULL, | ||
857 | "fixed_sun" boolean NOT NULL, | ||
858 | "sun_position" double precision NOT NULL, | ||
859 | "covenant" uuid NULL DEFAULT (NULL), | ||
860 | "Sandbox" boolean NOT NULL, | ||
861 | "sunvectorx" double precision NOT NULL DEFAULT ((0)), | ||
862 | "sunvectory" double precision NOT NULL DEFAULT ((0)), | ||
863 | "sunvectorz" double precision NOT NULL DEFAULT ((0)) | ||
864 | ); | ||
865 | |||
866 | INSERT INTO Tmp_regionsettings ("regionUUID", "block_terraform", "block_fly", "allow_damage", "restrict_pushing", "allow_land_resell", "allow_land_join_divide", "block_show_in_search", "agent_limit", "object_bonus", "maturity", "disable_scripts", "disable_collisions", "disable_physics", "terrain_texture_1", "terrain_texture_2", "terrain_texture_3", "terrain_texture_4", "elevation_1_nw", "elevation_2_nw", "elevation_1_ne", "elevation_2_ne", "elevation_1_se", "elevation_2_se", "elevation_1_sw", "elevation_2_sw", "water_height", "terrain_raise_limit", "terrain_lower_limit", "use_estate_sun", "fixed_sun", "sun_position", "covenant", "Sandbox", "sunvectorx", "sunvectory", "sunvectorz") | ||
867 | SELECT cast("regionUUID" as uuid), "block_terraform", "block_fly", "allow_damage", "restrict_pushing", "allow_land_resell", "allow_land_join_divide", "block_show_in_search", "agent_limit", "object_bonus", "maturity", "disable_scripts", "disable_collisions", "disable_physics", cast("terrain_texture_1" as uuid), cast("terrain_texture_2" as uuid), cast("terrain_texture_3" as uuid), cast("terrain_texture_4" as uuid), "elevation_1_nw", "elevation_2_nw", "elevation_1_ne", "elevation_2_ne", "elevation_1_se", "elevation_2_se", "elevation_1_sw", "elevation_2_sw", "water_height", "terrain_raise_limit", "terrain_lower_limit", "use_estate_sun", "fixed_sun", "sun_position", cast("covenant" as uuid), "Sandbox", "sunvectorx", "sunvectory", "sunvectorz" | ||
868 | FROM regionsettings ; | ||
869 | |||
870 | DROP TABLE regionsettings; | ||
871 | |||
872 | alter table Tmp_regionsettings rename to regionsettings; | ||
873 | |||
874 | ALTER TABLE regionsettings ADD CONSTRAINT | ||
875 | PK__regionse__5B35159D21B6055D PRIMARY KEY | ||
876 | ( | ||
877 | "regionUUID" | ||
878 | ); | ||
879 | |||
880 | COMMIT; | ||
881 | |||
882 | |||
883 | :VERSION 21 | ||
884 | |||
885 | BEGIN TRANSACTION; | ||
886 | |||
887 | ALTER TABLE prims ADD "PassTouches" boolean not null default false; | ||
888 | |||
889 | COMMIT; | ||
890 | |||
891 | |||
892 | :VERSION 22 | ||
893 | |||
894 | BEGIN TRANSACTION; | ||
895 | |||
896 | ALTER TABLE regionsettings ADD "loaded_creation_date" varchar(20) ; | ||
897 | ALTER TABLE regionsettings ADD "loaded_creation_time" varchar(20) ; | ||
898 | ALTER TABLE regionsettings ADD "loaded_creation_id" varchar(64) ; | ||
899 | |||
900 | COMMIT; | ||
901 | |||
902 | :VERSION 23 | ||
903 | |||
904 | BEGIN TRANSACTION; | ||
905 | |||
906 | ALTER TABLE regionsettings DROP COLUMN "loaded_creation_date"; | ||
907 | ALTER TABLE regionsettings DROP COLUMN "loaded_creation_time"; | ||
908 | ALTER TABLE regionsettings ADD "loaded_creation_datetime" int NOT NULL default 0; | ||
909 | |||
910 | COMMIT; | ||
911 | |||
912 | :VERSION 24 | ||
913 | |||
914 | BEGIN TRANSACTION; | ||
915 | |||
916 | ALTER TABLE prims ADD "MediaURL" varchar(255); | ||
917 | ALTER TABLE primshapes ADD "Media" TEXT NULL; | ||
918 | |||
919 | COMMIT; | ||
920 | |||
921 | :VERSION 25 | ||
922 | |||
923 | BEGIN TRANSACTION; | ||
924 | CREATE TABLE regionwindlight ( | ||
925 | "region_id" varchar(36) NOT NULL DEFAULT '000000-0000-0000-0000-000000000000' PRIMARY KEY, | ||
926 | "water_color_r" double precision NOT NULL DEFAULT '4.000000', | ||
927 | water_color_g double precision NOT NULL DEFAULT '38.000000', | ||
928 | water_color_b double precision NOT NULL DEFAULT '64.000000', | ||
929 | water_fog_density_exponent double precision NOT NULL DEFAULT '4.0', | ||
930 | underwater_fog_modifier double precision NOT NULL DEFAULT '0.25', | ||
931 | reflection_wavelet_scale_1 double precision NOT NULL DEFAULT '2.0', | ||
932 | reflection_wavelet_scale_2 double precision NOT NULL DEFAULT '2.0', | ||
933 | reflection_wavelet_scale_3 double precision NOT NULL DEFAULT '2.0', | ||
934 | fresnel_scale double precision NOT NULL DEFAULT '0.40', | ||
935 | fresnel_offset double precision NOT NULL DEFAULT '0.50', | ||
936 | refract_scale_above double precision NOT NULL DEFAULT '0.03', | ||
937 | refract_scale_below double precision NOT NULL DEFAULT '0.20', | ||
938 | blur_multiplier double precision NOT NULL DEFAULT '0.040', | ||
939 | big_wave_direction_x double precision NOT NULL DEFAULT '1.05', | ||
940 | big_wave_direction_y double precision NOT NULL DEFAULT '-0.42', | ||
941 | little_wave_direction_x double precision NOT NULL DEFAULT '1.11', | ||
942 | little_wave_direction_y double precision NOT NULL DEFAULT '-1.16', | ||
943 | normal_map_texture varchar(36) NOT NULL DEFAULT '822ded49-9a6c-f61c-cb89-6df54f42cdf4', | ||
944 | horizon_r double precision NOT NULL DEFAULT '0.25', | ||
945 | horizon_g double precision NOT NULL DEFAULT '0.25', | ||
946 | horizon_b double precision NOT NULL DEFAULT '0.32', | ||
947 | horizon_i double precision NOT NULL DEFAULT '0.32', | ||
948 | haze_horizon double precision NOT NULL DEFAULT '0.19', | ||
949 | blue_density_r double precision NOT NULL DEFAULT '0.12', | ||
950 | blue_density_g double precision NOT NULL DEFAULT '0.22', | ||
951 | blue_density_b double precision NOT NULL DEFAULT '0.38', | ||
952 | blue_density_i double precision NOT NULL DEFAULT '0.38', | ||
953 | haze_density double precision NOT NULL DEFAULT '0.70', | ||
954 | density_multiplier double precision NOT NULL DEFAULT '0.18', | ||
955 | distance_multiplier double precision NOT NULL DEFAULT '0.8', | ||
956 | max_altitude int NOT NULL DEFAULT '1605', | ||
957 | sun_moon_color_r double precision NOT NULL DEFAULT '0.24', | ||
958 | sun_moon_color_g double precision NOT NULL DEFAULT '0.26', | ||
959 | sun_moon_color_b double precision NOT NULL DEFAULT '0.30', | ||
960 | sun_moon_color_i double precision NOT NULL DEFAULT '0.30', | ||
961 | sun_moon_position double precision NOT NULL DEFAULT '0.317', | ||
962 | ambient_r double precision NOT NULL DEFAULT '0.35', | ||
963 | ambient_g double precision NOT NULL DEFAULT '0.35', | ||
964 | ambient_b double precision NOT NULL DEFAULT '0.35', | ||
965 | ambient_i double precision NOT NULL DEFAULT '0.35', | ||
966 | east_angle double precision NOT NULL DEFAULT '0.00', | ||
967 | sun_glow_focus double precision NOT NULL DEFAULT '0.10', | ||
968 | sun_glow_size double precision NOT NULL DEFAULT '1.75', | ||
969 | scene_gamma double precision NOT NULL DEFAULT '1.00', | ||
970 | star_brightness double precision NOT NULL DEFAULT '0.00', | ||
971 | cloud_color_r double precision NOT NULL DEFAULT '0.41', | ||
972 | cloud_color_g double precision NOT NULL DEFAULT '0.41', | ||
973 | cloud_color_b double precision NOT NULL DEFAULT '0.41', | ||
974 | cloud_color_i double precision NOT NULL DEFAULT '0.41', | ||
975 | cloud_x double precision NOT NULL DEFAULT '1.00', | ||
976 | cloud_y double precision NOT NULL DEFAULT '0.53', | ||
977 | cloud_density double precision NOT NULL DEFAULT '1.00', | ||
978 | cloud_coverage double precision NOT NULL DEFAULT '0.27', | ||
979 | cloud_scale double precision NOT NULL DEFAULT '0.42', | ||
980 | cloud_detail_x double precision NOT NULL DEFAULT '1.00', | ||
981 | cloud_detail_y double precision NOT NULL DEFAULT '0.53', | ||
982 | cloud_detail_density double precision NOT NULL DEFAULT '0.12', | ||
983 | cloud_scroll_x double precision NOT NULL DEFAULT '0.20', | ||
984 | cloud_scroll_x_lock smallint NOT NULL DEFAULT '0', | ||
985 | cloud_scroll_y double precision NOT NULL DEFAULT '0.01', | ||
986 | cloud_scroll_y_lock smallint NOT NULL DEFAULT '0', | ||
987 | draw_classic_clouds smallint NOT NULL DEFAULT '1' | ||
988 | ); | ||
989 | |||
990 | COMMIT; | ||
991 | |||
992 | :VERSION 26 | ||
993 | |||
994 | BEGIN TRANSACTION; | ||
995 | |||
996 | ALTER TABLE regionsettings ADD "map_tile_ID" CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; | ||
997 | |||
998 | COMMIT; | ||
999 | |||
1000 | :VERSION 27 #--------------------- | ||
1001 | |||
1002 | BEGIN TRANSACTION; | ||
1003 | ALTER TABLE land ADD "MediaType" VARCHAR(32) NOT NULL DEFAULT 'none/none' ; | ||
1004 | ALTER TABLE land ADD "MediaDescription" VARCHAR(255) NOT NULL DEFAULT ''; | ||
1005 | ALTER TABLE land ADD "MediaSize" VARCHAR(16) NOT NULL DEFAULT '0,0'; | ||
1006 | ALTER TABLE land ADD "MediaLoop" boolean NOT NULL DEFAULT false; | ||
1007 | ALTER TABLE land ADD "ObscureMusic" boolean NOT NULL DEFAULT false; | ||
1008 | ALTER TABLE land ADD "ObscureMedia" boolean NOT NULL DEFAULT false; | ||
1009 | COMMIT; | ||
1010 | |||
1011 | :VERSION 28 #--------------------- | ||
1012 | |||
1013 | BEGIN TRANSACTION; | ||
1014 | |||
1015 | ALTER TABLE prims | ||
1016 | alter column "CreatorID" set DEFAULT '00000000-0000-0000-0000-000000000000' ; | ||
1017 | |||
1018 | ALTER TABLE prims ALTER COLUMN "CreatorID" set NOT NULL; | ||
1019 | |||
1020 | ALTER TABLE primitems | ||
1021 | alter column "creatorID" set DEFAULT '00000000-0000-0000-0000-000000000000' ; | ||
1022 | |||
1023 | ALTER TABLE primitems ALTER COLUMN "creatorID" set NOT NULL; | ||
1024 | |||
1025 | COMMIT; | ||
1026 | |||
1027 | :VERSION 29 #----------------- Region Covenant changed time | ||
1028 | |||
1029 | BEGIN TRANSACTION; | ||
1030 | |||
1031 | ALTER TABLE regionsettings ADD "covenant_datetime" int NOT NULL default 0; | ||
1032 | |||
1033 | COMMIT; | ||
1034 | |||
1035 | :VERSION 30 #------------------Migrate "creatorID" storage to varchars instead of UUIDs for HG support | ||
1036 | |||
1037 | BEGIN TRANSACTION; | ||
1038 | |||
1039 | alter table prims rename column "CreatorID" to "CreatorIDOld"; | ||
1040 | alter table primitems rename column "creatorID" to "creatorIDOld"; | ||
1041 | |||
1042 | COMMIT; | ||
1043 | |||
1044 | :VERSION 31 #--------------------- | ||
1045 | |||
1046 | BEGIN TRANSACTION; | ||
1047 | |||
1048 | ALTER TABLE prims ADD "CreatorID" varchar(255); | ||
1049 | ALTER TABLE primitems ADD "creatorID" varchar(255); | ||
1050 | |||
1051 | COMMIT; | ||
1052 | |||
1053 | :VERSION 32 #--------------------- | ||
1054 | |||
1055 | BEGIN TRANSACTION; | ||
1056 | |||
1057 | UPDATE prims SET "CreatorID" = cast("CreatorIDOld" as varchar(255)); | ||
1058 | UPDATE primitems SET "creatorID" = cast("creatorIDOld" as varchar(255)); | ||
1059 | |||
1060 | COMMIT; | ||
1061 | |||
1062 | :VERSION 33 #--------------------- | ||
1063 | |||
1064 | BEGIN TRANSACTION; | ||
1065 | |||
1066 | ALTER TABLE prims alter column "CreatorID" set default '00000000-0000-0000-0000-000000000000' ; | ||
1067 | |||
1068 | ALTER TABLE prims ALTER COLUMN "CreatorID" set NOT NULL; | ||
1069 | |||
1070 | ALTER TABLE primitems alter column "creatorID" set DEFAULT '00000000-0000-0000-0000-000000000000' ; | ||
1071 | |||
1072 | ALTER TABLE primitems ALTER COLUMN "creatorID" set NOT NULL; | ||
1073 | |||
1074 | COMMIT; | ||
1075 | |||
1076 | :VERSION 34 #--------------- Telehub support | ||
1077 | |||
1078 | BEGIN TRANSACTION; | ||
1079 | |||
1080 | CREATE TABLE spawn_points( | ||
1081 | "RegionUUID" uuid NOT NULL PRIMARY KEY, | ||
1082 | "Yaw" double precision NOT NULL, | ||
1083 | "Pitch" double precision NOT NULL, | ||
1084 | "Distance" double precision NOT NULL | ||
1085 | ); | ||
1086 | |||
1087 | ALTER TABLE regionsettings ADD "TelehubObject" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; | ||
1088 | |||
1089 | COMMIT; | ||
1090 | |||
1091 | :VERSION 35 #---------------- Parcels for sale | ||
1092 | |||
1093 | BEGIN TRANSACTION; | ||
1094 | |||
1095 | ALTER TABLE regionsettings ADD "parcel_tile_ID" uuid NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000'; | ||
1096 | |||
1097 | COMMIT; | ||
1098 | |||
1099 | :VERSION 36 #---------------- Timed bans/access | ||
1100 | |||
1101 | BEGIN TRANSACTION; | ||
1102 | |||
1103 | ALTER TABLE landaccesslist ADD "Expires" integer NOT NULL DEFAULT 0; | ||
1104 | |||
1105 | COMMIT; | ||
1106 | |||
1107 | :VERSION 37 #---------------- Environment Settings | ||
1108 | |||
1109 | BEGIN TRANSACTION; | ||
1110 | |||
1111 | CREATE TABLE regionenvironment( | ||
1112 | "region_id" uuid NOT NULL primary key, | ||
1113 | "llsd_settings" varchar NOT NULL | ||
1114 | ); | ||
1115 | |||
1116 | COMMIT; | ||
1117 | |||
1118 | :VERSION 38 #---------------- Dynamic attributes | ||
1119 | |||
1120 | BEGIN TRANSACTION; | ||
1121 | |||
1122 | ALTER TABLE prims ADD "DynAttrs" TEXT; | ||
1123 | |||
1124 | COMMIT; | ||
1125 | |||
1126 | :VERSION 39 #---------------- Extra physics params | ||
1127 | |||
1128 | BEGIN TRANSACTION; | ||
1129 | |||
1130 | ALTER TABLE prims ADD "PhysicsShapeType" smallint NOT NULL default '0'; | ||
1131 | ALTER TABLE prims ADD "Density" double precision NOT NULL default '1000'; | ||
1132 | ALTER TABLE prims ADD "GravityModifier" double precision NOT NULL default '1'; | ||
1133 | ALTER TABLE prims ADD "Friction" double precision NOT NULL default '0.6'; | ||
1134 | ALTER TABLE prims ADD "Restitution" double precision NOT NULL default '0.5'; | ||
1135 | |||
1136 | COMMIT; | ||
1137 | |||
1138 | :VERSION 40 #-- regionwindlight changed type from smallint to bool | ||
1139 | |||
1140 | BEGIN TRANSACTION; | ||
1141 | |||
1142 | ALTER TABLE regionwindlight ALTER COLUMN cloud_scroll_x_lock DROP DEFAULT; | ||
1143 | ALTER TABLE regionwindlight ALTER cloud_scroll_x_lock TYPE bool USING CASE WHEN cloud_scroll_x_lock=0 THEN FALSE ELSE TRUE END; | ||
1144 | ALTER TABLE regionwindlight ALTER COLUMN cloud_scroll_x_lock SET DEFAULT FALSE; | ||
1145 | |||
1146 | ALTER TABLE regionwindlight ALTER COLUMN cloud_scroll_y_lock DROP DEFAULT; | ||
1147 | ALTER TABLE regionwindlight ALTER cloud_scroll_y_lock TYPE bool USING CASE WHEN cloud_scroll_y_lock=0 THEN FALSE ELSE TRUE END; | ||
1148 | ALTER TABLE regionwindlight ALTER COLUMN cloud_scroll_y_lock SET DEFAULT FALSE; | ||
1149 | |||
1150 | ALTER TABLE regionwindlight ALTER COLUMN draw_classic_clouds DROP DEFAULT; | ||
1151 | ALTER TABLE regionwindlight ALTER draw_classic_clouds TYPE bool USING CASE WHEN draw_classic_clouds=0 THEN FALSE ELSE TRUE END; | ||
1152 | ALTER TABLE regionwindlight ALTER COLUMN draw_classic_clouds SET DEFAULT FALSE; | ||
1153 | |||
1154 | COMMIT; | ||
1155 | |||
1156 | VERSION 41 #-- Change Landlags to bigint | ||
1157 | |||
1158 | BEGIN TRANSACTION; | ||
1159 | |||
1160 | ALTER TABLE land ALTER "LandFlags" TYPE bigint; | ||
1161 | |||
1162 | COMMIT; | ||
diff --git a/OpenSim/Data/PGSQL/Resources/UserAccount.migrations b/OpenSim/Data/PGSQL/Resources/UserAccount.migrations new file mode 100644 index 0000000..c785463 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/UserAccount.migrations | |||
@@ -0,0 +1,51 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | CREATE TABLE UserAccounts ( | ||
4 | "PrincipalID" uuid NOT NULL Primary key, | ||
5 | "ScopeID" uuid NOT NULL, | ||
6 | "FirstName" varchar(64) NOT NULL, | ||
7 | "LastName" varchar(64) NOT NULL, | ||
8 | "Email" varchar(64) NULL, | ||
9 | "ServiceURLs" text NULL, | ||
10 | "Created" int default NULL | ||
11 | ); | ||
12 | |||
13 | |||
14 | :VERSION 2 | ||
15 | |||
16 | BEGIN TRANSACTION; | ||
17 | |||
18 | INSERT INTO UserAccounts ("PrincipalID", "ScopeID", "FirstName", "LastName", "Email", "ServiceURLs", "Created") | ||
19 | SELECT UUID AS "PrincipalID", '00000000-0000-0000-0000-000000000000' AS "ScopeID", | ||
20 | username AS "FirstName", | ||
21 | lastname AS "LastName", | ||
22 | email as "Email", ( | ||
23 | 'AssetServerURI=' + | ||
24 | userAssetURI + ' InventoryServerURI=' + userInventoryURI + ' GatewayURI= HomeURI=') AS "ServiceURLs", | ||
25 | created as "Created" FROM users; | ||
26 | |||
27 | COMMIT; | ||
28 | |||
29 | :VERSION 3 | ||
30 | |||
31 | BEGIN TRANSACTION; | ||
32 | |||
33 | CREATE UNIQUE INDEX "PrincipalID" ON UserAccounts("PrincipalID"); | ||
34 | CREATE INDEX "Email" ON UserAccounts("Email"); | ||
35 | CREATE INDEX "FirstName" ON UserAccounts("FirstName"); | ||
36 | CREATE INDEX "LastName" ON UserAccounts("LastName"); | ||
37 | CREATE INDEX Name ON UserAccounts("FirstName","LastName"); | ||
38 | |||
39 | COMMIT; | ||
40 | |||
41 | :VERSION 4 | ||
42 | |||
43 | BEGIN TRANSACTION; | ||
44 | |||
45 | ALTER TABLE UserAccounts ADD "UserLevel" integer NOT NULL DEFAULT 0; | ||
46 | ALTER TABLE UserAccounts ADD "UserFlags" integer NOT NULL DEFAULT 0; | ||
47 | ALTER TABLE UserAccounts ADD "UserTitle" varchar(64) NOT NULL DEFAULT ''; | ||
48 | |||
49 | COMMIT; | ||
50 | |||
51 | |||
diff --git a/OpenSim/Data/PGSQL/Resources/UserProfiles.migrations b/OpenSim/Data/PGSQL/Resources/UserProfiles.migrations new file mode 100644 index 0000000..a6bd8ca --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/UserProfiles.migrations | |||
@@ -0,0 +1,155 @@ | |||
1 | :VERSION 1 # ------------------------------- | ||
2 | |||
3 | begin; | ||
4 | |||
5 | CREATE TABLE classifieds ( | ||
6 | "classifieduuid" char(36) NOT NULL, | ||
7 | "creatoruuid" char(36) NOT NULL, | ||
8 | "creationdate" integer NOT NULL, | ||
9 | "expirationdate" integer NOT NULL, | ||
10 | "category" varchar(20) NOT NULL, | ||
11 | "name" varchar(255) NOT NULL, | ||
12 | "description" text NOT NULL, | ||
13 | "parceluuid" char(36) NOT NULL, | ||
14 | "parentestate" integer NOT NULL, | ||
15 | "snapshotuuid" char(36) NOT NULL, | ||
16 | "simname" varchar(255) NOT NULL, | ||
17 | "posglobal" varchar(255) NOT NULL, | ||
18 | "parcelname" varchar(255) NOT NULL, | ||
19 | "classifiedflags" integer NOT NULL, | ||
20 | "priceforlisting" integer NOT NULL, | ||
21 | constraint classifiedspk PRIMARY KEY ("classifieduuid") | ||
22 | ); | ||
23 | |||
24 | |||
25 | CREATE TABLE usernotes ( | ||
26 | "useruuid" varchar(36) NOT NULL, | ||
27 | "targetuuid" varchar(36) NOT NULL, | ||
28 | "notes" text NOT NULL, | ||
29 | constraint usernoteuk UNIQUE ("useruuid","targetuuid") | ||
30 | ); | ||
31 | |||
32 | |||
33 | CREATE TABLE userpicks ( | ||
34 | "pickuuid" varchar(36) NOT NULL, | ||
35 | "creatoruuid" varchar(36) NOT NULL, | ||
36 | "toppick" boolean NOT NULL, | ||
37 | "parceluuid" varchar(36) NOT NULL, | ||
38 | "name" varchar(255) NOT NULL, | ||
39 | "description" text NOT NULL, | ||
40 | "snapshotuuid" varchar(36) NOT NULL, | ||
41 | "user" varchar(255) NOT NULL, | ||
42 | "originalname" varchar(255) NOT NULL, | ||
43 | "simname" varchar(255) NOT NULL, | ||
44 | "posglobal" varchar(255) NOT NULL, | ||
45 | "sortorder" integer NOT NULL, | ||
46 | "enabled" boolean NOT NULL, | ||
47 | PRIMARY KEY ("pickuuid") | ||
48 | ); | ||
49 | |||
50 | |||
51 | CREATE TABLE userprofile ( | ||
52 | "useruuid" varchar(36) NOT NULL, | ||
53 | "profilePartner" varchar(36) NOT NULL, | ||
54 | "profileAllowPublish" bytea NOT NULL, | ||
55 | "profileMaturePublish" bytea NOT NULL, | ||
56 | "profileURL" varchar(255) NOT NULL, | ||
57 | "profileWantToMask" integer NOT NULL, | ||
58 | "profileWantToText" text NOT NULL, | ||
59 | "profileSkillsMask" integer NOT NULL, | ||
60 | "profileSkillsText" text NOT NULL, | ||
61 | "profileLanguages" text NOT NULL, | ||
62 | "profileImage" varchar(36) NOT NULL, | ||
63 | "profileAboutText" text NOT NULL, | ||
64 | "profileFirstImage" varchar(36) NOT NULL, | ||
65 | "profileFirstText" text NOT NULL, | ||
66 | PRIMARY KEY ("useruuid") | ||
67 | ); | ||
68 | |||
69 | commit; | ||
70 | |||
71 | :VERSION 2 # ------------------------------- | ||
72 | |||
73 | begin; | ||
74 | CREATE TABLE userdata ( | ||
75 | "UserId" char(36) NOT NULL, | ||
76 | "TagId" varchar(64) NOT NULL, | ||
77 | "DataKey" varchar(255), | ||
78 | "DataVal" varchar(255), | ||
79 | PRIMARY KEY ("UserId","TagId") | ||
80 | ); | ||
81 | |||
82 | commit; | ||
83 | |||
84 | :VERSION 3 # ------------------------------- | ||
85 | begin; | ||
86 | CREATE TABLE usersettings ( | ||
87 | "useruuid" char(36) NOT NULL, | ||
88 | "imviaemail" bytea NOT NULL, | ||
89 | "visible" bytea NOT NULL, | ||
90 | PRIMARY KEY ("useruuid") | ||
91 | ); | ||
92 | commit; | ||
93 | |||
94 | :VERSION 4 | ||
95 | |||
96 | BEGIN; | ||
97 | |||
98 | -- Classifieds | ||
99 | ALTER TABLE classifieds DROP CONSTRAINT classifiedspk; | ||
100 | ALTER TABLE classifieds ALTER COLUMN classifieduuid SET DATA TYPE uuid using classifieduuid::uuid; | ||
101 | ALTER TABLE classifieds ALTER COLUMN creatoruuid SET DATA TYPE uuid using creatoruuid::uuid; | ||
102 | ALTER TABLE classifieds ALTER COLUMN parceluuid SET DATA TYPE uuid using parceluuid::uuid; | ||
103 | ALTER TABLE classifieds ALTER COLUMN snapshotuuid SET DATA TYPE uuid using snapshotuuid::uuid; | ||
104 | ALTER TABLE classifieds ADD CONSTRAINT classifiedspk PRIMARY KEY (classifieduuid); | ||
105 | |||
106 | -- Notes | ||
107 | ALTER TABLE usernotes DROP CONSTRAINT usernoteuk; | ||
108 | ALTER TABLE usernotes ALTER COLUMN useruuid SET DATA TYPE uuid USING useruuid::uuid; | ||
109 | ALTER TABLE usernotes ALTER COLUMN targetuuid SET DATA TYPE uuid USING targetuuid::uuid; | ||
110 | ALTER TABLE usernotes ADD CONSTRAINT usernoteuk UNIQUE (useruuid,targetuuid); | ||
111 | |||
112 | |||
113 | -- Userpicks | ||
114 | ALTER TABLE userpicks DROP CONSTRAINT userpicks_pkey; | ||
115 | ALTER TABLE userpicks ALTER COLUMN pickuuid SET DATA TYPE uuid USING pickuuid::uuid; | ||
116 | ALTER TABLE userpicks ALTER COLUMN creatoruuid SET DATA TYPE uuid USING creatoruuid::uuid; | ||
117 | ALTER TABLE userpicks ALTER COLUMN parceluuid SET DATA TYPE uuid USING parceluuid::uuid; | ||
118 | ALTER TABLE userpicks ALTER COLUMN parceluuid SET DATA TYPE uuid USING parceluuid::uuid; | ||
119 | ALTER TABLE userpicks ADD PRIMARY KEY (pickuuid); | ||
120 | |||
121 | -- Userprofile | ||
122 | ALTER TABLE userprofile DROP CONSTRAINT userprofile_pkey; | ||
123 | ALTER TABLE userprofile ALTER COLUMN useruuid SET DATA TYPE uuid USING useruuid::uuid; | ||
124 | ALTER TABLE userprofile ALTER COLUMN "profilePartner" SET DATA TYPE uuid USING "profilePartner"::uuid; | ||
125 | -- Force column conversions | ||
126 | ALTER TABLE userprofile ALTER COLUMN "profileAllowPublish" SET DATA TYPE boolean USING CASE WHEN false THEN false ELSE true END; | ||
127 | ALTER TABLE userprofile ALTER COLUMN "profileMaturePublish" SET DATA TYPE boolean USING CASE WHEN false THEN false ELSE true END; | ||
128 | ALTER TABLE userprofile ALTER COLUMN "profileImage" SET DATA TYPE uuid USING "profileImage"::uuid; | ||
129 | ALTER TABLE userprofile ALTER COLUMN "profileFirstImage" SET DATA TYPE uuid USING "profileFirstImage"::uuid; | ||
130 | ALTER TABLE userprofile ADD PRIMARY KEY (useruuid); | ||
131 | |||
132 | -- Userdata | ||
133 | ALTER TABLE userdata DROP CONSTRAINT userdata_pkey; | ||
134 | ALTER TABLE userdata ALTER COLUMN "UserId" SET DATA TYPE uuid USING "UserId"::uuid; | ||
135 | ALTER TABLE userdata ALTER COLUMN "UserId" SET DATA TYPE uuid USING "UserId"::uuid; | ||
136 | ALTER TABLE userdata ADD PRIMARY KEY ("UserId","TagId"); | ||
137 | |||
138 | |||
139 | -- Usersettings | ||
140 | ALTER TABLE usersettings DROP CONSTRAINT usersettings_pkey; | ||
141 | ALTER TABLE usersettings ALTER COLUMN useruuid SET DATA TYPE uuid USING useruuid::uuid; | ||
142 | ALTER TABLE usersettings ALTER COLUMN visible SET DATA TYPE boolean USING CASE WHEN false THEN false ELSE true END; | ||
143 | ALTER TABLE usersettings ADD COLUMN email varchar(254) NOT NULL; | ||
144 | ALTER TABLE usersettings ADD PRIMARY KEY (useruuid); | ||
145 | |||
146 | COMMIT; | ||
147 | |||
148 | |||
149 | :VERSION 5 # ------------------------------- | ||
150 | |||
151 | BEGIN; | ||
152 | |||
153 | ALTER TABLE usersettings ALTER COLUMN imviaemail SET DATA TYPE boolean USING CASE WHEN false THEN false ELSE true END; | ||
154 | |||
155 | COMMIT; \ No newline at end of file | ||
diff --git a/OpenSim/Data/PGSQL/Resources/UserStore.migrations b/OpenSim/Data/PGSQL/Resources/UserStore.migrations new file mode 100644 index 0000000..974d489 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/UserStore.migrations | |||
@@ -0,0 +1,404 @@ | |||
1 | :VERSION 1 | ||
2 | |||
3 | CREATE TABLE users ( | ||
4 | "UUID" varchar(36) NOT NULL default '' Primary Key, | ||
5 | "username" varchar(32) NOT NULL, | ||
6 | "lastname" varchar(32) NOT NULL, | ||
7 | "passwordHash" varchar(32) NOT NULL, | ||
8 | "passwordSalt" varchar(32) NOT NULL, | ||
9 | "homeRegion" bigint default NULL, | ||
10 | "homeLocationX" double precision default NULL, | ||
11 | "homeLocationY" double precision default NULL, | ||
12 | "homeLocationZ" double precision default NULL, | ||
13 | "homeLookAtX" double precision default NULL, | ||
14 | "homeLookAtY" double precision default NULL, | ||
15 | "homeLookAtZ" double precision default NULL, | ||
16 | "created" int NOT NULL, | ||
17 | "lastLogin" int NOT NULL, | ||
18 | "userInventoryURI" varchar(255) default NULL, | ||
19 | "userAssetURI" varchar(255) default NULL, | ||
20 | "profileCanDoMask" int default NULL, | ||
21 | "profileWantDoMask" int default NULL, | ||
22 | "profileAboutText" text, | ||
23 | "profileFirstText" text, | ||
24 | "profileImage" varchar(36) default NULL, | ||
25 | "profileFirstImage" varchar(36) default NULL, | ||
26 | "webLoginKey" varchar(36) default NULL | ||
27 | ); | ||
28 | |||
29 | CREATE INDEX "usernames" ON users | ||
30 | ( | ||
31 | "username" ASC, | ||
32 | "lastname" ASC | ||
33 | ); | ||
34 | |||
35 | |||
36 | CREATE TABLE agents ( | ||
37 | "UUID" varchar(36) NOT NULL Primary Key, | ||
38 | "sessionID" varchar(36) NOT NULL, | ||
39 | "secureSessionID" varchar(36) NOT NULL, | ||
40 | "agentIP" varchar(16) NOT NULL, | ||
41 | "agentPort" int NOT NULL, | ||
42 | "agentOnline" smallint NOT NULL, | ||
43 | "loginTime" int NOT NULL, | ||
44 | "logoutTime" int NOT NULL, | ||
45 | "currentRegion" varchar(36) NOT NULL, | ||
46 | "currentHandle" bigint NOT NULL, | ||
47 | "currentPos" varchar(64) NOT NULL | ||
48 | ); | ||
49 | |||
50 | CREATE INDEX session ON agents | ||
51 | ( | ||
52 | "sessionID" ASC | ||
53 | ); | ||
54 | |||
55 | CREATE INDEX ssession ON agents | ||
56 | ( | ||
57 | "secureSessionID" ASC | ||
58 | ); | ||
59 | |||
60 | |||
61 | CREATE TABLE userfriends( | ||
62 | "ownerID" varchar(50) NOT NULL, | ||
63 | "friendID" varchar(50) NOT NULL, | ||
64 | "friendPerms" varchar(50) NOT NULL, | ||
65 | "datetimestamp" varchar(50) NOT NULL | ||
66 | ); | ||
67 | |||
68 | CREATE TABLE avatarappearance ( | ||
69 | "Owner" varchar(36) NOT NULL primary key, | ||
70 | "Serial" int NOT NULL, | ||
71 | "Visual_Params" bytea NOT NULL, | ||
72 | "Texture" bytea NOT NULL, | ||
73 | "Avatar_Height" double precision NOT NULL, | ||
74 | "Body_Item" varchar(36) NOT NULL, | ||
75 | "Body_Asset" varchar(36) NOT NULL, | ||
76 | "Skin_Item" varchar(36) NOT NULL, | ||
77 | "Skin_Asset" varchar(36) NOT NULL, | ||
78 | "Hair_Item" varchar(36) NOT NULL, | ||
79 | "Hair_Asset" varchar(36) NOT NULL, | ||
80 | "Eyes_Item" varchar(36) NOT NULL, | ||
81 | "Eyes_Asset" varchar(36) NOT NULL, | ||
82 | "Shirt_Item" varchar(36) NOT NULL, | ||
83 | "Shirt_Asset" varchar(36) NOT NULL, | ||
84 | "Pants_Item" varchar(36) NOT NULL, | ||
85 | "Pants_Asset" varchar(36) NOT NULL, | ||
86 | "Shoes_Item" varchar(36) NOT NULL, | ||
87 | "Shoes_Asset" varchar(36) NOT NULL, | ||
88 | "Socks_Item" varchar(36) NOT NULL, | ||
89 | "Socks_Asset" varchar(36) NOT NULL, | ||
90 | "Jacket_Item" varchar(36) NOT NULL, | ||
91 | "Jacket_Asset" varchar(36) NOT NULL, | ||
92 | "Gloves_Item" varchar(36) NOT NULL, | ||
93 | "Gloves_Asset" varchar(36) NOT NULL, | ||
94 | "Undershirt_Item" varchar(36) NOT NULL, | ||
95 | "Undershirt_Asset" varchar(36) NOT NULL, | ||
96 | "Underpants_Item" varchar(36) NOT NULL, | ||
97 | "Underpants_Asset" varchar(36) NOT NULL, | ||
98 | "Skirt_Item" varchar(36) NOT NULL, | ||
99 | "Skirt_Asset" varchar(36) NOT NULL | ||
100 | ); | ||
101 | |||
102 | :VERSION 2 | ||
103 | |||
104 | BEGIN TRANSACTION; | ||
105 | |||
106 | ALTER TABLE users ADD "homeRegionID" varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000'; | ||
107 | ALTER TABLE users ADD "userFlags" int NOT NULL default 0; | ||
108 | ALTER TABLE users ADD "godLevel" int NOT NULL default 0; | ||
109 | ALTER TABLE users ADD "customType" varchar(32) not null default ''; | ||
110 | ALTER TABLE users ADD "partner" varchar(36) not null default '00000000-0000-0000-0000-000000000000'; | ||
111 | |||
112 | COMMIT; | ||
113 | |||
114 | |||
115 | :VERSION 3 | ||
116 | |||
117 | BEGIN TRANSACTION; | ||
118 | |||
119 | CREATE TABLE avatarattachments ( | ||
120 | "UUID" varchar(36) NOT NULL | ||
121 | , "attachpoint" int NOT NULL | ||
122 | , item varchar(36) NOT NULL | ||
123 | , asset varchar(36) NOT NULL); | ||
124 | |||
125 | CREATE INDEX IX_avatarattachments ON avatarattachments | ||
126 | ( | ||
127 | "UUID" | ||
128 | ); | ||
129 | |||
130 | COMMIT; | ||
131 | |||
132 | |||
133 | :VERSION 4 | ||
134 | |||
135 | BEGIN TRANSACTION; | ||
136 | |||
137 | CREATE TABLE Tmp_userfriends | ||
138 | ( | ||
139 | "ownerID" varchar(36) NOT NULL, | ||
140 | "friendID" varchar(36) NOT NULL, | ||
141 | "friendPerms" int NOT NULL, | ||
142 | "datetimestamp" int NOT NULL | ||
143 | ); | ||
144 | |||
145 | INSERT INTO Tmp_userfriends ("ownerID", "friendID", "friendPerms", "datetimestamp") | ||
146 | SELECT cast("ownerID" as varchar(36)), cast("friendID" as varchar(36)), cast("friendPerms" as int), cast("datetimestamp" as int) | ||
147 | FROM userfriends; | ||
148 | |||
149 | DROP TABLE userfriends; | ||
150 | |||
151 | alter table Tmp_userfriends rename to userfriends; | ||
152 | |||
153 | CREATE INDEX IX_userfriends_ownerID ON userfriends | ||
154 | ( | ||
155 | "ownerID" | ||
156 | ); | ||
157 | |||
158 | CREATE INDEX IX_userfriends_friendID ON userfriends | ||
159 | ( | ||
160 | "friendID" | ||
161 | ); | ||
162 | |||
163 | COMMIT; | ||
164 | |||
165 | |||
166 | :VERSION 5 | ||
167 | |||
168 | BEGIN TRANSACTION; | ||
169 | |||
170 | ALTER TABLE users add "email" varchar(250); | ||
171 | |||
172 | COMMIT; | ||
173 | |||
174 | |||
175 | :VERSION 6 | ||
176 | |||
177 | BEGIN TRANSACTION; | ||
178 | |||
179 | CREATE TABLE Tmp_users | ||
180 | ( | ||
181 | "UUID" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
182 | "username" varchar(32) NOT NULL, | ||
183 | "lastname" varchar(32) NOT NULL, | ||
184 | "passwordHash" varchar(32) NOT NULL, | ||
185 | "passwordSalt" varchar(32) NOT NULL, | ||
186 | "homeRegion" bigint NULL DEFAULT (NULL), | ||
187 | "homeLocationX" double precision NULL DEFAULT (NULL), | ||
188 | "homeLocationY" double precision NULL DEFAULT (NULL), | ||
189 | "homeLocationZ" double precision NULL DEFAULT (NULL), | ||
190 | "homeLookAtX" double precision NULL DEFAULT (NULL), | ||
191 | "homeLookAtY" double precision NULL DEFAULT (NULL), | ||
192 | "homeLookAtZ" double precision NULL DEFAULT (NULL), | ||
193 | "created" int NOT NULL, | ||
194 | "lastLogin" int NOT NULL, | ||
195 | "userInventoryURI" varchar(255) NULL DEFAULT (NULL), | ||
196 | "userAssetURI" varchar(255) NULL DEFAULT (NULL), | ||
197 | "profileCanDoMask" int NULL DEFAULT (NULL), | ||
198 | "profileWantDoMask" int NULL DEFAULT (NULL), | ||
199 | "profileAboutText" text NULL, | ||
200 | "profileFirstText" text NULL, | ||
201 | "profileImage" uuid NULL DEFAULT (NULL), | ||
202 | "profileFirstImage" uuid NULL DEFAULT (NULL), | ||
203 | "webLoginKey" uuid NULL DEFAULT (NULL), | ||
204 | "homeRegionID" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
205 | "userFlags" int NOT NULL DEFAULT ((0)), | ||
206 | "godLevel" int NOT NULL DEFAULT ((0)), | ||
207 | "customType" varchar(32) NOT NULL DEFAULT (''), | ||
208 | "partner" uuid NOT NULL DEFAULT ('00000000-0000-0000-0000-000000000000'), | ||
209 | email varchar(250) NULL | ||
210 | ); | ||
211 | |||
212 | INSERT INTO Tmp_users ("UUID", "username", "lastname", "passwordHash", "passwordSalt", "homeRegion", "homeLocationX", "homeLocationY", "homeLocationZ", "homeLookAtX", "homeLookAtY", "homeLookAtZ", "created", "lastLogin", "userInventoryURI", "userAssetURI", "profileCanDoMask", "profileWantDoMask", "profileAboutText", "profileFirstText", "profileImage", "profileFirstImage", "webLoginKey", "homeRegionID", "userFlags", "godLevel", "customType", "partner", email) | ||
213 | SELECT cast("UUID" as uuid), "username", "lastname", "passwordHash", "passwordSalt", "homeRegion", "homeLocationX", "homeLocationY", "homeLocationZ", "homeLookAtX", "homeLookAtY", "homeLookAtZ", "created", "lastLogin", "userInventoryURI", "userAssetURI", "profileCanDoMask", "profileWantDoMask", "profileAboutText", "profileFirstText", cast("profileImage" as uuid), cast("profileFirstImage" as uuid), cast("webLoginKey" as uuid), cast("homeRegionID" as uuid), "userFlags", "godLevel", "customType", cast("partner" as uuid), email | ||
214 | FROM users ; | ||
215 | |||
216 | DROP TABLE users; | ||
217 | |||
218 | alter table Tmp_users rename to users; | ||
219 | |||
220 | ALTER TABLE users ADD CONSTRAINT | ||
221 | PK__users__65A475E737A5467C PRIMARY KEY | ||
222 | ( | ||
223 | "UUID" | ||
224 | ); | ||
225 | |||
226 | CREATE INDEX "usernames" ON users | ||
227 | ( | ||
228 | "username", | ||
229 | "lastname" | ||
230 | ); | ||
231 | |||
232 | COMMIT; | ||
233 | |||
234 | |||
235 | :VERSION 7 | ||
236 | |||
237 | BEGIN TRANSACTION; | ||
238 | |||
239 | CREATE TABLE Tmp_agents | ||
240 | ( | ||
241 | "UUID" uuid NOT NULL, | ||
242 | "sessionID" uuid NOT NULL, | ||
243 | "secureSessionID" uuid NOT NULL, | ||
244 | "agentIP" varchar(16) NOT NULL, | ||
245 | "agentPort" int NOT NULL, | ||
246 | "agentOnline" smallint NOT NULL, | ||
247 | "loginTime" int NOT NULL, | ||
248 | "logoutTime" int NOT NULL, | ||
249 | "currentRegion" uuid NOT NULL, | ||
250 | "currentHandle" bigint NOT NULL, | ||
251 | "currentPos" varchar(64) NOT NULL | ||
252 | ); | ||
253 | |||
254 | INSERT INTO Tmp_agents ("UUID", "sessionID", "secureSessionID", "agentIP", "agentPort", "agentOnline", "loginTime", "logoutTime", "currentRegion", "currentHandle", "currentPos") | ||
255 | SELECT cast("UUID" as uuid), cast("sessionID" as uuid), cast("secureSessionID" as uuid), "agentIP", "agentPort", "agentOnline", "loginTime", "logoutTime", cast("currentRegion" as uuid), "currentHandle", "currentPos" | ||
256 | FROM agents ; | ||
257 | |||
258 | DROP TABLE agents; | ||
259 | |||
260 | alter table Tmp_agents rename to agents; | ||
261 | |||
262 | ALTER TABLE agents ADD CONSTRAINT | ||
263 | PK__agents__65A475E749C3F6B7 PRIMARY KEY | ||
264 | ( | ||
265 | "UUID" | ||
266 | ) ; | ||
267 | |||
268 | CREATE INDEX session ON agents | ||
269 | ( | ||
270 | "sessionID" | ||
271 | ); | ||
272 | |||
273 | CREATE INDEX ssession ON agents | ||
274 | ( | ||
275 | "secureSessionID" | ||
276 | ); | ||
277 | |||
278 | COMMIT; | ||
279 | |||
280 | |||
281 | :VERSION 8 | ||
282 | |||
283 | BEGIN TRANSACTION; | ||
284 | |||
285 | CREATE TABLE Tmp_userfriends | ||
286 | ( | ||
287 | "ownerID" uuid NOT NULL, | ||
288 | "friendID" uuid NOT NULL, | ||
289 | "friendPerms" int NOT NULL, | ||
290 | "datetimestamp" int NOT NULL | ||
291 | ); | ||
292 | |||
293 | INSERT INTO Tmp_userfriends ("ownerID", "friendID", "friendPerms", "datetimestamp") | ||
294 | SELECT cast("ownerID" as uuid), cast( "friendID" as uuid), "friendPerms", "datetimestamp" | ||
295 | FROM userfriends; | ||
296 | |||
297 | DROP TABLE userfriends; | ||
298 | |||
299 | alter table Tmp_userfriends rename to userfriends; | ||
300 | |||
301 | CREATE INDEX IX_userfriends_ownerID ON userfriends | ||
302 | ( | ||
303 | "ownerID" | ||
304 | ); | ||
305 | |||
306 | CREATE INDEX IX_userfriends_friendID ON userfriends | ||
307 | ( | ||
308 | "friendID" | ||
309 | ); | ||
310 | |||
311 | COMMIT; | ||
312 | |||
313 | |||
314 | :VERSION 9 | ||
315 | |||
316 | BEGIN TRANSACTION; | ||
317 | |||
318 | CREATE TABLE Tmp_avatarappearance | ||
319 | ( | ||
320 | "Owner" uuid NOT NULL, | ||
321 | "Serial" int NOT NULL, | ||
322 | "Visual_Params" bytea NOT NULL, | ||
323 | "Texture" bytea NOT NULL, | ||
324 | "Avatar_Height" double precision NOT NULL, | ||
325 | "Body_Item" uuid NOT NULL, | ||
326 | "Body_Asset" uuid NOT NULL, | ||
327 | "Skin_Item" uuid NOT NULL, | ||
328 | "Skin_Asset" uuid NOT NULL, | ||
329 | "Hair_Item" uuid NOT NULL, | ||
330 | "Hair_Asset" uuid NOT NULL, | ||
331 | "Eyes_Item" uuid NOT NULL, | ||
332 | "Eyes_Asset" uuid NOT NULL, | ||
333 | "Shirt_Item" uuid NOT NULL, | ||
334 | "Shirt_Asset" uuid NOT NULL, | ||
335 | "Pants_Item" uuid NOT NULL, | ||
336 | "Pants_Asset" uuid NOT NULL, | ||
337 | "Shoes_Item" uuid NOT NULL, | ||
338 | "Shoes_Asset" uuid NOT NULL, | ||
339 | "Socks_Item" uuid NOT NULL, | ||
340 | "Socks_Asset" uuid NOT NULL, | ||
341 | "Jacket_Item" uuid NOT NULL, | ||
342 | "Jacket_Asset" uuid NOT NULL, | ||
343 | "Gloves_Item" uuid NOT NULL, | ||
344 | "Gloves_Asset" uuid NOT NULL, | ||
345 | "Undershirt_Item" uuid NOT NULL, | ||
346 | "Undershirt_Asset" uuid NOT NULL, | ||
347 | "Underpants_Item" uuid NOT NULL, | ||
348 | "Underpants_Asset" uuid NOT NULL, | ||
349 | "Skirt_Item" uuid NOT NULL, | ||
350 | "Skirt_Asset" uuid NOT NULL | ||
351 | ); | ||
352 | |||
353 | INSERT INTO Tmp_avatarappearance ("Owner", "Serial", "Visual_Params", "Texture", "Avatar_Height", "Body_Item", "Body_Asset", "Skin_Item", "Skin_Asset", "Hair_Item", "Hair_Asset", "Eyes_Item", "Eyes_Asset", "Shirt_Item", "Shirt_Asset", "Pants_Item", "Pants_Asset", "Shoes_Item", "Shoes_Asset", "Socks_Item", "Socks_Asset", "Jacket_Item", "Jacket_Asset", "Gloves_Item", "Gloves_Asset", "Undershirt_Item", "Undershirt_Asset", "Underpants_Item", "Underpants_Asset", "Skirt_Item", "Skirt_Asset") | ||
354 | SELECT cast("Owner" as uuid), "Serial", "Visual_Params", "Texture", "Avatar_Height", cast("Body_Item" as uuid), cast("Body_Asset" as uuid), cast("Skin_Item" as uuid), cast("Skin_Asset" as uuid), cast("Hair_Item" as uuid), cast("Hair_Asset" as uuid), cast("Eyes_Item" as uuid), cast("Eyes_Asset" as uuid), cast("Shirt_Item" as uuid), cast("Shirt_Asset" as uuid), cast("Pants_Item" as uuid), cast("Pants_Asset" as uuid), cast("Shoes_Item" as uuid), cast("Shoes_Asset" as uuid), cast("Socks_Item" as uuid), cast("Socks_Asset" as uuid), cast("Jacket_Item" as uuid), cast("Jacket_Asset" as uuid), cast("Gloves_Item" as uuid), cast("Gloves_Asset" as uuid), cast("Undershirt_Item" as uuid), cast("Undershirt_Asset" as uuid), cast("Underpants_Item" as uuid), cast("Underpants_Asset" as uuid), cast("Skirt_Item" as uuid), cast("Skirt_Asset" as uuid) | ||
355 | FROM avatarappearance ; | ||
356 | |||
357 | DROP TABLE avatarappearance; | ||
358 | |||
359 | alter table Tmp_avatarappearance rename to avatarappearance; | ||
360 | |||
361 | ALTER TABLE avatarappearance ADD CONSTRAINT | ||
362 | PK__avatarap__7DD115CC4E88ABD4 PRIMARY KEY | ||
363 | ( | ||
364 | "Owner" | ||
365 | ); | ||
366 | |||
367 | COMMIT; | ||
368 | |||
369 | |||
370 | :VERSION 10 | ||
371 | |||
372 | BEGIN TRANSACTION; | ||
373 | |||
374 | CREATE TABLE Tmp_avatarattachments | ||
375 | ( | ||
376 | "UUID" uuid NOT NULL, | ||
377 | "attachpoint" int NOT NULL, | ||
378 | item uuid NOT NULL, | ||
379 | asset uuid NOT NULL | ||
380 | ); | ||
381 | |||
382 | INSERT INTO Tmp_avatarattachments ("UUID", "attachpoint", item, asset) | ||
383 | SELECT cast("UUID" as uuid), "attachpoint", cast(item as uuid), cast(asset as uuid) | ||
384 | FROM avatarattachments ; | ||
385 | |||
386 | DROP TABLE avatarattachments; | ||
387 | |||
388 | alter table Tmp_avatarattachments rename to avatarattachments; | ||
389 | |||
390 | CREATE INDEX IX_avatarattachments ON avatarattachments | ||
391 | ( | ||
392 | "UUID" | ||
393 | ); | ||
394 | |||
395 | COMMIT; | ||
396 | |||
397 | |||
398 | :VERSION 11 | ||
399 | |||
400 | BEGIN TRANSACTION; | ||
401 | |||
402 | ALTER TABLE users ADD "scopeID" uuid not null default '00000000-0000-0000-0000-000000000000'; | ||
403 | |||
404 | COMMIT; | ||
diff --git a/OpenSim/Data/PGSQL/Resources/XAssetStore.migrations b/OpenSim/Data/PGSQL/Resources/XAssetStore.migrations new file mode 100644 index 0000000..df9d821 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/XAssetStore.migrations | |||
@@ -0,0 +1,80 @@ | |||
1 | # ----------------- | ||
2 | :VERSION 1 | ||
3 | |||
4 | BEGIN; | ||
5 | |||
6 | CREATE TABLE XAssetsMeta ( | ||
7 | "ID" char(36) NOT NULL, | ||
8 | "Hash" char(32) NOT NULL, | ||
9 | "Name" varchar(64) NOT NULL, | ||
10 | "Description" varchar(64) NOT NULL, | ||
11 | "AssetType" smallint NOT NULL, | ||
12 | "Local" smallint NOT NULL, | ||
13 | "Temporary" smallint NOT NULL, | ||
14 | "CreateTime" integer NOT NULL, | ||
15 | "AccessTime" integer NOT NULL, | ||
16 | "AssetFlags" integer NOT NULL, | ||
17 | "CreatorID" varchar(128) NOT NULL, | ||
18 | PRIMARY KEY ("ID") | ||
19 | ); | ||
20 | |||
21 | CREATE TABLE XAssetsData ( | ||
22 | "Hash" char(32) NOT NULL, | ||
23 | "Data" bytea NOT NULL, | ||
24 | PRIMARY KEY ("Hash") | ||
25 | ); | ||
26 | |||
27 | COMMIT; | ||
28 | |||
29 | |||
30 | :VERSION 2 | ||
31 | |||
32 | BEGIN; | ||
33 | |||
34 | ALTER TABLE xassetsmeta ALTER COLUMN "Local" SET DATA TYPE boolean USING CASE WHEN '0' THEN FALSE ELSE TRUE END; | ||
35 | ALTER TABLE xassetsmeta ALTER COLUMN "Temporary" SET DATA TYPE boolean USING CASE WHEN '0' THEN FALSE ELSE TRUE END; | ||
36 | ALTER TABLE xassetsmeta ALTER COLUMN "Hash" SET DATA TYPE char(66); | ||
37 | ALTER TABLE xassetsdata ALTER COLUMN "Hash" SET DATA TYPE char(66); | ||
38 | |||
39 | COMMIT; | ||
40 | |||
41 | :VERSION 3 | ||
42 | |||
43 | BEGIN; | ||
44 | |||
45 | ALTER TABLE xassetsmeta RENAME COLUMN "ID" TO id; | ||
46 | ALTER TABLE xassetsmeta RENAME COLUMN "Hash" TO hash; | ||
47 | ALTER TABLE xassetsmeta RENAME COLUMN "Name" TO name; | ||
48 | ALTER TABLE xassetsmeta RENAME COLUMN "Description" TO description; | ||
49 | ALTER TABLE xassetsmeta RENAME COLUMN "Local" to local; | ||
50 | ALTER TABLE xassetsmeta RENAME COLUMN "Temporary" TO temporary; | ||
51 | ALTER TABLE xassetsmeta RENAME COLUMN "CreateTime" TO create_time; | ||
52 | ALTER TABLE xassetsmeta RENAME COLUMN "AccessTime" TO access_time; | ||
53 | ALTER TABLE xassetsmeta RENAME COLUMN "AssetFlags" TO asset_flags; | ||
54 | ALTER TABLE xassetsmeta RENAME COLUMN "CreatorID" TO creatorid; | ||
55 | ALTER TABLE xassetsmeta DROP CONSTRAINT xassetsmeta_pkey; | ||
56 | ALTER TABLE xassetsmeta ADD PRIMARY KEY (id); | ||
57 | |||
58 | |||
59 | ALTER TABLE xassetsdata RENAME COLUMN "Hash" TO hash; | ||
60 | ALTER TABLE xassetsdata RENAME COLUMN "Data" TO data; | ||
61 | ALTER TABLE xassetsdata DROP CONSTRAINT xassetsdata_pkey; | ||
62 | ALTER TABLE xassetsdata ADD PRIMARY KEY (hash); | ||
63 | |||
64 | COMMIT; | ||
65 | |||
66 | |||
67 | :VERSION 4 | ||
68 | |||
69 | BEGIN; | ||
70 | |||
71 | ALTER TABLE xassetsmeta ALTER COLUMN id SET DATA TYPE uuid USING id::uuid; | ||
72 | ALTER TABLE xassetsmeta ALTER COLUMN hash SET DATA TYPE bytea USING hash::bytea; | ||
73 | ALTER TABLE xassetsdata ALTER COLUMN hash SET DATA TYPE bytea USING hash::bytea; | ||
74 | |||
75 | COMMIT; | ||
76 | |||
77 | :VERSION 5 | ||
78 | |||
79 | BEGIN; | ||
80 | COMMIT; | ||
diff --git a/OpenSim/Data/PGSQL/Resources/os_groups_Store.migrations b/OpenSim/Data/PGSQL/Resources/os_groups_Store.migrations new file mode 100644 index 0000000..74b07c3 --- /dev/null +++ b/OpenSim/Data/PGSQL/Resources/os_groups_Store.migrations | |||
@@ -0,0 +1,211 @@ | |||
1 | :VERSION 1 # -------------------------- | ||
2 | |||
3 | BEGIN; | ||
4 | |||
5 | CREATE TABLE os_groups_groups ( | ||
6 | "GroupID" char(36) Primary Key NOT NULL default '', | ||
7 | "Location" varchar(255) NOT NULL default '', | ||
8 | "Name" varchar(255) NOT NULL default '', | ||
9 | "Charter" text NOT NULL, | ||
10 | "InsigniaID" char(36) NOT NULL default '', | ||
11 | "FounderID" char(36) NOT NULL default '', | ||
12 | "MembershipFee" integer NOT NULL default '0', | ||
13 | "OpenEnrollment" varchar(255) NOT NULL default '', | ||
14 | "ShowInList" integer NOT NULL default '0', | ||
15 | "AllowPublish" integer NOT NULL default '0', | ||
16 | "MaturePublish" integer NOT NULL default '0', | ||
17 | "OwnerRoleID" char(36) NOT NULL default '' | ||
18 | ); | ||
19 | |||
20 | |||
21 | CREATE TABLE os_groups_membership ( | ||
22 | "GroupID"char(36) NOT NULL default '', | ||
23 | "PrincipalID" VARCHAR(255) NOT NULL default '', | ||
24 | "SelectedRoleID" char(36) NOT NULL default '', | ||
25 | "Contribution" integer NOT NULL default '0', | ||
26 | "ListInProfile" integer NOT NULL default '1', | ||
27 | "AcceptNotices" integer NOT NULL default '1', | ||
28 | "AccessToken" char(36) NOT NULL default '', | ||
29 | constraint os_groupmemberpk primary key ("GroupID", "PrincipalID") | ||
30 | ); | ||
31 | |||
32 | |||
33 | |||
34 | CREATE TABLE os_groups_roles ( | ||
35 | "GroupID" char(36) NOT NULL default '', | ||
36 | "RoleID" char(36) NOT NULL default '', | ||
37 | "Name" varchar(255) NOT NULL default '', | ||
38 | "Description" varchar(255) NOT NULL default '', | ||
39 | "Title" varchar(255) NOT NULL default '', | ||
40 | "Powers" bigint NOT NULL default 0, | ||
41 | constraint os_grouprolepk PRIMARY KEY ("GroupID","RoleID") | ||
42 | ); | ||
43 | |||
44 | |||
45 | CREATE TABLE os_groups_rolemembership ( | ||
46 | "GroupID" char(36) NOT NULL default '', | ||
47 | "RoleID" char(36) NOT NULL default '', | ||
48 | "PrincipalID" VARCHAR(255) NOT NULL default '', | ||
49 | constraint os_grouprolememberpk PRIMARY KEY ("GroupID","RoleID","PrincipalID") | ||
50 | ); | ||
51 | |||
52 | |||
53 | CREATE TABLE os_groups_invites ( | ||
54 | "InviteID" char(36) NOT NULL default '', | ||
55 | "GroupID" char(36) NOT NULL default '', | ||
56 | "RoleID" char(36) NOT NULL default '', | ||
57 | "PrincipalID" VARCHAR(255) NOT NULL default '', | ||
58 | "TMStamp" timestamp NOT NULL default now(), | ||
59 | constraint os_groupinvitespk PRIMARY KEY ("InviteID") | ||
60 | ); | ||
61 | -- UNIQUE KEY "PrincipalGroup" ("GroupID","PrincipalID") | ||
62 | |||
63 | |||
64 | CREATE TABLE os_groups_notices ( | ||
65 | "GroupID" char(36) NOT NULL default '', | ||
66 | "NoticeID" char(36) NOT NULL default '', | ||
67 | "TMStamp" integer NOT NULL default '0', | ||
68 | "FromName" varchar(255) NOT NULL default '', | ||
69 | "Subject" varchar(255) NOT NULL default '', | ||
70 | "Message" text NOT NULL, | ||
71 | "HasAttachment" integer NOT NULL default '0', | ||
72 | "AttachmentType" integer NOT NULL default '0', | ||
73 | "AttachmentName" varchar(128) NOT NULL default '', | ||
74 | "AttachmentItemID" char(36) NOT NULL default '', | ||
75 | "AttachmentOwnerID" varchar(255) NOT NULL default '', | ||
76 | constraint os_groupsnoticespk PRIMARY KEY ("NoticeID") | ||
77 | ); | ||
78 | -- KEY "GroupID" ("GroupID"), | ||
79 | -- KEY "TMStamp" ("TMStamp") | ||
80 | |||
81 | CREATE TABLE os_groups_principals ( | ||
82 | "PrincipalID" VARCHAR(255) NOT NULL default '', | ||
83 | "ActiveGroupID" char(36) NOT NULL default '', | ||
84 | constraint os_groupprincpk PRIMARY KEY ("PrincipalID") | ||
85 | ); | ||
86 | |||
87 | COMMIT; | ||
88 | |||
89 | :VERSION 2 # -------------------------- | ||
90 | |||
91 | BEGIN; | ||
92 | |||
93 | |||
94 | COMMIT; | ||
95 | |||
96 | |||
97 | |||
98 | :VERSION 3 | ||
99 | |||
100 | BEGIN; | ||
101 | |||
102 | -- Not a pretty way to do this, but it did not work as-is | ||
103 | -- and nothing was found about converting between existing data | ||
104 | -- and the new type. | ||
105 | -- Since there should be nothing to preserve ... | ||
106 | |||
107 | DROP TABLE IF EXISTS os_groups_groups CASCADE; | ||
108 | |||
109 | CREATE TABLE os_groups_groups ( | ||
110 | "GroupID" uuid PRIMARY KEY NOT NULL, | ||
111 | "Location" varchar(255) NOT NULL DEFAULT '', | ||
112 | "Name" varchar(255) NOT NULL DEFAULT '', | ||
113 | "Charter" text NOT NULL, | ||
114 | "InsigniaID" uuid NOT NULL, | ||
115 | "FounderID" uuid NOT NULL, | ||
116 | "MembershipFee" integer NOT NULL DEFAULT '0', | ||
117 | "OpenEnrollment" varchar(255) NOT NULL DEFAULT '', | ||
118 | "ShowInList" integer NOT NULL DEFAULT '0', | ||
119 | "AllowPublish" integer NOT NULL DEFAULT '0', | ||
120 | "MaturePublish" integer NOT NULL DEFAULT '0', | ||
121 | "OwnerRoleID" uuid NOT NULL | ||
122 | ); | ||
123 | |||
124 | |||
125 | DROP TABLE IF EXISTS os_groups_membership; | ||
126 | |||
127 | CREATE TABLE os_groups_membership ( | ||
128 | "GroupID"uuid NOT NULL, | ||
129 | "PrincipalID" VARCHAR(255) NOT NULL DEFAULT '', | ||
130 | "SelectedRoleID" uuid NOT NULL, | ||
131 | "Contribution" integer NOT NULL DEFAULT '0', | ||
132 | "ListInProfile" integer NOT NULL DEFAULT '1', | ||
133 | "AcceptNotices" integer NOT NULL DEFAULT '1', | ||
134 | "AccessToken" uuid NOT NULL, | ||
135 | constraint os_groupmemberpk PRIMARY KEY ("GroupID", "PrincipalID") | ||
136 | ); | ||
137 | |||
138 | |||
139 | |||
140 | DROP TABLE IF EXISTS os_groups_roles; | ||
141 | |||
142 | CREATE TABLE os_groups_roles ( | ||
143 | "GroupID" uuid NOT NULL, | ||
144 | "RoleID" uuid NOT NULL, | ||
145 | "Name" varchar(255) NOT NULL DEFAULT '', | ||
146 | "Description" varchar(255) NOT NULL DEFAULT '', | ||
147 | "Title" varchar(255) NOT NULL DEFAULT '', | ||
148 | "Powers" varchar(36) NOT NULL DEFAULT '', | ||
149 | constraint os_grouprolepk PRIMARY KEY ("GroupID","RoleID") | ||
150 | ); | ||
151 | |||
152 | |||
153 | DROP TABLE IF EXISTS os_groups_rolemembership; | ||
154 | |||
155 | CREATE TABLE os_groups_rolemembership ( | ||
156 | "GroupID" uuid NOT NULL, | ||
157 | "RoleID" uuid NOT NULL, | ||
158 | "PrincipalID" VARCHAR(255) NOT NULL DEFAULT '', | ||
159 | constraint os_grouprolememberpk PRIMARY KEY ("GroupID","RoleID","PrincipalID") | ||
160 | ); | ||
161 | |||
162 | |||
163 | DROP TABLE IF EXISTS os_groups_invites; | ||
164 | |||
165 | CREATE TABLE os_groups_invites ( | ||
166 | "InviteID" uuid NOT NULL, | ||
167 | "GroupID" uuid NOT NULL, | ||
168 | "RoleID" uuid NOT NULL, | ||
169 | "PrincipalID" VARCHAR(255) NOT NULL DEFAULT '', | ||
170 | "TMStamp" timestamp NOT NULL DEFAULT now(), | ||
171 | constraint os_groupinvitespk PRIMARY KEY ("InviteID") | ||
172 | ); | ||
173 | |||
174 | |||
175 | DROP TABLE IF EXISTS os_groups_notices; | ||
176 | |||
177 | CREATE TABLE os_groups_notices ( | ||
178 | "GroupID" uuid NOT NULL, | ||
179 | "NoticeID" uuid NOT NULL, | ||
180 | "TMStamp" integer NOT NULL DEFAULT '0', | ||
181 | "FromName" varchar(255) NOT NULL DEFAULT '', | ||
182 | "Subject" varchar(255) NOT NULL DEFAULT '', | ||
183 | "Message" text NOT NULL, | ||
184 | "HasAttachment" integer NOT NULL DEFAULT '0', | ||
185 | "AttachmentType" integer NOT NULL DEFAULT '0', | ||
186 | "AttachmentName" varchar(128) NOT NULL DEFAULT '', | ||
187 | "AttachmentItemID" uuid NOT NULL, | ||
188 | "AttachmentOwnerID" varchar(255) NOT NULL DEFAULT '', | ||
189 | constraint os_groupsnoticespk PRIMARY KEY ("NoticeID") | ||
190 | ); | ||
191 | |||
192 | |||
193 | DROP TABLE IF EXISTS os_groups_principals; | ||
194 | |||
195 | CREATE TABLE os_groups_principals ( | ||
196 | "PrincipalID" VARCHAR(255) NOT NULL DEFAULT '', | ||
197 | "ActiveGroupID" uuid NOT NULL, | ||
198 | constraint os_groupprincpk PRIMARY KEY ("PrincipalID") | ||
199 | ); | ||
200 | |||
201 | COMMIT; | ||
202 | |||
203 | :VERSION 4 | ||
204 | |||
205 | BEGIN; | ||
206 | |||
207 | ALTER TABLE IF EXISTS os_groups_notices | ||
208 | ALTER COLUMN "AttachmentItemID" SET DEFAULT '00000000-0000-0000-0000-000000000000' | ||
209 | ; | ||
210 | |||
211 | COMMIT; | ||