diff options
author | Justin Clark-Casey (justincc) | 2012-11-14 04:45:59 +0000 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2012-11-14 04:45:59 +0000 |
commit | 94da908813e42c328572bc5da2ddc41b6664b59c (patch) | |
tree | 1a3e1ffaadb34cac64c798f5cc06eadf612c6af9 /OpenSim/Data/SQLite/SQLiteAuthenticationData.cs | |
parent | If no ISimulationDataStore or IEstateDataStore implementations could be loade... (diff) | |
download | opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.zip opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.tar.gz opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.tar.bz2 opensim-SC-94da908813e42c328572bc5da2ddc41b6664b59c.tar.xz |
More consistently dispose of SqliteCommand in OpenSim.Data.SQLite where possible.
Not doing SQLiteInventoryStore since this is no longer used and should disappear in the future.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteAuthenticationData.cs | 145 |
1 files changed, 66 insertions, 79 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs index 5120453..0428c11 100644 --- a/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs +++ b/OpenSim/Data/SQLite/SQLiteAuthenticationData.cs | |||
@@ -82,11 +82,14 @@ namespace OpenSim.Data.SQLite | |||
82 | { | 82 | { |
83 | AuthenticationData ret = new AuthenticationData(); | 83 | AuthenticationData ret = new AuthenticationData(); |
84 | ret.Data = new Dictionary<string, object>(); | 84 | ret.Data = new Dictionary<string, object>(); |
85 | IDataReader result; | ||
85 | 86 | ||
86 | SqliteCommand cmd = new SqliteCommand("select * from `" + m_Realm + "` where UUID = :PrincipalID"); | 87 | using (SqliteCommand cmd = new SqliteCommand("select * from `" + m_Realm + "` where UUID = :PrincipalID")) |
87 | cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); | 88 | { |
89 | cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); | ||
88 | 90 | ||
89 | IDataReader result = ExecuteReader(cmd, m_Connection); | 91 | result = ExecuteReader(cmd, m_Connection); |
92 | } | ||
90 | 93 | ||
91 | try | 94 | try |
92 | { | 95 | { |
@@ -121,10 +124,6 @@ namespace OpenSim.Data.SQLite | |||
121 | catch | 124 | catch |
122 | { | 125 | { |
123 | } | 126 | } |
124 | finally | ||
125 | { | ||
126 | //CloseCommand(cmd); | ||
127 | } | ||
128 | 127 | ||
129 | return null; | 128 | return null; |
130 | } | 129 | } |
@@ -140,84 +139,81 @@ namespace OpenSim.Data.SQLite | |||
140 | foreach (object o in data.Data.Values) | 139 | foreach (object o in data.Data.Values) |
141 | values[i++] = o.ToString(); | 140 | values[i++] = o.ToString(); |
142 | 141 | ||
143 | SqliteCommand cmd = new SqliteCommand(); | 142 | using (SqliteCommand cmd = new SqliteCommand()) |
144 | |||
145 | if (Get(data.PrincipalID) != null) | ||
146 | { | 143 | { |
144 | if (Get(data.PrincipalID) != null) | ||
145 | { | ||
147 | 146 | ||
148 | 147 | ||
149 | string update = "update `" + m_Realm + "` set "; | 148 | string update = "update `" + m_Realm + "` set "; |
150 | bool first = true; | 149 | bool first = true; |
151 | foreach (string field in fields) | 150 | foreach (string field in fields) |
152 | { | 151 | { |
153 | if (!first) | 152 | if (!first) |
154 | update += ", "; | 153 | update += ", "; |
155 | update += "`" + field + "` = :" + field; | 154 | update += "`" + field + "` = :" + field; |
156 | cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); | 155 | cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); |
157 | 156 | ||
158 | first = false; | 157 | first = false; |
159 | } | 158 | } |
160 | 159 | ||
161 | update += " where UUID = :UUID"; | 160 | update += " where UUID = :UUID"; |
162 | cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); | 161 | cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); |
163 | 162 | ||
164 | cmd.CommandText = update; | 163 | cmd.CommandText = update; |
165 | try | 164 | try |
166 | { | 165 | { |
167 | if (ExecuteNonQuery(cmd, m_Connection) < 1) | 166 | if (ExecuteNonQuery(cmd, m_Connection) < 1) |
167 | { | ||
168 | //CloseCommand(cmd); | ||
169 | return false; | ||
170 | } | ||
171 | } | ||
172 | catch (Exception e) | ||
168 | { | 173 | { |
174 | m_log.Error("[SQLITE]: Exception storing authentication data", e); | ||
169 | //CloseCommand(cmd); | 175 | //CloseCommand(cmd); |
170 | return false; | 176 | return false; |
171 | } | 177 | } |
172 | } | 178 | } |
173 | catch (Exception e) | 179 | else |
174 | { | 180 | { |
175 | m_log.Error("[SQLITE]: Exception storing authentication data", e); | 181 | string insert = "insert into `" + m_Realm + "` (`UUID`, `" + |
176 | //CloseCommand(cmd); | 182 | String.Join("`, `", fields) + |
177 | return false; | 183 | "`) values (:UUID, :" + String.Join(", :", fields) + ")"; |
178 | } | ||
179 | } | ||
180 | 184 | ||
181 | else | 185 | cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); |
182 | { | 186 | foreach (string field in fields) |
183 | string insert = "insert into `" + m_Realm + "` (`UUID`, `" + | 187 | cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); |
184 | String.Join("`, `", fields) + | ||
185 | "`) values (:UUID, :" + String.Join(", :", fields) + ")"; | ||
186 | |||
187 | cmd.Parameters.Add(new SqliteParameter(":UUID", data.PrincipalID.ToString())); | ||
188 | foreach (string field in fields) | ||
189 | cmd.Parameters.Add(new SqliteParameter(":" + field, data.Data[field])); | ||
190 | 188 | ||
191 | cmd.CommandText = insert; | 189 | cmd.CommandText = insert; |
192 | 190 | ||
193 | try | 191 | try |
194 | { | ||
195 | if (ExecuteNonQuery(cmd, m_Connection) < 1) | ||
196 | { | 192 | { |
197 | //CloseCommand(cmd); | 193 | if (ExecuteNonQuery(cmd, m_Connection) < 1) |
194 | { | ||
195 | return false; | ||
196 | } | ||
197 | } | ||
198 | catch (Exception e) | ||
199 | { | ||
200 | Console.WriteLine(e.ToString()); | ||
198 | return false; | 201 | return false; |
199 | } | 202 | } |
200 | } | 203 | } |
201 | catch (Exception e) | ||
202 | { | ||
203 | Console.WriteLine(e.ToString()); | ||
204 | //CloseCommand(cmd); | ||
205 | return false; | ||
206 | } | ||
207 | } | 204 | } |
208 | 205 | ||
209 | //CloseCommand(cmd); | ||
210 | |||
211 | return true; | 206 | return true; |
212 | } | 207 | } |
213 | 208 | ||
214 | public bool SetDataItem(UUID principalID, string item, string value) | 209 | public bool SetDataItem(UUID principalID, string item, string value) |
215 | { | 210 | { |
216 | SqliteCommand cmd = new SqliteCommand("update `" + m_Realm + | 211 | using (SqliteCommand cmd = new SqliteCommand("update `" + m_Realm + |
217 | "` set `" + item + "` = " + value + " where UUID = '" + principalID.ToString() + "'"); | 212 | "` set `" + item + "` = " + value + " where UUID = '" + principalID.ToString() + "'")) |
218 | 213 | { | |
219 | if (ExecuteNonQuery(cmd, m_Connection) > 0) | 214 | if (ExecuteNonQuery(cmd, m_Connection) > 0) |
220 | return true; | 215 | return true; |
216 | } | ||
221 | 217 | ||
222 | return false; | 218 | return false; |
223 | } | 219 | } |
@@ -227,16 +223,13 @@ namespace OpenSim.Data.SQLite | |||
227 | if (System.Environment.TickCount - m_LastExpire > 30000) | 223 | if (System.Environment.TickCount - m_LastExpire > 30000) |
228 | DoExpire(); | 224 | DoExpire(); |
229 | 225 | ||
230 | SqliteCommand cmd = new SqliteCommand("insert into tokens (UUID, token, validity) values ('" + principalID.ToString() + | 226 | using (SqliteCommand cmd = new SqliteCommand("insert into tokens (UUID, token, validity) values ('" + principalID.ToString() + |
231 | "', '" + token + "', datetime('now', 'localtime', '+" + lifetime.ToString() + " minutes'))"); | 227 | "', '" + token + "', datetime('now', 'localtime', '+" + lifetime.ToString() + " minutes'))")) |
232 | |||
233 | if (ExecuteNonQuery(cmd, m_Connection) > 0) | ||
234 | { | 228 | { |
235 | cmd.Dispose(); | 229 | if (ExecuteNonQuery(cmd, m_Connection) > 0) |
236 | return true; | 230 | return true; |
237 | } | 231 | } |
238 | 232 | ||
239 | cmd.Dispose(); | ||
240 | return false; | 233 | return false; |
241 | } | 234 | } |
242 | 235 | ||
@@ -245,28 +238,22 @@ namespace OpenSim.Data.SQLite | |||
245 | if (System.Environment.TickCount - m_LastExpire > 30000) | 238 | if (System.Environment.TickCount - m_LastExpire > 30000) |
246 | DoExpire(); | 239 | DoExpire(); |
247 | 240 | ||
248 | SqliteCommand cmd = new SqliteCommand("update tokens set validity = datetime('now', 'localtime', '+" + lifetime.ToString() + | 241 | using (SqliteCommand cmd = new SqliteCommand("update tokens set validity = datetime('now', 'localtime', '+" + lifetime.ToString() + |
249 | " minutes') where UUID = '" + principalID.ToString() + "' and token = '" + token + "' and validity > datetime('now', 'localtime')"); | 242 | " minutes') where UUID = '" + principalID.ToString() + "' and token = '" + token + "' and validity > datetime('now', 'localtime')")) |
250 | |||
251 | if (ExecuteNonQuery(cmd, m_Connection) > 0) | ||
252 | { | 243 | { |
253 | cmd.Dispose(); | 244 | if (ExecuteNonQuery(cmd, m_Connection) > 0) |
254 | return true; | 245 | return true; |
255 | } | 246 | } |
256 | 247 | ||
257 | cmd.Dispose(); | ||
258 | |||
259 | return false; | 248 | return false; |
260 | } | 249 | } |
261 | 250 | ||
262 | private void DoExpire() | 251 | private void DoExpire() |
263 | { | 252 | { |
264 | SqliteCommand cmd = new SqliteCommand("delete from tokens where validity < datetime('now', 'localtime')"); | 253 | using (SqliteCommand cmd = new SqliteCommand("delete from tokens where validity < datetime('now', 'localtime')")) |
265 | ExecuteNonQuery(cmd, m_Connection); | 254 | ExecuteNonQuery(cmd, m_Connection); |
266 | |||
267 | cmd.Dispose(); | ||
268 | 255 | ||
269 | m_LastExpire = System.Environment.TickCount; | 256 | m_LastExpire = System.Environment.TickCount; |
270 | } | 257 | } |
271 | } | 258 | } |
272 | } | 259 | } \ No newline at end of file |