diff options
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLUserAccountData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLUserAccountData.cs | 141 |
1 files changed, 68 insertions, 73 deletions
diff --git a/OpenSim/Data/MySQL/MySQLUserAccountData.cs b/OpenSim/Data/MySQL/MySQLUserAccountData.cs index d48144d..c713a11 100644 --- a/OpenSim/Data/MySQL/MySQLUserAccountData.cs +++ b/OpenSim/Data/MySQL/MySQLUserAccountData.cs | |||
@@ -64,48 +64,44 @@ namespace OpenSim.Data.MySQL | |||
64 | if (scopeID != UUID.Zero) | 64 | if (scopeID != UUID.Zero) |
65 | command += " and ScopeID = ?scopeID"; | 65 | command += " and ScopeID = ?scopeID"; |
66 | 66 | ||
67 | MySqlCommand cmd = new MySqlCommand(command); | 67 | using (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 | { | 68 | { |
76 | ret.PrincipalID = principalID; | 69 | cmd.Parameters.AddWithValue("?principalID", principalID.ToString()); |
77 | UUID scope; | 70 | cmd.Parameters.AddWithValue("?scopeID", scopeID.ToString()); |
78 | UUID.TryParse(result["ScopeID"].ToString(), out scope); | ||
79 | ret.ScopeID = scope; | ||
80 | 71 | ||
81 | if (m_ColumnNames == null) | 72 | using (IDataReader result = ExecuteReader(cmd)) |
82 | { | 73 | { |
83 | m_ColumnNames = new List<string>(); | 74 | if (result.Read()) |
84 | 75 | { | |
85 | DataTable schemaTable = result.GetSchemaTable(); | 76 | ret.PrincipalID = principalID; |
86 | foreach (DataRow row in schemaTable.Rows) | 77 | UUID scope; |
87 | m_ColumnNames.Add(row["ColumnName"].ToString()); | 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 | return ret; | ||
101 | } | ||
88 | } | 102 | } |
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 | } | 103 | } |
105 | 104 | ||
106 | result.Close(); | ||
107 | CloseReaderCommand(cmd); | ||
108 | |||
109 | return null; | 105 | return null; |
110 | } | 106 | } |
111 | 107 | ||
@@ -118,61 +114,60 @@ namespace OpenSim.Data.MySQL | |||
118 | 114 | ||
119 | string[] fields = new List<string>(data.Data.Keys).ToArray(); | 115 | string[] fields = new List<string>(data.Data.Keys).ToArray(); |
120 | 116 | ||
121 | MySqlCommand cmd = new MySqlCommand(); | 117 | using (MySqlCommand cmd = new MySqlCommand()) |
122 | |||
123 | string update = "update `"+m_Realm+"` set "; | ||
124 | bool first = true; | ||
125 | foreach (string field in fields) | ||
126 | { | 118 | { |
127 | if (!first) | 119 | string update = "update `" + m_Realm + "` set "; |
128 | update += ", "; | 120 | bool first = true; |
129 | update += "`" + field + "` = ?"+field; | 121 | foreach (string field in fields) |
130 | 122 | { | |
131 | first = false; | 123 | if (!first) |
132 | 124 | update += ", "; | |
133 | cmd.Parameters.AddWithValue("?"+field, data.Data[field]); | 125 | update += "`" + field + "` = ?" + field; |
134 | } | ||
135 | 126 | ||
136 | update += " where UUID = ?principalID"; | 127 | first = false; |
137 | 128 | ||
138 | if (data.ScopeID != UUID.Zero) | 129 | cmd.Parameters.AddWithValue("?" + field, data.Data[field]); |
139 | update += " and ScopeID = ?scopeID"; | 130 | } |
140 | 131 | ||
141 | cmd.CommandText = update; | 132 | update += " where UUID = ?principalID"; |
142 | cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); | ||
143 | cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); | ||
144 | 133 | ||
145 | if (ExecuteNonQuery(cmd) < 1) | 134 | if (data.ScopeID != UUID.Zero) |
146 | { | 135 | update += " and ScopeID = ?scopeID"; |
147 | string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" + | ||
148 | String.Join("`, `", fields) + | ||
149 | "`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")"; | ||
150 | 136 | ||
151 | cmd.CommandText = insert; | 137 | cmd.CommandText = update; |
138 | cmd.Parameters.AddWithValue("?principalID", data.PrincipalID.ToString()); | ||
139 | cmd.Parameters.AddWithValue("?scopeID", data.ScopeID.ToString()); | ||
152 | 140 | ||
153 | if (ExecuteNonQuery(cmd) < 1) | 141 | if (ExecuteNonQuery(cmd) < 1) |
154 | { | 142 | { |
155 | cmd.Dispose(); | 143 | string insert = "insert into `" + m_Realm + "` (`UUID`, `ScopeID`, `" + |
156 | return false; | 144 | String.Join("`, `", fields) + |
145 | "`) values (?principalID, ?scopeID, ?" + String.Join(", ?", fields) + ")"; | ||
146 | |||
147 | cmd.CommandText = insert; | ||
148 | |||
149 | if (ExecuteNonQuery(cmd) < 1) | ||
150 | { | ||
151 | cmd.Dispose(); | ||
152 | return false; | ||
153 | } | ||
157 | } | 154 | } |
158 | } | 155 | } |
159 | 156 | ||
160 | cmd.Dispose(); | ||
161 | |||
162 | return true; | 157 | return true; |
163 | } | 158 | } |
164 | 159 | ||
165 | public bool SetDataItem(UUID principalID, string item, string value) | 160 | public bool SetDataItem(UUID principalID, string item, string value) |
166 | { | 161 | { |
167 | MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + | 162 | using (MySqlCommand cmd = new MySqlCommand("update `" + m_Realm + "` set `" + |
168 | "` set `" + item + "` = ?" + item + " where UUID = ?UUID"); | 163 | item + "` = ?" + item + " where UUID = ?UUID")) |
169 | 164 | { | |
170 | 165 | cmd.Parameters.AddWithValue("?" + item, value); | |
171 | cmd.Parameters.AddWithValue("?"+item, value); | 166 | cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); |
172 | cmd.Parameters.AddWithValue("?UUID", principalID.ToString()); | ||
173 | 167 | ||
174 | if (ExecuteNonQuery(cmd) > 0) | 168 | if (ExecuteNonQuery(cmd) > 0) |
175 | return true; | 169 | return true; |
170 | } | ||
176 | 171 | ||
177 | return false; | 172 | return false; |
178 | } | 173 | } |