aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLUserAccountData.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLUserAccountData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLUserAccountData.cs161
1 files changed, 40 insertions, 121 deletions
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
index 3cb0010..a18ac66 100644
--- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs
+++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs
@@ -35,150 +35,69 @@ 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 48
68 string command = "select * from `"+m_Realm+"` where UUID = ?principalID"; 49 bool valid = false;
69 if (scopeID != UUID.Zero)
70 command += " and ScopeID = ?scopeID";
71 50
72 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 51 for (int i = 0 ; i < words.Length ; i++)
73 { 52 {
74 dbcon.Open(); 53 if (words[i].Length > 2)
75 MySqlCommand cmd = new MySqlCommand(command, dbcon); 54 valid = true;
76 55// if (words[i].Length < 3)
77 cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); 56// {
78 cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); 57// if (i != words.Length - 1)
79 58// Array.Copy(words, i + 1, words, i, words.Length - i - 1);
80 IDataReader result = cmd.ExecuteReader(); 59// Array.Resize(ref words, words.Length - 1);
81 60// }
82 if (result.Read()) 61 }
83 {
84 ret.PrincipalID = principalID;
85 UUID scope;
86 UUID.TryParse(result["ScopeID"].ToString(), out scope);
87 ret.ScopeID = scope;
88
89 if (m_ColumnNames == null)
90 {
91 m_ColumnNames = new List<string>();
92 62
93 DataTable schemaTable = result.GetSchemaTable(); 63 if ((!valid) || words.Length == 0)
94 foreach (DataRow row in schemaTable.Rows) 64 return new UserAccountData[0];
95 m_ColumnNames.Add(row["ColumnName"].ToString());
96 }
97 65
98 foreach (string s in m_ColumnNames) 66 if (words.Length > 2)
99 { 67 return new UserAccountData[0];
100 if (s == "UUID")
101 continue;
102 if (s == "ScopeID")
103 continue;
104 68
105 ret.Data[s] = result[s].ToString(); 69 MySqlCommand cmd = new MySqlCommand();
106 }
107 70
108 return ret; 71 if (words.Length == 1)
109 } 72 {
110 else 73 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) and active=1", m_Realm);
111 { 74 cmd.Parameters.AddWithValue("?search", words[0] + "%");
112 return null; 75 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
113 }
114 } 76 }
115 } 77 else
116
117 public bool Store(UserAccountData data)
118 {
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 { 78 {
128 string update = "update `" + m_Realm + "` set "; 79 cmd.CommandText = String.Format("select * from {0} where (ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like ?searchFirst and LastName like ?searchLast) and active=1", m_Realm);
129 bool first = true; 80 cmd.Parameters.AddWithValue("?searchFirst", words[0] + "%");
130 foreach (string field in fields) 81 cmd.Parameters.AddWithValue("?searchLast", words[1] + "%");
131 { 82 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
132 if (!first)
133 update += ", ";
134 update += "`" + field + "` = ?" + field;
135
136 first = false;
137
138 cmd.Parameters.AddWithValue("?" + field, data.Data[field]);
139 }
140
141 update += " where UUID = ?principalID";
142
143 if (data.ScopeID != UUID.Zero)
144 update += " and ScopeID = ?scopeID";
145
146 cmd.CommandText = update;
147 cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString());
148 cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString());
149
150 if (ExecuteNonQuery(cmd) < 1)
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 } 83 }
165 84
166 return true; 85 return DoQuery(cmd);
167 } 86 }
168 87
169 public bool SetDataItem(UUID principalID, string item, string value) 88 public UserAccountData[] GetUsersWhere(UUID scopeID, string where)
170 { 89 {
171 using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" + 90 MySqlCommand cmd = new MySqlCommand();
172 item + "` = ?" + item + " where UUID = ?UUID"))
173 {
174 cmd.Parameters.AddWithValue("?" + item, value);
175 cmd.Parameters.AddWithValue("?UUID", principalID.ToString());
176 91
177 if (ExecuteNonQuery(cmd) > 0) 92 if (scopeID != UUID.Zero)
178 return true; 93 {
94 where = "(ScopeID=?ScopeID or ScopeID='00000000-0000-0000-0000-000000000000') and (" + where + ")";
95 cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString());
179 } 96 }
180 97
181 return false; 98 cmd.CommandText = String.Format("select * from {0} where " + where, m_Realm);
99
100 return DoQuery(cmd);
182 } 101 }
183 } 102 }
184} 103}