diff options
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLUserAccountData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLUserAccountData.cs | 142 |
1 files changed, 23 insertions, 119 deletions
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs index d48144d..aa69d68 100644 --- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs +++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs | |||
@@ -35,146 +35,50 @@ using MySql.Data.MySqlClient; | |||
35 | 35 | ||
36 | namespace OpenSim.Data.MySQL | 36 | namespace 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 | { | 42 | { |
55 | return null; | ||
56 | } | 43 | } |
57 | 44 | ||
58 | public UserAccountData Get(UUID principalID, UUID scopeID) | 45 | public UserAccountData[] GetUsers(UUID scopeID, string query) |
59 | { | 46 | { |
60 | UserAccountData ret = new UserAccountData(); | 47 | string[] words = query.Split(new char[] {' '}); |
61 | ret.Data = new Dictionary<string, object>(); | ||
62 | 48 | ||
63 | string command = "select * from `"+m_Realm+"` where UUID = ?principalID"; | 49 | for (int i = 0 ; i < words.Length ; i++) |
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 | { | 50 | { |
76 | ret.PrincipalID = principalID; | 51 | if (words[i].Length < 3) |
77 | UUID scope; | ||
78 | UUID.TryParse(result["ScopeID"].ToString(), out scope); | ||
79 | ret.ScopeID = scope; | ||
80 | |||
81 | if (m_ColumnNames == null) | ||
82 | { | 52 | { |
83 | m_ColumnNames = new List<string>(); | 53 | if (i != words.Length - 1) |
84 | 54 | Array.Copy(words, i + 1, words, i, words.Length - i - 1); | |
85 | DataTable schemaTable = result.GetSchemaTable(); | 55 | Array.Resize(ref words, words.Length - 1); |
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 | } | 56 | } |
99 | |||
100 | result.Close(); | ||
101 | CloseReaderCommand(cmd); | ||
102 | |||
103 | return ret; | ||
104 | } | 57 | } |
105 | 58 | ||
106 | result.Close(); | 59 | if (words.Length == 0) |
107 | CloseReaderCommand(cmd); | 60 | return new UserAccountData[0]; |
108 | 61 | ||
109 | return null; | 62 | if (words.Length > 2) |
110 | } | 63 | return new UserAccountData[0]; |
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 | 64 | ||
121 | MySqlCommand cmd = new MySqlCommand(); | 65 | MySqlCommand cmd = new MySqlCommand(); |
122 | 66 | ||
123 | string update = "update `"+m_Realm+"` set "; | 67 | if (words.Length == 1) |
124 | bool first = true; | ||
125 | foreach (string field in fields) | ||
126 | { | 68 | { |
127 | if (!first) | 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); |
128 | update += ", "; | 70 | cmd.Parameters.AddWithValue("?search", "%" + words[0] + "%"); |
129 | update += "`" + field + "` = ?"+field; | 71 | cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); |
130 | |||
131 | first = false; | ||
132 | |||
133 | cmd.Parameters.AddWithValue("?"+field, data.Data[field]); | ||
134 | } | 72 | } |
135 | 73 | else | |
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 | { | 74 | { |
147 | string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" + | 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); |
148 | String.Join("`, `", fields) + | 76 | cmd.Parameters.AddWithValue("?searchFirst", "%" + words[0] + "%"); |
149 | "`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")"; | 77 | cmd.Parameters.AddWithValue("?searchLast", "%" + words[1] + "%"); |
150 | 78 | cmd.Parameters.AddWithValue("?ScopeID", scopeID.ToString()); | |
151 | cmd.CommandText = insert; | ||
152 | |||
153 | if (ExecuteNonQuery(cmd) < 1) | ||
154 | { | ||
155 | cmd.Dispose(); | ||
156 | return false; | ||
157 | } | ||
158 | } | 79 | } |
159 | 80 | ||
160 | cmd.Dispose(); | 81 | return DoQuery(cmd); |
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 | } | 82 | } |
179 | } | 83 | } |
180 | } | 84 | } |