aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/IUserAccountData.cs55
-rw-r--r--OpenSim/Data/MSSQL/MSSQLAuthenticationData.cs222
-rw-r--r--OpenSim/Data/MSSQL/MSSQLUserAccountData.cs186
-rw-r--r--OpenSim/Data/MSSQL/Resources/011_UserStore.sql5
-rw-r--r--OpenSim/Data/MySQL/MySQLUserAccountData.cs180
-rw-r--r--OpenSim/Data/MySQL/Resources/008_UserStore.sql5
6 files changed, 653 insertions, 0 deletions
diff --git a/OpenSim/Data/IUserAccountData.cs b/OpenSim/Data/IUserAccountData.cs
new file mode 100644
index 0000000..6bec188
--- /dev/null
+++ b/OpenSim/Data/IUserAccountData.cs
@@ -0,0 +1,55 @@
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 OpenMetaverse;
31using OpenSim.Framework;
32
33namespace OpenSim.Data
34{
35 public class UserAccountData
36 {
37 public UUID PrincipalID;
38 public UUID ScopeID;
39 public Dictionary<string, object> Data;
40 }
41
42 /// <summary>
43 /// An interface for connecting to the authentication datastore
44 /// </summary>
45 public interface IUserAccountData
46 {
47 UserAccountData Get(UUID principalID, UUID ScopeID);
48
49 List<UserAccountData> Query(UUID principalID, UUID ScopeID, string query);
50
51 bool Store(UserAccountData data);
52
53 bool SetDataItem(UUID principalID, string item, string value);
54 }
55}
diff --git a/OpenSim/Data/MSSQL/MSSQLAuthenticationData.cs b/OpenSim/Data/MSSQL/MSSQLAuthenticationData.cs
new file mode 100644
index 0000000..78fc22c
--- /dev/null
+++ b/OpenSim/Data/MSSQL/MSSQLAuthenticationData.cs
@@ -0,0 +1,222 @@
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 System.Data.SqlClient;
35using System.Reflection;
36using System.Text;
37
38namespace OpenSim.Data.MSSQL
39{
40 public class MSSQLAuthenticationData : IAuthenticationData
41 {
42 private string m_Realm;
43 private List<string> m_ColumnNames = null;
44 private int m_LastExpire = 0;
45 private string m_ConnectionString;
46
47 public MSSQLAuthenticationData(string connectionString, string realm)
48 {
49 m_Realm = realm;
50 m_ConnectionString = connectionString;
51 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
52 {
53 conn.Open();
54 Migration m = new Migration(conn, GetType().Assembly, "AuthStore");
55 m.Update();
56 }
57 }
58
59 public AuthenticationData Get(UUID principalID)
60 {
61 AuthenticationData ret = new AuthenticationData();
62 ret.Data = new Dictionary<string, object>();
63
64 string sql = string.Format("select * from '{0}' where UUID = @principalID", m_Realm);
65
66 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
67 using (SqlCommand cmd = new SqlCommand(sql, conn))
68 {
69 cmd.Parameters.AddWithValue("@principalID", principalID.ToString());
70 conn.Open();
71 using (SqlDataReader result = cmd.ExecuteReader())
72 {
73 if (result.Read())
74 {
75 ret.PrincipalID = principalID;
76
77 if (m_ColumnNames == null)
78 {
79 m_ColumnNames = new List<string>();
80
81 DataTable schemaTable = result.GetSchemaTable();
82 foreach (DataRow row in schemaTable.Rows)
83 m_ColumnNames.Add(row["ColumnName"].ToString());
84 }
85
86 foreach (string s in m_ColumnNames)
87 {
88 if (s == "UUID")
89 continue;
90
91 ret.Data[s] = result[s].ToString();
92 }
93 return ret;
94 }
95 }
96 }
97 return null;
98 }
99
100 public bool Store(AuthenticationData data)
101 {
102 if (data.Data.ContainsKey("UUID"))
103 data.Data.Remove("UUID");
104
105 string[] fields = new List<string>(data.Data.Keys).ToArray();
106 StringBuilder updateBuilder = new StringBuilder();
107
108 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
109 using (SqlCommand cmd = new SqlCommand())
110 {
111 updateBuilder.AppendFormat("update '{0}' set ", m_Realm);
112
113 bool first = true;
114 foreach (string field in fields)
115 {
116 if (!first)
117 updateBuilder.Append(", ");
118 updateBuilder.AppendFormat("'{0}' = @{0}",field);
119
120 first = false;
121
122 cmd.Parameters.AddWithValue("@" + field, data.Data[field]);
123 }
124
125 updateBuilder.Append(" where UUID = @principalID");
126
127 cmd.CommandText = updateBuilder.ToString();
128 cmd.Connection = conn;
129
130 cmd.Parameters.AddWithValue("@principalID", data.PrincipalID.ToString());
131 conn.Open();
132 if (cmd.ExecuteNonQuery() < 1)
133 {
134 StringBuilder insertBuilder = new StringBuilder();
135
136 insertBuilder.AppendFormat("insert into '{0}' ('UUID', '", m_Realm);
137 insertBuilder.Append(String.Join("', '", fields));
138 insertBuilder.Append("') values ( @principalID, @");
139 insertBuilder.Append(String.Join(", @", fields));
140 insertBuilder.Append(")");
141
142 cmd.CommandText = insertBuilder.ToString();
143
144 if (cmd.ExecuteNonQuery() < 1)
145 {
146 return false;
147 }
148 }
149 }
150 return true;
151 }
152
153 public bool SetDataItem(UUID principalID, string item, string value)
154 {
155 string sql = string.Format("update '{0}' set '{1}' = @{1} where UUID = @UUID", m_Realm, item);
156 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
157 using (SqlCommand cmd = new SqlCommand(sql, conn))
158 {
159 cmd.Parameters.AddWithValue("@" + item, value);
160 cmd.Parameters.AddWithValue("@UUID", principalID.ToString());
161 conn.Open();
162 if (cmd.ExecuteNonQuery() > 0)
163 return true;
164 }
165 return false;
166 }
167
168 public bool SetToken(UUID principalID, string token, int lifetime)
169 {
170 if (System.Environment.TickCount - m_LastExpire > 30000)
171 DoExpire();
172 string sql = "insert into tokens (UUID, token, validity) values (@principalID, @token, date_add(now(), interval @lifetime minute))";
173 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
174 using (SqlCommand cmd = new SqlCommand(sql, conn))
175 {
176 cmd.Parameters.AddWithValue("@principalID", principalID.ToString());
177 cmd.Parameters.AddWithValue("@token", token);
178 cmd.Parameters.AddWithValue("@lifetime", lifetime.ToString());
179 conn.Open();
180
181 if (cmd.ExecuteNonQuery() > 0)
182 {
183 return true;
184 }
185 }
186 return false;
187 }
188
189 public bool CheckToken(UUID principalID, string token, int lifetime)
190 {
191 if (System.Environment.TickCount - m_LastExpire > 30000)
192 DoExpire();
193 string sql = "update tokens set validity = date_add(now(), interval @lifetime minute) where UUID = @principalID and token = @token and validity > now()";
194 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
195 using (SqlCommand cmd = new SqlCommand(sql, conn))
196 {
197 cmd.Parameters.AddWithValue("@principalID", principalID.ToString());
198 cmd.Parameters.AddWithValue("@token", token);
199 cmd.Parameters.AddWithValue("@lifetime", lifetime.ToString());
200 conn.Open();
201
202 if (cmd.ExecuteNonQuery() > 0)
203 {
204 return true;
205 }
206 }
207 return false;
208 }
209
210 private void DoExpire()
211 {
212 string sql = "delete from tokens where validity < now()";
213 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
214 using (SqlCommand cmd = new SqlCommand(sql, conn))
215 {
216 conn.Open();
217 cmd.ExecuteNonQuery();
218 }
219 m_LastExpire = System.Environment.TickCount;
220 }
221 }
222}
diff --git a/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs
new file mode 100644
index 0000000..1520888
--- /dev/null
+++ b/OpenSim/Data/MSSQL/MSSQLUserAccountData.cs
@@ -0,0 +1,186 @@
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 System.Data.SqlClient;
35using System.Text;
36
37namespace OpenSim.Data.MSSQL
38{
39 public class MSSQLUserAccountData : IUserAccountData
40 {
41 private string m_Realm;
42 private List<string> m_ColumnNames = null;
43 private int m_LastExpire = 0;
44 private string m_ConnectionString;
45
46 public MSSQLUserAccountData(string connectionString, string realm)
47 {
48 m_Realm = realm;
49 m_ConnectionString = connectionString;
50 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
51 {
52 conn.Open();
53 Migration m = new Migration(conn, GetType().Assembly, "UserStore");
54 m.Update();
55 }
56 }
57
58 public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query)
59 {
60 return null;
61 }
62
63 public UserAccountData Get(UUID principalID, UUID scopeID)
64 {
65 UserAccountData ret = new UserAccountData();
66 ret.Data = new Dictionary<string, object>();
67
68 string sql = string.Format("select * from '{0}' where UUID = @principalID", m_Realm);
69 if (scopeID != UUID.Zero)
70 sql += " and ScopeID = @scopeID";
71
72 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
73 using (SqlCommand cmd = new SqlCommand(sql, conn))
74 {
75
76 cmd.Parameters.AddWithValue("@principalID", principalID);
77 cmd.Parameters.AddWithValue("@scopeID", scopeID);
78 conn.Open();
79 using (SqlDataReader result = cmd.ExecuteReader())
80 {
81 if (result.Read())
82 {
83 ret.PrincipalID = principalID;
84 UUID scope;
85 UUID.TryParse(result["ScopeID"].ToString(), out scope);
86 ret.ScopeID = scope;
87
88 if (m_ColumnNames == null)
89 {
90 m_ColumnNames = new List<string>();
91
92 DataTable schemaTable = result.GetSchemaTable();
93 foreach (DataRow row in schemaTable.Rows)
94 m_ColumnNames.Add(row["ColumnName"].ToString());
95 }
96
97 foreach (string s in m_ColumnNames)
98 {
99 if (s == "UUID")
100 continue;
101 if (s == "ScopeID")
102 continue;
103
104 ret.Data[s] = result[s].ToString();
105 }
106 return ret;
107 }
108 }
109 }
110 return null;
111 }
112
113 public bool Store(UserAccountData data)
114 {
115 if (data.Data.ContainsKey("UUID"))
116 data.Data.Remove("UUID");
117 if (data.Data.ContainsKey("ScopeID"))
118 data.Data.Remove("ScopeID");
119
120 string[] fields = new List<string>(data.Data.Keys).ToArray();
121
122 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
123 using (SqlCommand cmd = new SqlCommand())
124 {
125 StringBuilder updateBuilder = new StringBuilder();
126 updateBuilder.AppendFormat("update '{0}' set ", m_Realm);
127 bool first = true;
128 foreach (string field in fields)
129 {
130 if (!first)
131 updateBuilder.Append(", ");
132 updateBuilder.AppendFormat("'{0}' = @{0}", field);
133
134 first = false;
135
136 cmd.Parameters.AddWithValue("@" + field, data.Data[field]);
137 }
138
139 updateBuilder.Append(" where UUID = @principalID");
140
141 if (data.ScopeID != UUID.Zero)
142 updateBuilder.Append(" and ScopeID = @scopeID");
143
144 cmd.CommandText = updateBuilder.ToString();
145 cmd.Connection = conn;
146 cmd.Parameters.AddWithValue("@principalID", data.PrincipalID);
147 cmd.Parameters.AddWithValue("@scopeID", data.ScopeID);
148 conn.Open();
149
150 if (cmd.ExecuteNonQuery() < 1)
151 {
152 StringBuilder insertBuilder = new StringBuilder();
153 insertBuilder.AppendFormat("insert into '{0}' ('UUID', 'ScopeID', '", m_Realm);
154 insertBuilder.Append(String.Join("', '", fields));
155 insertBuilder.Append("') values ( @principalID, @scopeID, @");
156 insertBuilder.Append(String.Join(", @", fields));
157 insertBuilder.Append(")");
158
159 cmd.CommandText = insertBuilder.ToString();
160
161 if (cmd.ExecuteNonQuery() < 1)
162 {
163 return false;
164 }
165 }
166 }
167 return true;
168 }
169
170 public bool SetDataItem(UUID principalID, string item, string value)
171 {
172 string sql = string.Format("update '{0}' set '{1}' = @{1} where UUID = @UUID", m_Realm, item);
173 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
174 using (SqlCommand cmd = new SqlCommand(sql, conn))
175 {
176 cmd.Parameters.AddWithValue("@" + item, value);
177 cmd.Parameters.AddWithValue("@UUID", principalID);
178 conn.Open();
179
180 if (cmd.ExecuteNonQuery() > 0)
181 return true;
182 }
183 return false;
184 }
185 }
186}
diff --git a/OpenSim/Data/MSSQL/Resources/011_UserStore.sql b/OpenSim/Data/MSSQL/Resources/011_UserStore.sql
new file mode 100644
index 0000000..5aa064f
--- /dev/null
+++ b/OpenSim/Data/MSSQL/Resources/011_UserStore.sql
@@ -0,0 +1,5 @@
1BEGIN TRANSACTION
2
3ALTER TABLE users ADD scopeID uniqueidentifier not null default '00000000-0000-0000-0000-000000000000'
4
5COMMIT
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
new file mode 100644
index 0000000..39d60ca
--- /dev/null
+++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
@@ -0,0 +1,180 @@
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 MySqlUserAccountData : MySqlFramework, IUserAccountData
39 {
40 private string m_Realm;
41 private List<string> m_ColumnNames = null;
42 private int m_LastExpire = 0;
43
44 public MySqlUserAccountData(string connectionString, string realm)
45 : base(connectionString)
46 {
47 m_Realm = realm;
48
49 Migration m = new Migration(m_Connection, GetType().Assembly, "UserStore");
50 m.Update();
51 }
52
53 public List<UserAccountData> Query(UUID principalID, UUID scopeID, string query)
54 {
55 return null;
56 }
57
58 public UserAccountData Get(UUID principalID, UUID scopeID)
59 {
60 UserAccountData ret = new UserAccountData();
61 ret.Data = new Dictionary<string, object>();
62
63 string command = "select * from `"+m_Realm+"` where UUID = ?principalID";
64 if (scopeID != UUID.Zero)
65 command += " and ScopeID = ?scopeID";
66
67 MySqlCommand cmd = new MySqlCommand(command);
68
69 cmd.Parameters.AddWithValue("?principalID", principalID.ToString());
70 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString());
71
72 IDataReader result = ExecuteReader(cmd);
73
74 if (result.Read())
75 {
76 ret.PrincipalID = principalID;
77 UUID scope;
78 UUID.TryParse(result["ScopeID"].ToString(), out scope);
79 ret.ScopeID = scope;
80
81 if (m_ColumnNames == null)
82 {
83 m_ColumnNames = new List<string>();
84
85 DataTable schemaTable = result.GetSchemaTable();
86 foreach (DataRow row in schemaTable.Rows)
87 m_ColumnNames.Add(row["ColumnName"].ToString());
88 }
89
90 foreach (string s in m_ColumnNames)
91 {
92 if (s == "UUID")
93 continue;
94 if (s == "ScopeID")
95 continue;
96
97 ret.Data[s] = result[s].ToString();
98 }
99
100 result.Close();
101 CloseReaderCommand(cmd);
102
103 return ret;
104 }
105
106 result.Close();
107 CloseReaderCommand(cmd);
108
109 return null;
110 }
111
112 public bool Store(UserAccountData data)
113 {
114 if (data.Data.ContainsKey("UUID"))
115 data.Data.Remove("UUID");
116 if (data.Data.ContainsKey("ScopeID"))
117 data.Data.Remove("ScopeID");
118
119 string[] fields = new List<string>(data.Data.Keys).ToArray();
120
121 MySqlCommand cmd = new MySqlCommand();
122
123 string update = "update `"+m_Realm+"` set ";
124 bool first = true;
125 foreach (string field in fields)
126 {
127 if (!first)
128 update += ", ";
129 update += "`" + field + "` = ?"+field;
130
131 first = false;
132
133 cmd.Parameters.AddWithValue("?"+field, data.Data[field]);
134 }
135
136 update += " where UUID = ?principalID";
137
138 if (data.ScopeID != UUID.Zero)
139 update += " and ScopeID = ?scopeID";
140
141 cmd.CommandText = update;
142 cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
143 cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
144
145 if (ExecuteNonQuery(cmd) < 1)
146 {
147 string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" +
148 String.Join("`, `", fields) +
149 "`) values ( ?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")";
150
151 cmd.CommandText = insert;
152
153 if (ExecuteNonQuery(cmd) < 1)
154 {
155 cmd.Dispose();
156 return false;
157 }
158 }
159
160 cmd.Dispose();
161
162 return true;
163 }
164
165 public bool SetDataItem(UUID principalID, string item, string value)
166 {
167 MySqlCommand cmd = new MySqlCommand("update `" + m_Realm +
168 "` set `" + item + "` = ?" + item + " where UUID = ?UUID");
169
170
171 cmd.Parameters.AddWithValue("?"+item, value);
172 cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
173
174 if (ExecuteNonQuery(cmd) > 0)
175 return true;
176
177 return false;
178 }
179 }
180}
diff --git a/OpenSim/Data/MySQL/Resources/008_UserStore.sql b/OpenSim/Data/MySQL/Resources/008_UserStore.sql
new file mode 100644
index 0000000..4500bd5
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/008_UserStore.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3ALTER TABLE users add scopeID char(36) not null default '00000000-0000-0000-0000-000000000000';
4
5COMMIT;