aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLAssetData.cs
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2012-04-30 15:54:35 +0100
committerJustin Clark-Casey (justincc)2012-04-30 15:54:35 +0100
commit522eff61383e9a8acfdf34289cd64a8fdc27bb19 (patch)
tree3e9d6428bf6832caafd69d45c3a377a9f643dcae /OpenSim/Data/MySQL/MySQLAssetData.cs
parentComment out debug [ASYNC DELETER] messages for now. (diff)
downloadopensim-SC_OLD-522eff61383e9a8acfdf34289cd64a8fdc27bb19.zip
opensim-SC_OLD-522eff61383e9a8acfdf34289cd64a8fdc27bb19.tar.gz
opensim-SC_OLD-522eff61383e9a8acfdf34289cd64a8fdc27bb19.tar.bz2
opensim-SC_OLD-522eff61383e9a8acfdf34289cd64a8fdc27bb19.tar.xz
Consistently use using() to make sure we dispose of used MySqlCommands where this is not already being done.
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLAssetData.cs')
-rw-r--r--OpenSim/Data/MySQL/MySQLAssetData.cs180
1 files changed, 92 insertions, 88 deletions
diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs
index a743479..73de64b 100644
--- a/OpenSim/Data/MySQL/MySQLAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLAssetData.cs
@@ -163,52 +163,51 @@ namespace OpenSim.Data.MySQL
163 { 163 {
164 dbcon.Open(); 164 dbcon.Open();
165 165
166 MySqlCommand cmd = 166 using (MySqlCommand cmd =
167 new MySqlCommand( 167 new MySqlCommand(
168 "replace INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, asset_flags, CreatorID, data)" + 168 "replace INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, asset_flags, CreatorID, data)" +
169 "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?CreatorID, ?data)", 169 "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?CreatorID, ?data)",
170 dbcon); 170 dbcon))
171
172 string assetName = asset.Name;
173 if (asset.Name.Length > 64)
174 {
175 assetName = asset.Name.Substring(0, 64);
176 m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on add");
177 }
178
179 string assetDescription = asset.Description;
180 if (asset.Description.Length > 64)
181 {
182 assetDescription = asset.Description.Substring(0, 64);
183 m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
184 }
185
186 // need to ensure we dispose
187 try
188 { 171 {
189 using (cmd) 172 string assetName = asset.Name;
173 if (asset.Name.Length > 64)
190 { 174 {
191 // create unix epoch time 175 assetName = asset.Name.Substring(0, 64);
192 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); 176 m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on add");
193 cmd.Parameters.AddWithValue("?id", asset.ID); 177 }
194 cmd.Parameters.AddWithValue("?name", assetName); 178
195 cmd.Parameters.AddWithValue("?description", assetDescription); 179 string assetDescription = asset.Description;
196 cmd.Parameters.AddWithValue("?assetType", asset.Type); 180 if (asset.Description.Length > 64)
197 cmd.Parameters.AddWithValue("?local", asset.Local); 181 {
198 cmd.Parameters.AddWithValue("?temporary", asset.Temporary); 182 assetDescription = asset.Description.Substring(0, 64);
199 cmd.Parameters.AddWithValue("?create_time", now); 183 m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
200 cmd.Parameters.AddWithValue("?access_time", now); 184 }
201 cmd.Parameters.AddWithValue("?CreatorID", asset.Metadata.CreatorID); 185
202 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); 186 try
203 cmd.Parameters.AddWithValue("?data", asset.Data); 187 {
204 cmd.ExecuteNonQuery(); 188 using (cmd)
205 cmd.Dispose(); 189 {
190 // create unix epoch time
191 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
192 cmd.Parameters.AddWithValue("?id", asset.ID);
193 cmd.Parameters.AddWithValue("?name", assetName);
194 cmd.Parameters.AddWithValue("?description", assetDescription);
195 cmd.Parameters.AddWithValue("?assetType", asset.Type);
196 cmd.Parameters.AddWithValue("?local", asset.Local);
197 cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
198 cmd.Parameters.AddWithValue("?create_time", now);
199 cmd.Parameters.AddWithValue("?access_time", now);
200 cmd.Parameters.AddWithValue("?CreatorID", asset.Metadata.CreatorID);
201 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
202 cmd.Parameters.AddWithValue("?data", asset.Data);
203 cmd.ExecuteNonQuery();
204 }
205 }
206 catch (Exception e)
207 {
208 m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}",
209 asset.FullID, asset.Name, e.Message);
206 } 210 }
207 }
208 catch (Exception e)
209 {
210 m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}",
211 asset.FullID, asset.Name, e.Message);
212 } 211 }
213 } 212 }
214 } 213 }
@@ -221,33 +220,31 @@ namespace OpenSim.Data.MySQL
221 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 220 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
222 { 221 {
223 dbcon.Open(); 222 dbcon.Open();
224 MySqlCommand cmd =
225 new MySqlCommand("update assets set access_time=?access_time where id=?id",
226 dbcon);
227 223
228 // need to ensure we dispose 224 using (MySqlCommand cmd
229 try 225 = new MySqlCommand("update assets set access_time=?access_time where id=?id", dbcon))
230 { 226 {
231 using (cmd) 227 try
232 { 228 {
233 // create unix epoch time 229 using (cmd)
234 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); 230 {
235 cmd.Parameters.AddWithValue("?id", asset.ID); 231 // create unix epoch time
236 cmd.Parameters.AddWithValue("?access_time", now); 232 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
237 cmd.ExecuteNonQuery(); 233 cmd.Parameters.AddWithValue("?id", asset.ID);
238 cmd.Dispose(); 234 cmd.Parameters.AddWithValue("?access_time", now);
235 cmd.ExecuteNonQuery();
236 }
237 }
238 catch (Exception e)
239 {
240 m_log.ErrorFormat(
241 "[ASSETS DB]: " +
242 "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString()
243 + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
239 } 244 }
240 }
241 catch (Exception e)
242 {
243 m_log.ErrorFormat(
244 "[ASSETS DB]: " +
245 "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString()
246 + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
247 } 245 }
248 } 246 }
249 } 247 }
250
251 } 248 }
252 249
253 /// <summary> 250 /// <summary>
@@ -310,35 +307,41 @@ namespace OpenSim.Data.MySQL
310 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 307 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
311 { 308 {
312 dbcon.Open(); 309 dbcon.Open();
313 MySqlCommand cmd = new MySqlCommand("SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count", dbcon);
314 cmd.Parameters.AddWithValue("?start", start);
315 cmd.Parameters.AddWithValue("?count", count);
316 310
317 try 311 using (MySqlCommand cmd
312 = new MySqlCommand(
313 "SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count",
314 dbcon))
318 { 315 {
319 using (MySqlDataReader dbReader = cmd.ExecuteReader()) 316 cmd.Parameters.AddWithValue("?start", start);
317 cmd.Parameters.AddWithValue("?count", count);
318
319 try
320 { 320 {
321 while (dbReader.Read()) 321 using (MySqlDataReader dbReader = cmd.ExecuteReader())
322 { 322 {
323 AssetMetadata metadata = new AssetMetadata(); 323 while (dbReader.Read())
324 metadata.Name = (string)dbReader["name"]; 324 {
325 metadata.Description = (string)dbReader["description"]; 325 AssetMetadata metadata = new AssetMetadata();
326 metadata.Type = (sbyte)dbReader["assetType"]; 326 metadata.Name = (string)dbReader["name"];
327 metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct. 327 metadata.Description = (string)dbReader["description"];
328 metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); 328 metadata.Type = (sbyte)dbReader["assetType"];
329 metadata.FullID = DBGuid.FromDB(dbReader["id"]); 329 metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct.
330 metadata.CreatorID = dbReader["CreatorID"].ToString(); 330 metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
331 331 metadata.FullID = DBGuid.FromDB(dbReader["id"]);
332 // Current SHA1s are not stored/computed. 332 metadata.CreatorID = dbReader["CreatorID"].ToString();
333 metadata.SHA1 = new byte[] { }; 333
334 334 // Current SHA1s are not stored/computed.
335 retList.Add(metadata); 335 metadata.SHA1 = new byte[] { };
336
337 retList.Add(metadata);
338 }
336 } 339 }
337 } 340 }
338 } 341 catch (Exception e)
339 catch (Exception e) 342 {
340 { 343 m_log.Error("[ASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString());
341 m_log.Error("[ASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString()); 344 }
342 } 345 }
343 } 346 }
344 } 347 }
@@ -353,11 +356,12 @@ namespace OpenSim.Data.MySQL
353 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 356 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
354 { 357 {
355 dbcon.Open(); 358 dbcon.Open();
356 MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id", dbcon);
357 cmd.Parameters.AddWithValue("?id", id);
358 cmd.ExecuteNonQuery();
359 359
360 cmd.Dispose(); 360 using (MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id", dbcon))
361 {
362 cmd.Parameters.AddWithValue("?id", id);
363 cmd.ExecuteNonQuery();
364 }
361 } 365 }
362 } 366 }
363 367
@@ -366,4 +370,4 @@ namespace OpenSim.Data.MySQL
366 370
367 #endregion 371 #endregion
368 } 372 }
369} 373} \ No newline at end of file