aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL')
-rw-r--r--OpenSim/Data/MySQL/MySQLAvatarData.cs67
-rw-r--r--OpenSim/Data/MySQL/MySQLFriendsData.cs68
-rw-r--r--OpenSim/Data/MySQL/MySQLGenericTableHandler.cs10
-rw-r--r--OpenSim/Data/MySQL/MySQLPresenceData.cs155
-rw-r--r--OpenSim/Data/MySQL/MySQLRegionData.cs26
-rw-r--r--OpenSim/Data/MySQL/MySQLUserAccountData.cs150
-rw-r--r--OpenSim/Data/MySQL/Resources/001_Avatar.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/001_Friends.sql9
-rw-r--r--OpenSim/Data/MySQL/Resources/001_FriendsStore.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/001_Presence.sql15
-rw-r--r--OpenSim/Data/MySQL/Resources/001_UserAccount.sql13
-rw-r--r--OpenSim/Data/MySQL/Resources/002_AuthStore.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/002_Friends.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/002_FriendsStore.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/002_Presence.sql7
-rw-r--r--OpenSim/Data/MySQL/Resources/002_UserAccount.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/003_AuthStore.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/003_Presence.sql6
-rw-r--r--OpenSim/Data/MySQL/Resources/003_UserAccount.sql9
-rw-r--r--OpenSim/Data/MySQL/Resources/004_UserAccount.sql8
-rw-r--r--OpenSim/Data/MySQL/Resources/005_GridStore.sql6
-rw-r--r--OpenSim/Data/MySQL/Resources/006_GridStore.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/007_GridStore.sql7
23 files changed, 466 insertions, 130 deletions
diff --git a/OpenSim/Data/MySQL/MySQLAvatarData.cs b/OpenSim/Data/MySQL/MySQLAvatarData.cs
new file mode 100644
index 0000000..5611302
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLAvatarData.cs
@@ -0,0 +1,67 @@
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
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Reflection;
32using System.Threading;
33using log4net;
34using OpenMetaverse;
35using OpenSim.Framework;
36using MySql.Data.MySqlClient;
37
38namespace OpenSim.Data.MySQL
39{
40 /// <summary>
41 /// A MySQL Interface for the Grid Server
42 /// </summary>
43 public class MySQLAvatarData : MySQLGenericTableHandler<AvatarBaseData>,
44 IAvatarData
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 public MySQLAvatarData(string connectionString, string realm) :
49 base(connectionString, realm, "Avatar")
50 {
51 }
52
53 public bool Delete(UUID principalID, string name)
54 {
55 MySqlCommand cmd = new MySqlCommand();
56
57 cmd.CommandText = String.Format("delete from {0} where `PrincipalID` = ?PrincipalID and `Name` = ?Name", m_Realm);
58 cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString());
59 cmd.Parameters.AddWithValue("?Name", name);
60
61 if (ExecuteNonQuery(cmd) > 0)
62 return true;
63
64 return false;
65 }
66 }
67}
diff --git a/OpenSim/Data/MySQL/MySQLFriendsData.cs b/OpenSim/Data/MySQL/MySQLFriendsData.cs
new file mode 100644
index 0000000..7a43bb6
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLFriendsData.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
28using System;
29using System.Collections;
30using System.Collections.Generic;
31using System.Data;
32using OpenMetaverse;
33using OpenSim.Framework;
34using MySql.Data.MySqlClient;
35
36namespace OpenSim.Data.MySQL
37{
38 public class MySqlFriendsData : MySQLGenericTableHandler<FriendsData>, IFriendsData
39 {
40 public MySqlFriendsData(string connectionString, string realm)
41 : base(connectionString, realm, "FriendsStore")
42 {
43 }
44
45 public bool Delete(UUID principalID, string friend)
46 {
47 MySqlCommand cmd = new MySqlCommand();
48
49 cmd.CommandText = String.Format("delete from {0} where PrincipalID = ?PrincipalID and Friend = ?Friend", m_Realm);
50 cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString());
51 cmd.Parameters.AddWithValue("?Friend", friend);
52
53 ExecuteNonQuery(cmd);
54
55 return true;
56 }
57
58 public FriendsData[] GetFriends(UUID principalID)
59 {
60 MySqlCommand cmd = new MySqlCommand();
61
62 cmd.CommandText = String.Format("select a.*,b.Flags as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = ?PrincipalID and b.Flags is not null", m_Realm);
63 cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString());
64
65 return DoQuery(cmd);
66 }
67 }
68}
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
index 698bf52..6ad59f6 100644
--- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
+++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
@@ -99,12 +99,12 @@ namespace OpenSim.Data.MySQL
99 } 99 }
100 } 100 }
101 101
102 public T[] Get(string field, string key) 102 public virtual T[] Get(string field, string key)
103 { 103 {
104 return Get(new string[] { field }, new string[] { key }); 104 return Get(new string[] { field }, new string[] { key });
105 } 105 }
106 106
107 public T[] Get(string[] fields, string[] keys) 107 public virtual T[] Get(string[] fields, string[] keys)
108 { 108 {
109 if (fields.Length != keys.Length) 109 if (fields.Length != keys.Length)
110 return new T[0]; 110 return new T[0];
@@ -198,7 +198,7 @@ namespace OpenSim.Data.MySQL
198 return result.ToArray(); 198 return result.ToArray();
199 } 199 }
200 200
201 public T[] Get(string where) 201 public virtual T[] Get(string where)
202 { 202 {
203 using (MySqlCommand cmd = new MySqlCommand()) 203 using (MySqlCommand cmd = new MySqlCommand())
204 { 204 {
@@ -212,7 +212,7 @@ namespace OpenSim.Data.MySQL
212 } 212 }
213 } 213 }
214 214
215 public bool Store(T row) 215 public virtual bool Store(T row)
216 { 216 {
217 using (MySqlCommand cmd = new MySqlCommand()) 217 using (MySqlCommand cmd = new MySqlCommand())
218 { 218 {
@@ -252,7 +252,7 @@ namespace OpenSim.Data.MySQL
252 } 252 }
253 } 253 }
254 254
255 public bool Delete(string field, string val) 255 public virtual bool Delete(string field, string val)
256 { 256 {
257 using (MySqlCommand cmd = new MySqlCommand()) 257 using (MySqlCommand cmd = new MySqlCommand())
258 { 258 {
diff --git a/OpenSim/Data/MySQL/MySQLPresenceData.cs b/OpenSim/Data/MySQL/MySQLPresenceData.cs
new file mode 100644
index 0000000..fcbe3d6
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLPresenceData.cs
@@ -0,0 +1,155 @@
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
28using System;
29using System.Collections.Generic;
30using System.Data;
31using System.Reflection;
32using System.Threading;
33using log4net;
34using OpenMetaverse;
35using OpenSim.Framework;
36using MySql.Data.MySqlClient;
37
38namespace OpenSim.Data.MySQL
39{
40 /// <summary>
41 /// A MySQL Interface for the Grid Server
42 /// </summary>
43 public class MySQLPresenceData : MySQLGenericTableHandler<PresenceData>,
44 IPresenceData
45 {
46 private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
47
48 public MySQLPresenceData(string connectionString, string realm) :
49 base(connectionString, realm, "Presence")
50 {
51 }
52
53 public PresenceData Get(UUID sessionID)
54 {
55 PresenceData[] ret = Get("SessionID",
56 sessionID.ToString());
57
58 if (ret.Length == 0)
59 return null;
60
61 return ret[0];
62 }
63
64 public void LogoutRegionAgents(UUID regionID)
65 {
66 MySqlCommand cmd = new MySqlCommand();
67
68 cmd.CommandText = String.Format("update {0} set Online='false' where `RegionID`=?RegionID", m_Realm);
69
70 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
71
72 ExecuteNonQuery(cmd);
73 }
74
75 public bool ReportAgent(UUID sessionID, UUID regionID, string position,
76 string lookAt)
77 {
78 PresenceData[] pd = Get("SessionID", sessionID.ToString());
79 if (pd.Length == 0)
80 return false;
81
82 MySqlCommand cmd = new MySqlCommand();
83
84 cmd.CommandText = String.Format("update {0} set RegionID=?RegionID, Position=?Position, LookAt=?LookAt, Online='true' where `SessionID`=?SessionID", m_Realm);
85
86 cmd.Parameters.AddWithValue("?SessionID", sessionID.ToString());
87 cmd.Parameters.AddWithValue("?RegionID", regionID.ToString());
88 cmd.Parameters.AddWithValue("?Position", position.ToString());
89 cmd.Parameters.AddWithValue("?LookAt", lookAt.ToString());
90
91 if (ExecuteNonQuery(cmd) == 0)
92 return false;
93
94 return true;
95 }
96
97 public bool SetHomeLocation(string userID, UUID regionID, Vector3 position, Vector3 lookAt)
98 {
99 PresenceData[] pd = Get("UserID", userID);
100 if (pd.Length == 0)
101 return false;
102
103 MySqlCommand cmd = new MySqlCommand();
104
105 cmd.CommandText = String.Format("update {0} set HomeRegionID=?HomeRegionID, HomePosition=?HomePosition, HomeLookAt=?HomeLookAt where UserID=?UserID", m_Realm);
106
107 cmd.Parameters.AddWithValue("?UserID", userID);
108 cmd.Parameters.AddWithValue("?HomeRegionID", regionID.ToString());
109 cmd.Parameters.AddWithValue("?HomePosition", position);
110 cmd.Parameters.AddWithValue("?HomeLookAt", lookAt);
111
112 if (ExecuteNonQuery(cmd) == 0)
113 return false;
114
115 return true;
116 }
117
118 public void Prune(string userID)
119 {
120 MySqlCommand cmd = new MySqlCommand();
121
122 cmd.CommandText = String.Format("select * from {0} where UserID=?UserID", m_Realm);
123
124 cmd.Parameters.AddWithValue("?UserID", userID);
125;
126 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
127 {
128 dbcon.Open();
129
130 cmd.Connection = dbcon;
131
132 using (IDataReader reader = cmd.ExecuteReader())
133 {
134
135 List<UUID> deleteSessions = new List<UUID>();
136 int online = 0;
137
138 while(reader.Read())
139 {
140 if (bool.Parse(reader["Online"].ToString()))
141 online++;
142 else
143 deleteSessions.Add(new UUID(reader["SessionID"].ToString()));
144 }
145
146 if (online == 0 && deleteSessions.Count > 0)
147 deleteSessions.RemoveAt(0);
148
149 foreach (UUID s in deleteSessions)
150 Delete("SessionID", s.ToString());
151 }
152 }
153 }
154 }
155}
diff --git a/OpenSim/Data/MySQL/MySQLRegionData.cs b/OpenSim/Data/MySQL/MySQLRegionData.cs
index a1a08b1..aa9a104 100644
--- a/OpenSim/Data/MySQL/MySQLRegionData.cs
+++ b/OpenSim/Data/MySQL/MySQLRegionData.cs
@@ -283,5 +283,31 @@ namespace OpenSim.Data.MySQL
283 283
284 return false; 284 return false;
285 } 285 }
286 public List<RegionData> GetDefaultRegions(UUID scopeID)
287 {
288 string command = "select * from `"+m_Realm+"` where (flags & 1) <> 0";
289 if (scopeID != UUID.Zero)
290 command += " and ScopeID = ?scopeID";
291
292 MySqlCommand cmd = new MySqlCommand(command);
293
294 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
295
296 return RunCommand(cmd);
297 }
298
299 public List<RegionData> GetFallbackRegions(UUID scopeID, int x, int y)
300 {
301 string command = "select * from `"+m_Realm+"` where (flags & 2) <> 0";
302 if (scopeID != UUID.Zero)
303 command += " and ScopeID = ?scopeID";
304
305 MySqlCommand cmd = new MySqlCommand(command);
306
307 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
308
309 // TODO: distance-sort results
310 return RunCommand(cmd);
311 }
286 } 312 }
287} 313}
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
index 3cb0010..aa69d68 100644
--- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
@@ -35,150 +35,50 @@ using MySql.Data.MySqlClient;
35 35
36namespace OpenSim.Data.MySQL 36namespace OpenSim.Data.MySQL
37{ 37{
38 public class MySqlUserAccountData : MySqlFramework, IUserAccountData 38 public class MySqlUserAccountData : MySQLGenericTableHandler<UserAccountData>, IUserAccountData
39 { 39 {
40 private string m_Realm;
41 private List<string> m_ColumnNames;
42 // private string m_connectionString;
43
44 public MySqlUserAccountData(string connectionString, string realm) 40 public MySqlUserAccountData(string connectionString, string realm)
45 : base(connectionString) 41 : base(connectionString, realm, "UserAccount")
46 {
47 m_Realm = realm;
48 m_connectionString = connectionString;
49
50 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
51 {
52 dbcon.Open();
53 Migration m = new Migration(dbcon, GetType().Assembly, "UserStore");
54 m.Update();
55 }
56 }
57
58 public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query)
59 { 42 {
60 return null;
61 } 43 }
62 44
63 public UserAccountData Get(UUID principalID, UUID scopeID) 45 public UserAccountData[] GetUsers(UUID scopeID, string query)
64 { 46 {
65 UserAccountData ret = new UserAccountData(); 47 string[] words = query.Split(new char[] {' '});
66 ret.Data = new Dictionary<string, object>();
67
68 string command = "select * from `"+m_Realm+"` where UUID = ?principalID";
69 if (scopeID != UUID.Zero)
70 command += " and ScopeID = ?scopeID";
71 48
72 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 49 for (int i = 0 ; i < words.Length ; i++)
73 { 50 {
74 dbcon.Open(); 51 if (words[i].Length < 3)
75 MySqlCommand cmd = new MySqlCommand(command, dbcon);
76
77 cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
78 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
79
80 IDataReader result = cmd.ExecuteReader();
81
82 if (result.Read())
83 { 52 {
84 ret.PrincipalID = principalID; 53 if (i != words.Length - 1)
85 UUID scope; 54 Array.Copy(words, i + 1, words, i, words.Length - i - 1);
86 UUID.TryParse(result["ScopeID"].ToString(), out scope); 55 Array.Resize(ref words, words.Length - 1);
87 ret.ScopeID = scope;
88
89 if (m_ColumnNames == null)
90 {
91 m_ColumnNames = new List<string>();
92
93 DataTable schemaTable = result.GetSchemaTable();
94 foreach (DataRow row in schemaTable.Rows)
95 m_ColumnNames.Add(row["ColumnName"].ToString());
96 }
97
98 foreach (string s in m_ColumnNames)
99 {
100 if (s == "UUID")
101 continue;
102 if (s == "ScopeID")
103 continue;
104
105 ret.Data[s] = result[s].ToString();
106 }
107
108 return ret;
109 }
110 else
111 {
112 return null;
113 } 56 }
114 } 57 }
115 }
116 58
117 public bool Store(UserAccountData data) 59 if (words.Length == 0)
118 { 60 return new UserAccountData[0];
119 if (data.Data.ContainsKey("UUID"))
120 data.Data.Remove("UUID");
121 if (data.Data.ContainsKey("ScopeID"))
122 data.Data.Remove("ScopeID");
123
124 string[] fields = new List<string>(data.Data.Keys).ToArray();
125
126 using (MySqlCommand cmd = new MySqlCommand())
127 {
128 string update = "update `" + m_Realm + "` set ";
129 bool first = true;
130 foreach (string field in fields)
131 {
132 if (!first)
133 update += ", ";
134 update += "`" + field + "` = ?" + field;
135 61
136 first = false; 62 if (words.Length > 2)
63 return new UserAccountData[0];
137 64
138 cmd.Parameters.AddWithValue("?" + field, data.Data[field]); 65 MySqlCommand cmd = new MySqlCommand();
139 }
140
141 update += " where UUID = ?principalID";
142
143 if (data.ScopeID != UUID.Zero)
144 update += " and ScopeID = ?scopeID";
145 66
146 cmd.CommandText = update; 67 if (words.Length == 1)
147 cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); 68 {
148 cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); 69 cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?search or LastName like ?search)", m_Realm);
149 70 cmd.Parameters.AddWithValue("?search", "%" + words[0] + "%");
150 if (ExecuteNonQuery(cmd) < 1) 71 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
151 {
152 string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" +
153 String.Join("`, `", fields) +
154 "`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")";
155
156 cmd.CommandText = insert;
157
158 if (ExecuteNonQuery(cmd) < 1)
159 {
160 cmd.Dispose();
161 return false;
162 }
163 }
164 } 72 }
165 73 else
166 return true;
167 }
168
169 public bool SetDataItem(UUID principalID, string item, string value)
170 {
171 using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" +
172 item + "` = ?" + item + " where UUID = ?UUID"))
173 { 74 {
174 cmd.Parameters.AddWithValue("?" + item, value); 75 cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?searchFirst or LastName like ?searchLast)", m_Realm);
175 cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); 76 cmd.Parameters.AddWithValue("?searchFirst", "%" + words[0] + "%");
176 77 cmd.Parameters.AddWithValue("?searchLast", "%" + words[1] + "%");
177 if (ExecuteNonQuery(cmd) > 0) 78 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
178 return true;
179 } 79 }
180 80
181 return false; 81 return DoQuery(cmd);
182 } 82 }
183 } 83 }
184} 84}
diff --git a/OpenSim/Data/MySQL/Resources/001_Avatar.sql b/OpenSim/Data/MySQL/Resources/001_Avatar.sql
new file mode 100644
index 0000000..27a3072
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/001_Avatar.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3CREATE TABLE Avatars (PrincipalID CHAR(36) NOT NULL, Name VARCHAR(32) NOT NULL, Value VARCHAR(255) NOT NULL DEFAULT '', PRIMARY KEY(PrincipalID, Name), KEY(PrincipalID));
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/001_Friends.sql b/OpenSim/Data/MySQL/Resources/001_Friends.sql
new file mode 100644
index 0000000..e158a2c
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/001_Friends.sql
@@ -0,0 +1,9 @@
1BEGIN;
2
3CREATE TABLE `Friends` (
4 `PrincipalID` CHAR(36) NOT NULL,
5 `FriendID` VARCHAR(255) NOT NULL,
6 `Flags` CHAR(16) NOT NULL DEFAULT '0'
7) ENGINE=InnoDB;
8
9COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/001_FriendsStore.sql b/OpenSim/Data/MySQL/Resources/001_FriendsStore.sql
new file mode 100644
index 0000000..da2c59c
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/001_FriendsStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3CREATE TABLE `Friends` (`PrincipalID` CHAR(36) NOT NULL, `Friend` VARCHAR(255) NOT NULL, `Flags` VARCHAR(16) NOT NULL DEFAULT 0, `Offered` VARCHAR(32) NOT NULL DEFAULT 0, PRIMARY KEY(`PrincipalID`, `Friend`), KEY(`PrincipalID`));
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/001_Presence.sql b/OpenSim/Data/MySQL/Resources/001_Presence.sql
new file mode 100644
index 0000000..b8abaf7
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/001_Presence.sql
@@ -0,0 +1,15 @@
1BEGIN;
2
3CREATE TABLE `Presence` (
4 `UserID` VARCHAR(255) NOT NULL,
5 `RegionID` CHAR(36) NOT NULL,
6 `SessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
7 `SecureSessionID` CHAR(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000',
8 `Online` CHAR(5) NOT NULL DEFAULT 'false',
9 `Login` CHAR(16) NOT NULL DEFAULT '0',
10 `Logout` CHAR(16) NOT NULL DEFAULT '0',
11 `Position` CHAR(64) NOT NULL DEFAULT '<0,0,0>',
12 `LookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>'
13) ENGINE=InnoDB;
14
15COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/001_UserAccount.sql b/OpenSim/Data/MySQL/Resources/001_UserAccount.sql
new file mode 100644
index 0000000..07da571
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/001_UserAccount.sql
@@ -0,0 +1,13 @@
1BEGIN;
2
3CREATE TABLE `UserAccounts` (
4 `PrincipalID` CHAR(36) NOT NULL,
5 `ScopeID` CHAR(36) NOT NULL,
6 `FirstName` VARCHAR(64) NOT NULL,
7 `LastName` VARCHAR(64) NOT NULL,
8 `Email` VARCHAR(64),
9 `ServiceURLs` TEXT,
10 `Created` INT(11)
11) ENGINE=InnoDB DEFAULT CHARSET=utf8;
12
13COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/002_AuthStore.sql b/OpenSim/Data/MySQL/Resources/002_AuthStore.sql
new file mode 100644
index 0000000..dc7dfe0
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/002_AuthStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3INSERT INTO auth (UUID, passwordHash, passwordSalt, webLoginKey) SELECT `UUID` AS UUID, `passwordHash` AS passwordHash, `passwordSalt` AS passwordSalt, `webLoginKey` AS webLoginKey FROM users;
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/002_Friends.sql b/OpenSim/Data/MySQL/Resources/002_Friends.sql
new file mode 100644
index 0000000..5ff6438
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/002_Friends.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3INSERT INTO Friends (PrincipalID, FriendID, Flags) SELECT ownerID, friendID, friendPerms FROM userfriends;
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/002_FriendsStore.sql b/OpenSim/Data/MySQL/Resources/002_FriendsStore.sql
new file mode 100644
index 0000000..a363867
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/002_FriendsStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3INSERT INTO `Friends` SELECT `ownerID`, `friendID`, `friendPerms`, 0 FROM `userfriends`;
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/002_Presence.sql b/OpenSim/Data/MySQL/Resources/002_Presence.sql
new file mode 100644
index 0000000..e65f105
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/002_Presence.sql
@@ -0,0 +1,7 @@
1BEGIN;
2
3ALTER TABLE Presence ADD COLUMN `HomeRegionID` CHAR(36) NOT NULL;
4ALTER TABLE Presence ADD COLUMN `HomePosition` CHAR(64) NOT NULL DEFAULT '<0,0,0>';
5ALTER TABLE Presence ADD COLUMN `HomeLookAt` CHAR(64) NOT NULL DEFAULT '<0,0,0>';
6
7COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/002_UserAccount.sql b/OpenSim/Data/MySQL/Resources/002_UserAccount.sql
new file mode 100644
index 0000000..ad2ddda
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/002_UserAccount.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3INSERT INTO UserAccounts (PrincipalID, ScopeID, FirstName, LastName, Email, ServiceURLs, Created) SELECT `UUID` AS PrincipalID, '00000000-0000-0000-0000-000000000000' AS ScopeID, username AS FirstName, lastname AS LastName, email as Email, CONCAT('AssetServerURI=', userAssetURI, ' InventoryServerURI=', userInventoryURI, ' GatewayURI= HomeURI=') AS ServiceURLs, created as Created FROM users;
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/003_AuthStore.sql b/OpenSim/Data/MySQL/Resources/003_AuthStore.sql
new file mode 100644
index 0000000..af9ffe6
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/003_AuthStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3ALTER TABLE `auth` ADD COLUMN `accountType` VARCHAR(32) NOT NULL DEFAULT 'UserAccount';
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/003_Presence.sql b/OpenSim/Data/MySQL/Resources/003_Presence.sql
new file mode 100644
index 0000000..0efefa8
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/003_Presence.sql
@@ -0,0 +1,6 @@
1BEGIN;
2
3CREATE UNIQUE INDEX SessionID ON Presence(SessionID);
4CREATE INDEX UserID ON Presence(UserID);
5
6COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/003_UserAccount.sql b/OpenSim/Data/MySQL/Resources/003_UserAccount.sql
new file mode 100644
index 0000000..e42d93b
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/003_UserAccount.sql
@@ -0,0 +1,9 @@
1BEGIN;
2
3CREATE UNIQUE INDEX PrincipalID ON UserAccounts(PrincipalID);
4CREATE INDEX Email ON UserAccounts(Email);
5CREATE INDEX FirstName ON UserAccounts(FirstName);
6CREATE INDEX LastName ON UserAccounts(LastName);
7CREATE INDEX Name ON UserAccounts(FirstName,LastName);
8
9COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/004_UserAccount.sql b/OpenSim/Data/MySQL/Resources/004_UserAccount.sql
new file mode 100644
index 0000000..8abcd53
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/004_UserAccount.sql
@@ -0,0 +1,8 @@
1BEGIN;
2
3ALTER TABLE UserAccounts ADD COLUMN UserLevel integer NOT NULL DEFAULT 0;
4ALTER TABLE UserAccounts ADD COLUMN UserFlags integer NOT NULL DEFAULT 0;
5ALTER TABLE UserAccounts ADD COLUMN UserTitle varchar(64) NOT NULL DEFAULT '';
6
7COMMIT;
8
diff --git a/OpenSim/Data/MySQL/Resources/005_GridStore.sql b/OpenSim/Data/MySQL/Resources/005_GridStore.sql
new file mode 100644
index 0000000..835ba89
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/005_GridStore.sql
@@ -0,0 +1,6 @@
1BEGIN;
2
3ALTER TABLE `regions` ADD COLUMN `flags` integer NOT NULL DEFAULT 0;
4CREATE INDEX flags ON regions(flags);
5
6COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/006_GridStore.sql b/OpenSim/Data/MySQL/Resources/006_GridStore.sql
new file mode 100644
index 0000000..91322d6
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/006_GridStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3ALTER TABLE `regions` ADD COLUMN `last_seen` integer NOT NULL DEFAULT 0;
4
5COMMIT;
diff --git a/OpenSim/Data/MySQL/Resources/007_GridStore.sql b/OpenSim/Data/MySQL/Resources/007_GridStore.sql
new file mode 100644
index 0000000..dbec584
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/007_GridStore.sql
@@ -0,0 +1,7 @@
1BEGIN;
2
3ALTER TABLE `regions` ADD COLUMN `PrincipalID` char(36) NOT NULL DEFAULT '00000000-0000-0000-0000-000000000000';
4ALTER TABLE `regions` ADD COLUMN `Token` varchar(255) NOT NULL;
5
6COMMIT;
7