aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Data')
-rw-r--r--OpenSim/Data/MySQL/MySQLXAssetData.cs76
1 files changed, 59 insertions, 17 deletions
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs
index 778c7f4..748578b 100644
--- a/OpenSim/Data/MySQL/MySQLXAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs
@@ -168,7 +168,6 @@ namespace OpenSim.Data.MySQL
168 168
169 using (MySqlTransaction transaction = dbcon.BeginTransaction()) 169 using (MySqlTransaction transaction = dbcon.BeginTransaction())
170 { 170 {
171
172 string assetName = asset.Name; 171 string assetName = asset.Name;
173 if (asset.Name.Length > 64) 172 if (asset.Name.Length > 64)
174 { 173 {
@@ -220,26 +219,29 @@ namespace OpenSim.Data.MySQL
220 return; 219 return;
221 } 220 }
222 221
223 try 222 if (!ExistsData(dbcon, transaction, hash))
224 { 223 {
225 using (MySqlCommand cmd = 224 try
226 new MySqlCommand(
227 "replace INTO xassetsdata(hash, data) VALUES(?hash, ?data)",
228 dbcon))
229 { 225 {
230 cmd.Parameters.AddWithValue("?hash", hash); 226 using (MySqlCommand cmd =
231 cmd.Parameters.AddWithValue("?data", asset.Data); 227 new MySqlCommand(
232 cmd.ExecuteNonQuery(); 228 "INSERT INTO xassetsdata(hash, data) VALUES(?hash, ?data)",
229 dbcon))
230 {
231 cmd.Parameters.AddWithValue("?hash", hash);
232 cmd.Parameters.AddWithValue("?data", asset.Data);
233 cmd.ExecuteNonQuery();
234 }
233 } 235 }
234 } 236 catch (Exception e)
235 catch (Exception e) 237 {
236 { 238 m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}",
237 m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}", 239 asset.FullID, asset.Name, e.Message);
238 asset.FullID, asset.Name, e.Message);
239
240 transaction.Rollback();
241 240
242 return; 241 transaction.Rollback();
242
243 return;
244 }
243 } 245 }
244 246
245 transaction.Commit(); 247 transaction.Commit();
@@ -285,6 +287,46 @@ namespace OpenSim.Data.MySQL
285// } 287// }
286 288
287 /// <summary> 289 /// <summary>
290 /// We assume we already have the m_dbLock.
291 /// </summary>
292 /// TODO: need to actually use the transaction.
293 /// <param name="dbcon"></param>
294 /// <param name="transaction"></param>
295 /// <param name="hash"></param>
296 /// <returns></returns>
297 private bool ExistsData(MySqlConnection dbcon, MySqlTransaction transaction, string hash)
298 {
299// m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid);
300
301 bool exists = false;
302
303 using (MySqlCommand cmd = new MySqlCommand("SELECT hash FROM xassetsdata WHERE hash=?hash", dbcon))
304 {
305 cmd.Parameters.AddWithValue("?hash", hash);
306
307 try
308 {
309 using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
310 {
311 if (dbReader.Read())
312 {
313// m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid);
314 exists = true;
315 }
316 }
317 }
318 catch (Exception e)
319 {
320 m_log.ErrorFormat(
321 "[XASSETS DB]: MySql failure in ExistsData fetching hash {0}. Exception {1}{2}",
322 hash, e.Message, e.StackTrace);
323 }
324 }
325
326 return exists;
327 }
328
329 /// <summary>
288 /// Check if the asset exists in the database 330 /// Check if the asset exists in the database
289 /// </summary> 331 /// </summary>
290 /// <param name="uuid">The asset UUID</param> 332 /// <param name="uuid">The asset UUID</param>