aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/MySQL/MySQLXAssetData.cs126
1 files changed, 69 insertions, 57 deletions
diff --git a/OpenSim/Data/MySQL/MySQLXAssetData.cs b/OpenSim/Data/MySQL/MySQLXAssetData.cs
index 0dadf5e..778c7f4 100644
--- a/OpenSim/Data/MySQL/MySQLXAssetData.cs
+++ b/OpenSim/Data/MySQL/MySQLXAssetData.cs
@@ -166,71 +166,83 @@ namespace OpenSim.Data.MySQL
166 { 166 {
167 dbcon.Open(); 167 dbcon.Open();
168 168
169 string assetName = asset.Name; 169 using (MySqlTransaction transaction = dbcon.BeginTransaction())
170 if (asset.Name.Length > 64)
171 { 170 {
172 assetName = asset.Name.Substring(0, 64); 171
173 m_log.Warn("[XASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on add"); 172 string assetName = asset.Name;
174 } 173 if (asset.Name.Length > 64)
174 {
175 assetName = asset.Name.Substring(0, 64);
176 m_log.Warn("[XASSET 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("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
184 }
185
186 string hash = Util.SHA1Hash(asset.Data);
187
188 try
189 {
190 using (MySqlCommand cmd =
191 new MySqlCommand(
192 "replace INTO xassetsmeta(id, hash, name, description, asset_type, local, temporary, create_time, access_time, asset_flags, creator_id)" +
193 "VALUES(?id, ?hash, ?name, ?description, ?asset_type, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?creator_id)",
194 dbcon))
195 {
196 // create unix epoch time
197 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
198 cmd.Parameters.AddWithValue("?id", asset.ID);
199 cmd.Parameters.AddWithValue("?hash", hash);
200 cmd.Parameters.AddWithValue("?name", assetName);
201 cmd.Parameters.AddWithValue("?description", assetDescription);
202 cmd.Parameters.AddWithValue("?asset_type", asset.Type);
203 cmd.Parameters.AddWithValue("?local", asset.Local);
204 cmd.Parameters.AddWithValue("?temporary", asset.Temporary);
205 cmd.Parameters.AddWithValue("?create_time", now);
206 cmd.Parameters.AddWithValue("?access_time", now);
207 cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID);
208 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
209 cmd.Parameters.AddWithValue("?data", asset.Data);
210 cmd.ExecuteNonQuery();
211 }
212 }
213 catch (Exception e)
214 {
215 m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset metadata {0} with name \"{1}\". Error: {2}",
216 asset.FullID, asset.Name, e.Message);
175 217
176 string assetDescription = asset.Description; 218 transaction.Rollback();
177 if (asset.Description.Length > 64)
178 {
179 assetDescription = asset.Description.Substring(0, 64);
180 m_log.Warn("[XASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on add");
181 }
182 219
183 string hash = Util.SHA1Hash(asset.Data); 220 return;
221 }
184 222
185 try 223 try
186 {
187 using (MySqlCommand cmd =
188 new MySqlCommand(
189 "replace INTO xassetsmeta(id, hash, name, description, asset_type, local, temporary, create_time, access_time, asset_flags, creator_id)" +
190 "VALUES(?id, ?hash, ?name, ?description, ?asset_type, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?creator_id)",
191 dbcon))
192 { 224 {
193 // create unix epoch time 225 using (MySqlCommand cmd =
194 int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); 226 new MySqlCommand(
195 cmd.Parameters.AddWithValue("?id", asset.ID); 227 "replace INTO xassetsdata(hash, data) VALUES(?hash, ?data)",
196 cmd.Parameters.AddWithValue("?hash", hash); 228 dbcon))
197 cmd.Parameters.AddWithValue("?name", assetName); 229 {
198 cmd.Parameters.AddWithValue("?description", assetDescription); 230 cmd.Parameters.AddWithValue("?hash", hash);
199 cmd.Parameters.AddWithValue("?asset_type", asset.Type); 231 cmd.Parameters.AddWithValue("?data", asset.Data);
200 cmd.Parameters.AddWithValue("?local", asset.Local); 232 cmd.ExecuteNonQuery();
201 cmd.Parameters.AddWithValue("?temporary", asset.Temporary); 233 }
202 cmd.Parameters.AddWithValue("?create_time", now);
203 cmd.Parameters.AddWithValue("?access_time", now);
204 cmd.Parameters.AddWithValue("?creator_id", asset.Metadata.CreatorID);
205 cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags);
206 cmd.Parameters.AddWithValue("?data", asset.Data);
207 cmd.ExecuteNonQuery();
208 cmd.Dispose();
209 } 234 }
210 } 235 catch (Exception e)
211 catch (Exception e)
212 {
213 m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset metadata {0} with name \"{1}\". Error: {2}",
214 asset.FullID, asset.Name, e.Message);
215 }
216
217 try
218 {
219 using (MySqlCommand cmd =
220 new MySqlCommand(
221 "replace INTO xassetsdata(hash, data) VALUES(?hash, ?data)",
222 dbcon))
223 { 236 {
224 cmd.Parameters.AddWithValue("?hash", hash); 237 m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}",
225 cmd.Parameters.AddWithValue("?data", asset.Data); 238 asset.FullID, asset.Name, e.Message);
226 cmd.ExecuteNonQuery(); 239
227 cmd.Dispose(); 240 transaction.Rollback();
241
242 return;
228 } 243 }
229 } 244
230 catch (Exception e) 245 transaction.Commit();
231 {
232 m_log.ErrorFormat("[XASSET DB]: MySQL failure creating asset data {0} with name \"{1}\". Error: {2}",
233 asset.FullID, asset.Name, e.Message);
234 } 246 }
235 } 247 }
236 } 248 }