aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MySQL/MySQLAssetData.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Data/MySQL/MySQLAssetData.cs182
1 files changed, 93 insertions, 89 deletions
diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs
index a22dc0a..20df234 100644
--- a/OpenSim/Data/MySQL/MySQLAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLAssetData.cs
@@ -163,54 +163,53 @@ 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 {
206 return true; 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 return true;
205 }
206 }
207 catch (Exception e)
208 {
209 m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}",
210 asset.FullID, asset.Name, e.Message);
211 return false;
207 } 212 }
208 }
209 catch (Exception e)
210 {
211 m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}",
212 asset.FullID, asset.Name, e.Message);
213 return false;
214 } 213 }
215 } 214 }
216 } 215 }
@@ -223,33 +222,31 @@ namespace OpenSim.Data.MySQL
223 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 222 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
224 { 223 {
225 dbcon.Open(); 224 dbcon.Open();
226 MySqlCommand cmd =
227 new MySqlCommand("update assets set access_time=?access_time where id=?id",
228 dbcon);
229 225
230 // need to ensure we dispose 226 using (MySqlCommand cmd
231 try 227 = new MySqlCommand("update assets set access_time=?access_time where id=?id", dbcon))
232 { 228 {
233 using (cmd) 229 try
234 { 230 {
235 // create unix epoch time 231 using (cmd)
236 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); 232 {
237 cmd.Parameters.AddWithValue("?id", asset.ID); 233 // create unix epoch time
238 cmd.Parameters.AddWithValue("?access_time", now); 234 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
239 cmd.ExecuteNonQuery(); 235 cmd.Parameters.AddWithValue("?id", asset.ID);
240 cmd.Dispose(); 236 cmd.Parameters.AddWithValue("?access_time", now);
237 cmd.ExecuteNonQuery();
238 }
239 }
240 catch (Exception e)
241 {
242 m_log.ErrorFormat(
243 "[ASSETS DB]: " +
244 "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString()
245 + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
241 } 246 }
242 }
243 catch (Exception e)
244 {
245 m_log.ErrorFormat(
246 "[ASSETS DB]: " +
247 "MySql failure updating access_time for asset {0} with name {1}" + Environment.NewLine + e.ToString()
248 + Environment.NewLine + "Attempting reconnection", asset.FullID, asset.Name);
249 } 247 }
250 } 248 }
251 } 249 }
252
253 } 250 }
254 251
255 /// <summary> 252 /// <summary>
@@ -312,35 +309,41 @@ namespace OpenSim.Data.MySQL
312 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 309 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
313 { 310 {
314 dbcon.Open(); 311 dbcon.Open();
315 MySqlCommand cmd = new MySqlCommand("SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count", dbcon);
316 cmd.Parameters.AddWithValue("?start", start);
317 cmd.Parameters.AddWithValue("?count", count);
318 312
319 try 313 using (MySqlCommand cmd
314 = new MySqlCommand(
315 "SELECT name,description,assetType,temporary,id,asset_flags,CreatorID FROM assets LIMIT ?start, ?count",
316 dbcon))
320 { 317 {
321 using (MySqlDataReader dbReader = cmd.ExecuteReader()) 318 cmd.Parameters.AddWithValue("?start", start);
319 cmd.Parameters.AddWithValue("?count", count);
320
321 try
322 { 322 {
323 while (dbReader.Read()) 323 using (MySqlDataReader dbReader = cmd.ExecuteReader())
324 { 324 {
325 AssetMetadata metadata = new AssetMetadata(); 325 while (dbReader.Read())
326 metadata.Name = (string)dbReader["name"]; 326 {
327 metadata.Description = (string)dbReader["description"]; 327 AssetMetadata metadata = new AssetMetadata();
328 metadata.Type = (sbyte)dbReader["assetType"]; 328 metadata.Name = (string)dbReader["name"];
329 metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct. 329 metadata.Description = (string)dbReader["description"];
330 metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]); 330 metadata.Type = (sbyte)dbReader["assetType"];
331 metadata.FullID = DBGuid.FromDB(dbReader["id"]); 331 metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]); // Not sure if this is correct.
332 metadata.CreatorID = dbReader["CreatorID"].ToString(); 332 metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
333 333 metadata.FullID = DBGuid.FromDB(dbReader["id"]);
334 // Current SHA1s are not stored/computed. 334 metadata.CreatorID = dbReader["CreatorID"].ToString();
335 metadata.SHA1 = new byte[] { }; 335
336 336 // Current SHA1s are not stored/computed.
337 retList.Add(metadata); 337 metadata.SHA1 = new byte[] { };
338
339 retList.Add(metadata);
340 }
338 } 341 }
339 } 342 }
340 } 343 catch (Exception e)
341 catch (Exception e) 344 {
342 { 345 m_log.Error("[ASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString());
343 m_log.Error("[ASSETS DB]: MySql failure fetching asset set" + Environment.NewLine + e.ToString()); 346 }
344 } 347 }
345 } 348 }
346 } 349 }
@@ -355,11 +358,12 @@ namespace OpenSim.Data.MySQL
355 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) 358 using (MySqlConnection dbcon = new MySqlConnection(m_connectionString))
356 { 359 {
357 dbcon.Open(); 360 dbcon.Open();
358 MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id", dbcon);
359 cmd.Parameters.AddWithValue("?id", id);
360 cmd.ExecuteNonQuery();
361 361
362 cmd.Dispose(); 362 using (MySqlCommand cmd = new MySqlCommand("delete from assets where id=?id", dbcon))
363 {
364 cmd.Parameters.AddWithValue("?id", id);
365 cmd.ExecuteNonQuery();
366 }
363 } 367 }
364 } 368 }
365 369