aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL
diff options
context:
space:
mode:
authorMelanie2009-09-06 04:28:42 +0100
committerMelanie2009-09-06 04:28:42 +0100
commit2a8f66b221e93fb2d693c1c273c2dee85439f835 (patch)
treeea20d88556279d7d56bc9a15e7372652a814f835 /OpenSim/Data/MySQL
parentMerge branch 'master' of ssh://MyConnection/var/git/opensim (diff)
downloadopensim-SC-2a8f66b221e93fb2d693c1c273c2dee85439f835.zip
opensim-SC-2a8f66b221e93fb2d693c1c273c2dee85439f835.tar.gz
opensim-SC-2a8f66b221e93fb2d693c1c273c2dee85439f835.tar.bz2
opensim-SC-2a8f66b221e93fb2d693c1c273c2dee85439f835.tar.xz
Revising the user account data interfaces. No user functionality yet
Diffstat (limited to 'OpenSim/Data/MySQL')
-rw-r--r--OpenSim/Data/MySQL/MySQLUserAccountData.cs180
-rw-r--r--OpenSim/Data/MySQL/Resources/008_UserStore.sql5
2 files changed, 185 insertions, 0 deletions
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;