aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL
diff options
context:
space:
mode:
authorMelanie2009-12-29 18:31:27 +0000
committerMelanie2009-12-29 18:31:27 +0000
commit18ca978b81fb504b53bddadf292319b85807a299 (patch)
tree6b692d64a318d056246aa64a1edd89b37a048802 /OpenSim/Data/MySQL
parent* Added useraccount table (diff)
downloadopensim-SC_OLD-18ca978b81fb504b53bddadf292319b85807a299.zip
opensim-SC_OLD-18ca978b81fb504b53bddadf292319b85807a299.tar.gz
opensim-SC_OLD-18ca978b81fb504b53bddadf292319b85807a299.tar.bz2
opensim-SC_OLD-18ca978b81fb504b53bddadf292319b85807a299.tar.xz
Give the new user tables the once-over. Strip the current set of methods
from IUserAccountService, we need to define what goes in there. Change the handler to the generic handler. Adjust migrations, add index
Diffstat (limited to 'OpenSim/Data/MySQL')
-rw-r--r--OpenSim/Data/MySQL/MySQLUserAccountData.cs139
-rw-r--r--OpenSim/Data/MySQL/Resources/001_UserAccount.sql4
-rw-r--r--OpenSim/Data/MySQL/Resources/002_UserAccount.sql5
-rw-r--r--OpenSim/Data/MySQL/Resources/003_UserAccount.sql9
4 files changed, 18 insertions, 139 deletions
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
index d48144d..9624d79 100644
--- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
@@ -35,146 +35,11 @@ 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 = null;
42// private int m_LastExpire = 0;
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
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 { 42 {
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 } 43 }
179 } 44 }
180} 45}
diff --git a/OpenSim/Data/MySQL/Resources/001_UserAccount.sql b/OpenSim/Data/MySQL/Resources/001_UserAccount.sql
index f946430..7d63816 100644
--- a/OpenSim/Data/MySQL/Resources/001_UserAccount.sql
+++ b/OpenSim/Data/MySQL/Resources/001_UserAccount.sql
@@ -1,7 +1,7 @@
1BEGIN; 1BEGIN;
2 2
3CREATE TABLE `useraccount` ( 3CREATE TABLE `UserAccounts` (
4 `UserID` CHAR(36) NOT NULL, 4 `PrincipalID` CHAR(36) NOT NULL,
5 `ScopeID` CHAR(36) NOT NULL, 5 `ScopeID` CHAR(36) NOT NULL,
6 `FirstName` VARCHAR(64) NOT NULL, 6 `FirstName` VARCHAR(64) NOT NULL,
7 `LastName` VARCHAR(64) NOT NULL, 7 `LastName` VARCHAR(64) NOT NULL,
diff --git a/OpenSim/Data/MySQL/Resources/002_UserAccount.sql b/OpenSim/Data/MySQL/Resources/002_UserAccount.sql
new file mode 100644
index 0000000..08a0f87
--- /dev/null
+++ b/OpenSim/Data/MySQL/Resources/002_UserAccount.sql
@@ -0,0 +1,5 @@
1BEGIN;
2
3INSERT INTO UserAccounts (UserID, 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_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;