aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-11-14 04:45:59 +0000
committerJustin Clark-Casey (justincc)2012-11-14 04:45:59 +0000
commit94da908813e42c328572bc5da2ddc41b6664b59c (patch)
tree1a3e1ffaadb34cac64c798f5cc06eadf612c6af9
parentIf no ISimulationDataStore or IEstateDataStore implementations could be loade... (diff)
downloadopensim-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.
-rw-r--r--OpenSim/Data/SQLite/SQLiteAssetData.cs14
-rw-r--r--OpenSim/Data/SQLite/SQLiteAuthenticationData.cs145
-rw-r--r--OpenSim/Data/SQLite/SQLiteAvatarData.cs22
-rw-r--r--OpenSim/Data/SQLite/SQLiteEstateData.cs206
-rw-r--r--OpenSim/Data/SQLite/SQLiteFramework.cs9
-rw-r--r--OpenSim/Data/SQLite/SQLiteFriendsData.cs25
-rw-r--r--OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs106
-rw-r--r--OpenSim/Data/SQLite/SQLiteUserAccountData.cs25
-rw-r--r--OpenSim/Data/SQLite/SQLiteXInventoryData.cs51
9 files changed, 305 insertions, 298 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs
index d0e24c3..61e7aaf 100644
--- a/OpenSim/Data/SQLite/SQLiteAssetData.cs
+++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs
@@ -202,7 +202,8 @@ namespace OpenSim.Data.SQLite
202 /// <returns>True if exist, or false.</returns> 202 /// <returns>True if exist, or false.</returns>
203 override public bool ExistsAsset(UUID uuid) 203 override public bool ExistsAsset(UUID uuid)
204 { 204 {
205 lock (this) { 205 lock (this)
206 {
206 using (SqliteCommand cmd = new SqliteCommand(SelectAssetSQL, m_conn)) 207 using (SqliteCommand cmd = new SqliteCommand(SelectAssetSQL, m_conn))
207 { 208 {
208 cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString())); 209 cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString()));
@@ -353,12 +354,13 @@ namespace OpenSim.Data.SQLite
353 { 354 {
354 lock (this) 355 lock (this)
355 { 356 {
356 using (SqliteCommand cmd = new SqliteCommand(DeleteAssetSQL, m_conn)) 357 using (SqliteCommand cmd = new SqliteCommand(DeleteAssetSQL, m_conn))
357 { 358 {
358 cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString())); 359 cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString()));
359 cmd.ExecuteNonQuery(); 360 cmd.ExecuteNonQuery();
360 } 361 }
361 } 362 }
363
362 return true; 364 return true;
363 } 365 }
364 366
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
diff --git a/OpenSim/Data/SQLite/SQLiteAvatarData.cs b/OpenSim/Data/SQLite/SQLiteAvatarData.cs
index faf34da..c6d615b 100644
--- a/OpenSim/Data/SQLite/SQLiteAvatarData.cs
+++ b/OpenSim/Data/SQLite/SQLiteAvatarData.cs
@@ -56,23 +56,17 @@ namespace OpenSim.Data.SQLite
56 56
57 public bool Delete(UUID principalID, string name) 57 public bool Delete(UUID principalID, string name)
58 { 58 {
59 SqliteCommand cmd = new SqliteCommand(); 59 using (SqliteCommand cmd = new SqliteCommand())
60
61 cmd.CommandText = String.Format("delete from {0} where `PrincipalID` = :PrincipalID and `Name` = :Name", m_Realm);
62 cmd.Parameters.AddWithValue(":PrincipalID", principalID.ToString());
63 cmd.Parameters.AddWithValue(":Name", name);
64
65 try
66 { 60 {
61 cmd.CommandText = String.Format("delete from {0} where `PrincipalID` = :PrincipalID and `Name` = :Name", m_Realm);
62 cmd.Parameters.AddWithValue(":PrincipalID", principalID.ToString());
63 cmd.Parameters.AddWithValue(":Name", name);
64
67 if (ExecuteNonQuery(cmd, m_Connection) > 0) 65 if (ExecuteNonQuery(cmd, m_Connection) > 0)
68 return true; 66 return true;
69
70 return false;
71 }
72 finally
73 {
74 //CloseCommand(cmd);
75 } 67 }
68
69 return false;
76 } 70 }
77 } 71 }
78} 72} \ No newline at end of file
diff --git a/OpenSim/Data/SQLite/SQLiteEstateData.cs b/OpenSim/Data/SQLite/SQLiteEstateData.cs
index c042ba2..d51f2d4 100644
--- a/OpenSim/Data/SQLite/SQLiteEstateData.cs
+++ b/OpenSim/Data/SQLite/SQLiteEstateData.cs
@@ -104,12 +104,13 @@ namespace OpenSim.Data.SQLite
104 { 104 {
105 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = :RegionID"; 105 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_map left join estate_settings on estate_map.EstateID = estate_settings.EstateID where estate_settings.EstateID is not null and RegionID = :RegionID";
106 106
107 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 107 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
108 108 {
109 cmd.CommandText = sql; 109 cmd.CommandText = sql;
110 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString()); 110 cmd.Parameters.AddWithValue(":RegionID", regionID.ToString());
111 111
112 return DoLoad(cmd, regionID, create); 112 return DoLoad(cmd, regionID, create);
113 }
113 } 114 }
114 115
115 private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create) 116 private EstateSettings DoLoad(SqliteCommand cmd, UUID regionID, bool create)
@@ -186,37 +187,39 @@ namespace OpenSim.Data.SQLite
186 { 187 {
187 List<string> names = new List<string>(FieldList); 188 List<string> names = new List<string>(FieldList);
188 189
189 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand();
190 IDataReader r = null; 190 IDataReader r = null;
191 191
192 names.Remove("EstateID"); 192 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
193 {
194 names.Remove("EstateID");
193 195
194 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")"; 196 string sql = "insert into estate_settings ("+String.Join(",", names.ToArray())+") values ( :"+String.Join(", :", names.ToArray())+")";
195 197
196 cmd.CommandText = sql; 198 cmd.CommandText = sql;
197 cmd.Parameters.Clear(); 199 cmd.Parameters.Clear();
198 200
199 foreach (string name in FieldList) 201 foreach (string name in FieldList)
200 {
201 if (m_FieldMap[name].GetValue(es) is bool)
202 { 202 {
203 if ((bool)m_FieldMap[name].GetValue(es)) 203 if (m_FieldMap[name].GetValue(es) is bool)
204 cmd.Parameters.AddWithValue(":"+name, "1"); 204 {
205 if ((bool)m_FieldMap[name].GetValue(es))
206 cmd.Parameters.AddWithValue(":"+name, "1");
207 else
208 cmd.Parameters.AddWithValue(":"+name, "0");
209 }
205 else 210 else
206 cmd.Parameters.AddWithValue(":"+name, "0"); 211 {
207 } 212 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
208 else 213 }
209 {
210 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
211 } 214 }
212 }
213 215
214 cmd.ExecuteNonQuery(); 216 cmd.ExecuteNonQuery();
215 217
216 cmd.CommandText = "select LAST_INSERT_ROWID() as id"; 218 cmd.CommandText = "select LAST_INSERT_ROWID() as id";
217 cmd.Parameters.Clear(); 219 cmd.Parameters.Clear();
218 220
219 r = cmd.ExecuteReader(); 221 r = cmd.ExecuteReader();
222 }
220 223
221 r.Read(); 224 r.Read();
222 225
@@ -239,26 +242,27 @@ namespace OpenSim.Data.SQLite
239 242
240 string sql = "update estate_settings set "+String.Join(", ", terms.ToArray())+" where EstateID = :EstateID"; 243 string sql = "update estate_settings set "+String.Join(", ", terms.ToArray())+" where EstateID = :EstateID";
241 244
242 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 245 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
243
244 cmd.CommandText = sql;
245
246 foreach (string name in FieldList)
247 { 246 {
248 if (m_FieldMap[name].GetValue(es) is bool) 247 cmd.CommandText = sql;
248
249 foreach (string name in FieldList)
249 { 250 {
250 if ((bool)m_FieldMap[name].GetValue(es)) 251 if (m_FieldMap[name].GetValue(es) is bool)
251 cmd.Parameters.AddWithValue(":"+name, "1"); 252 {
253 if ((bool)m_FieldMap[name].GetValue(es))
254 cmd.Parameters.AddWithValue(":"+name, "1");
255 else
256 cmd.Parameters.AddWithValue(":"+name, "0");
257 }
252 else 258 else
253 cmd.Parameters.AddWithValue(":"+name, "0"); 259 {
254 } 260 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
255 else 261 }
256 {
257 cmd.Parameters.AddWithValue(":"+name, m_FieldMap[name].GetValue(es).ToString());
258 } 262 }
259 }
260 263
261 cmd.ExecuteNonQuery(); 264 cmd.ExecuteNonQuery();
265 }
262 266
263 SaveBanList(es); 267 SaveBanList(es);
264 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers); 268 SaveUUIDList(es.EstateID, "estate_managers", es.EstateManagers);
@@ -270,12 +274,15 @@ namespace OpenSim.Data.SQLite
270 { 274 {
271 es.ClearBans(); 275 es.ClearBans();
272 276
273 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 277 IDataReader r;
274 278
275 cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID"; 279 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
276 cmd.Parameters.AddWithValue(":EstateID", es.EstateID); 280 {
281 cmd.CommandText = "select bannedUUID from estateban where EstateID = :EstateID";
282 cmd.Parameters.AddWithValue(":EstateID", es.EstateID);
277 283
278 IDataReader r = cmd.ExecuteReader(); 284 r = cmd.ExecuteReader();
285 }
279 286
280 while (r.Read()) 287 while (r.Read())
281 { 288 {
@@ -294,60 +301,64 @@ namespace OpenSim.Data.SQLite
294 301
295 private void SaveBanList(EstateSettings es) 302 private void SaveBanList(EstateSettings es)
296 { 303 {
297 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 304 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
298
299 cmd.CommandText = "delete from estateban where EstateID = :EstateID";
300 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
301
302 cmd.ExecuteNonQuery();
303
304 cmd.Parameters.Clear();
305
306 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( :EstateID, :bannedUUID, '', '', '' )";
307
308 foreach (EstateBan b in es.EstateBans)
309 { 305 {
306 cmd.CommandText = "delete from estateban where EstateID = :EstateID";
310 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString()); 307 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
311 cmd.Parameters.AddWithValue(":bannedUUID", b.BannedUserID.ToString());
312 308
313 cmd.ExecuteNonQuery(); 309 cmd.ExecuteNonQuery();
310
314 cmd.Parameters.Clear(); 311 cmd.Parameters.Clear();
312
313 cmd.CommandText = "insert into estateban (EstateID, bannedUUID, bannedIp, bannedIpHostMask, bannedNameMask) values ( :EstateID, :bannedUUID, '', '', '' )";
314
315 foreach (EstateBan b in es.EstateBans)
316 {
317 cmd.Parameters.AddWithValue(":EstateID", es.EstateID.ToString());
318 cmd.Parameters.AddWithValue(":bannedUUID", b.BannedUserID.ToString());
319
320 cmd.ExecuteNonQuery();
321 cmd.Parameters.Clear();
322 }
315 } 323 }
316 } 324 }
317 325
318 void SaveUUIDList(uint EstateID, string table, UUID[] data) 326 void SaveUUIDList(uint EstateID, string table, UUID[] data)
319 { 327 {
320 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 328 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
321
322 cmd.CommandText = "delete from "+table+" where EstateID = :EstateID";
323 cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString());
324
325 cmd.ExecuteNonQuery();
326
327 cmd.Parameters.Clear();
328
329 cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( :EstateID, :uuid )";
330
331 foreach (UUID uuid in data)
332 { 329 {
330 cmd.CommandText = "delete from "+table+" where EstateID = :EstateID";
333 cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString()); 331 cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString());
334 cmd.Parameters.AddWithValue(":uuid", uuid.ToString());
335 332
336 cmd.ExecuteNonQuery(); 333 cmd.ExecuteNonQuery();
334
337 cmd.Parameters.Clear(); 335 cmd.Parameters.Clear();
336
337 cmd.CommandText = "insert into "+table+" (EstateID, uuid) values ( :EstateID, :uuid )";
338
339 foreach (UUID uuid in data)
340 {
341 cmd.Parameters.AddWithValue(":EstateID", EstateID.ToString());
342 cmd.Parameters.AddWithValue(":uuid", uuid.ToString());
343
344 cmd.ExecuteNonQuery();
345 cmd.Parameters.Clear();
346 }
338 } 347 }
339 } 348 }
340 349
341 UUID[] LoadUUIDList(uint EstateID, string table) 350 UUID[] LoadUUIDList(uint EstateID, string table)
342 { 351 {
343 List<UUID> uuids = new List<UUID>(); 352 List<UUID> uuids = new List<UUID>();
353 IDataReader r;
344 354
345 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 355 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
346 356 {
347 cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID"; 357 cmd.CommandText = "select uuid from "+table+" where EstateID = :EstateID";
348 cmd.Parameters.AddWithValue(":EstateID", EstateID); 358 cmd.Parameters.AddWithValue(":EstateID", EstateID);
349 359
350 IDataReader r = cmd.ExecuteReader(); 360 r = cmd.ExecuteReader();
361 }
351 362
352 while (r.Read()) 363 while (r.Read())
353 { 364 {
@@ -367,12 +378,13 @@ namespace OpenSim.Data.SQLite
367 { 378 {
368 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID = :EstateID"; 379 string sql = "select estate_settings."+String.Join(",estate_settings.", FieldList)+" from estate_settings where estate_settings.EstateID = :EstateID";
369 380
370 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 381 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
371 382 {
372 cmd.CommandText = sql; 383 cmd.CommandText = sql;
373 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString()); 384 cmd.Parameters.AddWithValue(":EstateID", estateID.ToString());
374 385
375 return DoLoad(cmd, UUID.Zero, false); 386 return DoLoad(cmd, UUID.Zero, false);
387 }
376 } 388 }
377 389
378 public List<EstateSettings> LoadEstateSettingsAll() 390 public List<EstateSettings> LoadEstateSettingsAll()
@@ -391,13 +403,15 @@ namespace OpenSim.Data.SQLite
391 List<int> result = new List<int>(); 403 List<int> result = new List<int>();
392 404
393 string sql = "select EstateID from estate_settings where estate_settings.EstateName = :EstateName"; 405 string sql = "select EstateID from estate_settings where estate_settings.EstateName = :EstateName";
406 IDataReader r;
394 407
395 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 408 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
396 409 {
397 cmd.CommandText = sql; 410 cmd.CommandText = sql;
398 cmd.Parameters.AddWithValue(":EstateName", search); 411 cmd.Parameters.AddWithValue(":EstateName", search);
399 412
400 IDataReader r = cmd.ExecuteReader(); 413 r = cmd.ExecuteReader();
414 }
401 415
402 while (r.Read()) 416 while (r.Read())
403 { 417 {
@@ -413,12 +427,14 @@ namespace OpenSim.Data.SQLite
413 List<int> result = new List<int>(); 427 List<int> result = new List<int>();
414 428
415 string sql = "select EstateID from estate_settings"; 429 string sql = "select EstateID from estate_settings";
430 IDataReader r;
416 431
417 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 432 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
418 433 {
419 cmd.CommandText = sql; 434 cmd.CommandText = sql;
420 435
421 IDataReader r = cmd.ExecuteReader(); 436 r = cmd.ExecuteReader();
437 }
422 438
423 while (r.Read()) 439 while (r.Read())
424 { 440 {
@@ -434,13 +450,15 @@ namespace OpenSim.Data.SQLite
434 List<int> result = new List<int>(); 450 List<int> result = new List<int>();
435 451
436 string sql = "select EstateID from estate_settings where estate_settings.EstateOwner = :EstateOwner"; 452 string sql = "select EstateID from estate_settings where estate_settings.EstateOwner = :EstateOwner";
453 IDataReader r;
437 454
438 SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand(); 455 using (SqliteCommand cmd = (SqliteCommand)m_connection.CreateCommand())
439 456 {
440 cmd.CommandText = sql; 457 cmd.CommandText = sql;
441 cmd.Parameters.AddWithValue(":EstateOwner", ownerID); 458 cmd.Parameters.AddWithValue(":EstateOwner", ownerID);
442 459
443 IDataReader r = cmd.ExecuteReader(); 460 r = cmd.ExecuteReader();
461 }
444 462
445 while (r.Read()) 463 while (r.Read())
446 { 464 {
diff --git a/OpenSim/Data/SQLite/SQLiteFramework.cs b/OpenSim/Data/SQLite/SQLiteFramework.cs
index 1594717..35b9a2f 100644
--- a/OpenSim/Data/SQLite/SQLiteFramework.cs
+++ b/OpenSim/Data/SQLite/SQLiteFramework.cs
@@ -90,12 +90,5 @@ namespace OpenSim.Data.SQLite
90 return cmd.ExecuteReader(); 90 return cmd.ExecuteReader();
91 } 91 }
92 } 92 }
93
94 protected void CloseCommand(SqliteCommand cmd)
95 {
96 cmd.Connection.Close();
97 cmd.Connection.Dispose();
98 cmd.Dispose();
99 }
100 } 93 }
101} 94} \ No newline at end of file
diff --git a/OpenSim/Data/SQLite/SQLiteFriendsData.cs b/OpenSim/Data/SQLite/SQLiteFriendsData.cs
index 5f68977..cab85eb 100644
--- a/OpenSim/Data/SQLite/SQLiteFriendsData.cs
+++ b/OpenSim/Data/SQLite/SQLiteFriendsData.cs
@@ -53,13 +53,13 @@ namespace OpenSim.Data.SQLite
53 53
54 public FriendsData[] GetFriends(string userID) 54 public FriendsData[] GetFriends(string userID)
55 { 55 {
56 SqliteCommand cmd = new SqliteCommand(); 56 using (SqliteCommand cmd = new SqliteCommand())
57 57 {
58 cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = :PrincipalID", m_Realm); 58 cmd.CommandText = String.Format("select a.*,case when b.Flags is null then -1 else b.Flags end as TheirFlags from {0} as a left join {0} as b on a.PrincipalID = b.Friend and a.Friend = b.PrincipalID where a.PrincipalID = :PrincipalID", m_Realm);
59 cmd.Parameters.AddWithValue(":PrincipalID", userID.ToString()); 59 cmd.Parameters.AddWithValue(":PrincipalID", userID.ToString());
60
61 return DoQuery(cmd);
62 60
61 return DoQuery(cmd);
62 }
63 } 63 }
64 64
65 public bool Delete(UUID principalID, string friend) 65 public bool Delete(UUID principalID, string friend)
@@ -69,13 +69,14 @@ namespace OpenSim.Data.SQLite
69 69
70 public bool Delete(string principalID, string friend) 70 public bool Delete(string principalID, string friend)
71 { 71 {
72 SqliteCommand cmd = new SqliteCommand(); 72 using (SqliteCommand cmd = new SqliteCommand())
73 73 {
74 cmd.CommandText = String.Format("delete from {0} where PrincipalID = :PrincipalID and Friend = :Friend", m_Realm); 74 cmd.CommandText = String.Format("delete from {0} where PrincipalID = :PrincipalID and Friend = :Friend", m_Realm);
75 cmd.Parameters.AddWithValue(":PrincipalID", principalID.ToString()); 75 cmd.Parameters.AddWithValue(":PrincipalID", principalID.ToString());
76 cmd.Parameters.AddWithValue(":Friend", friend); 76 cmd.Parameters.AddWithValue(":Friend", friend);
77 77
78 ExecuteNonQuery(cmd, m_Connection); 78 ExecuteNonQuery(cmd, m_Connection);
79 }
79 80
80 return true; 81 return true;
81 } 82 }
diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
index 4f977a8..917a0a1 100644
--- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
+++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
@@ -132,22 +132,23 @@ namespace OpenSim.Data.SQLite
132 132
133 List<string> terms = new List<string>(); 133 List<string> terms = new List<string>();
134 134
135 SqliteCommand cmd = new SqliteCommand(); 135 using (SqliteCommand cmd = new SqliteCommand())
136
137 for (int i = 0 ; i < fields.Length ; i++)
138 { 136 {
139 cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); 137 for (int i = 0 ; i < fields.Length ; i++)
140 terms.Add("`" + fields[i] + "` = :" + fields[i]); 138 {
141 } 139 cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i]));
140 terms.Add("`" + fields[i] + "` = :" + fields[i]);
141 }
142 142
143 string where = String.Join(" and ", terms.ToArray()); 143 string where = String.Join(" and ", terms.ToArray());
144 144
145 string query = String.Format("select * from {0} where {1}", 145 string query = String.Format("select * from {0} where {1}",
146 m_Realm, where); 146 m_Realm, where);
147 147
148 cmd.CommandText = query; 148 cmd.CommandText = query;
149 149
150 return DoQuery(cmd); 150 return DoQuery(cmd);
151 }
151 } 152 }
152 153
153 protected T[] DoQuery(SqliteCommand cmd) 154 protected T[] DoQuery(SqliteCommand cmd)
@@ -214,50 +215,52 @@ namespace OpenSim.Data.SQLite
214 215
215 public T[] Get(string where) 216 public T[] Get(string where)
216 { 217 {
217 SqliteCommand cmd = new SqliteCommand(); 218 using (SqliteCommand cmd = new SqliteCommand())
218 219 {
219 string query = String.Format("select * from {0} where {1}", 220 string query = String.Format("select * from {0} where {1}",
220 m_Realm, where); 221 m_Realm, where);
221 222
222 cmd.CommandText = query; 223 cmd.CommandText = query;
223 224
224 return DoQuery(cmd); 225 return DoQuery(cmd);
226 }
225 } 227 }
226 228
227 public bool Store(T row) 229 public bool Store(T row)
228 { 230 {
229 SqliteCommand cmd = new SqliteCommand(); 231 using (SqliteCommand cmd = new SqliteCommand())
230
231 string query = "";
232 List<String> names = new List<String>();
233 List<String> values = new List<String>();
234
235 foreach (FieldInfo fi in m_Fields.Values)
236 { 232 {
237 names.Add(fi.Name); 233 string query = "";
238 values.Add(":" + fi.Name); 234 List<String> names = new List<String>();
239 cmd.Parameters.Add(new SqliteParameter(":" + fi.Name, fi.GetValue(row).ToString())); 235 List<String> values = new List<String>();
240 }
241 236
242 if (m_DataField != null) 237 foreach (FieldInfo fi in m_Fields.Values)
243 { 238 {
244 Dictionary<string, string> data = 239 names.Add(fi.Name);
245 (Dictionary<string, string>)m_DataField.GetValue(row); 240 values.Add(":" + fi.Name);
241 cmd.Parameters.Add(new SqliteParameter(":" + fi.Name, fi.GetValue(row).ToString()));
242 }
246 243
247 foreach (KeyValuePair<string, string> kvp in data) 244 if (m_DataField != null)
248 { 245 {
249 names.Add(kvp.Key); 246 Dictionary<string, string> data =
250 values.Add(":" + kvp.Key); 247 (Dictionary<string, string>)m_DataField.GetValue(row);
251 cmd.Parameters.Add(new SqliteParameter(":" + kvp.Key, kvp.Value)); 248
249 foreach (KeyValuePair<string, string> kvp in data)
250 {
251 names.Add(kvp.Key);
252 values.Add(":" + kvp.Key);
253 cmd.Parameters.Add(new SqliteParameter(":" + kvp.Key, kvp.Value));
254 }
252 } 255 }
253 }
254 256
255 query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values (" + String.Join(",", values.ToArray()) + ")"; 257 query = String.Format("replace into {0} (`", m_Realm) + String.Join("`,`", names.ToArray()) + "`) values (" + String.Join(",", values.ToArray()) + ")";
256 258
257 cmd.CommandText = query; 259 cmd.CommandText = query;
258 260
259 if (ExecuteNonQuery(cmd, m_Connection) > 0) 261 if (ExecuteNonQuery(cmd, m_Connection) > 0)
260 return true; 262 return true;
263 }
261 264
262 return false; 265 return false;
263 } 266 }
@@ -274,21 +277,22 @@ namespace OpenSim.Data.SQLite
274 277
275 List<string> terms = new List<string>(); 278 List<string> terms = new List<string>();
276 279
277 SqliteCommand cmd = new SqliteCommand(); 280 using (SqliteCommand cmd = new SqliteCommand())
278
279 for (int i = 0 ; i < fields.Length ; i++)
280 { 281 {
281 cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i])); 282 for (int i = 0 ; i < fields.Length ; i++)
282 terms.Add("`" + fields[i] + "` = :" + fields[i]); 283 {
283 } 284 cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i]));
285 terms.Add("`" + fields[i] + "` = :" + fields[i]);
286 }
284 287
285 string where = String.Join(" and ", terms.ToArray()); 288 string where = String.Join(" and ", terms.ToArray());
286 289
287 string query = String.Format("delete from {0} where {1}", m_Realm, where); 290 string query = String.Format("delete from {0} where {1}", m_Realm, where);
288 291
289 cmd.CommandText = query; 292 cmd.CommandText = query;
290 293
291 return ExecuteNonQuery(cmd, m_Connection) > 0; 294 return ExecuteNonQuery(cmd, m_Connection) > 0;
295 }
292 } 296 }
293 } 297 }
294} 298}
diff --git a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs
index 7a5de50..f98d376 100644
--- a/OpenSim/Data/SQLite/SQLiteUserAccountData.cs
+++ b/OpenSim/Data/SQLite/SQLiteUserAccountData.cs
@@ -66,20 +66,21 @@ namespace OpenSim.Data.SQLite
66 if (words.Length > 2) 66 if (words.Length > 2)
67 return new UserAccountData[0]; 67 return new UserAccountData[0];
68 68
69 SqliteCommand cmd = new SqliteCommand(); 69 using (SqliteCommand cmd = new SqliteCommand())
70
71 if (words.Length == 1)
72 {
73 cmd.CommandText = String.Format("select * from {0} where (ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{2}%')",
74 m_Realm, scopeID.ToString(), words[0]);
75 }
76 else
77 { 70 {
78 cmd.CommandText = String.Format("select * from {0} where (ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{3}%')", 71 if (words.Length == 1)
79 m_Realm, scopeID.ToString(), words[0], words[1]); 72 {
80 } 73 cmd.CommandText = String.Format("select * from {0} where (ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{2}%')",
74 m_Realm, scopeID.ToString(), words[0]);
75 }
76 else
77 {
78 cmd.CommandText = String.Format("select * from {0} where (ScopeID='{1}' or ScopeID='00000000-0000-0000-0000-000000000000') and (FirstName like '{2}%' or LastName like '{3}%')",
79 m_Realm, scopeID.ToString(), words[0], words[1]);
80 }
81 81
82 return DoQuery(cmd); 82 return DoQuery(cmd);
83 }
83 } 84 }
84 } 85 }
85} 86}
diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
index 75f8c87..8eb1a63 100644
--- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
+++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
@@ -139,35 +139,41 @@ namespace OpenSim.Data.SQLite
139 139
140 public bool MoveItem(string id, string newParent) 140 public bool MoveItem(string id, string newParent)
141 { 141 {
142 SqliteCommand cmd = new SqliteCommand(); 142 using (SqliteCommand cmd = new SqliteCommand())
143 143 {
144 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm); 144 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where inventoryID = :InventoryID", m_Realm);
145 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent)); 145 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParent));
146 cmd.Parameters.Add(new SqliteParameter(":InventoryID", id)); 146 cmd.Parameters.Add(new SqliteParameter(":InventoryID", id));
147 147
148 return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; 148 return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true;
149 }
149 } 150 }
150 151
151 public XInventoryItem[] GetActiveGestures(UUID principalID) 152 public XInventoryItem[] GetActiveGestures(UUID principalID)
152 { 153 {
153 SqliteCommand cmd = new SqliteCommand(); 154 using (SqliteCommand cmd = new SqliteCommand())
154 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = :uuid and assetType = :type and flags = 1", m_Realm); 155 {
156 cmd.CommandText = String.Format("select * from inventoryitems where avatarId = :uuid and assetType = :type and flags = 1", m_Realm);
155 157
156 cmd.Parameters.Add(new SqliteParameter(":uuid", principalID.ToString())); 158 cmd.Parameters.Add(new SqliteParameter(":uuid", principalID.ToString()));
157 cmd.Parameters.Add(new SqliteParameter(":type", (int)AssetType.Gesture)); 159 cmd.Parameters.Add(new SqliteParameter(":type", (int)AssetType.Gesture));
158 160
159 return DoQuery(cmd); 161 return DoQuery(cmd);
162 }
160 } 163 }
161 164
162 public int GetAssetPermissions(UUID principalID, UUID assetID) 165 public int GetAssetPermissions(UUID principalID, UUID assetID)
163 { 166 {
164 SqliteCommand cmd = new SqliteCommand(); 167 IDataReader reader;
165 168
166 cmd.CommandText = String.Format("select inventoryCurrentPermissions from inventoryitems where avatarID = :PrincipalID and assetID = :AssetID", m_Realm); 169 using (SqliteCommand cmd = new SqliteCommand())
167 cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString())); 170 {
168 cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString())); 171 cmd.CommandText = String.Format("select inventoryCurrentPermissions from inventoryitems where avatarID = :PrincipalID and assetID = :AssetID", m_Realm);
172 cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString()));
173 cmd.Parameters.Add(new SqliteParameter(":AssetID", assetID.ToString()));
169 174
170 IDataReader reader = ExecuteReader(cmd, m_Connection); 175 reader = ExecuteReader(cmd, m_Connection);
176 }
171 177
172 int perms = 0; 178 int perms = 0;
173 179
@@ -192,13 +198,14 @@ namespace OpenSim.Data.SQLite
192 198
193 public bool MoveFolder(string id, string newParentFolderID) 199 public bool MoveFolder(string id, string newParentFolderID)
194 { 200 {
195 SqliteCommand cmd = new SqliteCommand(); 201 using (SqliteCommand cmd = new SqliteCommand())
196 202 {
197 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm); 203 cmd.CommandText = String.Format("update {0} set parentFolderID = :ParentFolderID where folderID = :FolderID", m_Realm);
198 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID)); 204 cmd.Parameters.Add(new SqliteParameter(":ParentFolderID", newParentFolderID));
199 cmd.Parameters.Add(new SqliteParameter(":FolderID", id)); 205 cmd.Parameters.Add(new SqliteParameter(":FolderID", id));
200 206
201 return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true; 207 return ExecuteNonQuery(cmd, m_Connection) == 0 ? false : true;
208 }
202 } 209 }
203 } 210 }
204} \ No newline at end of file 211} \ No newline at end of file