diff options
Diffstat (limited to 'OpenSim/Data/MySQL/MySQLAssetData.cs')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLAssetData.cs | 97 |
1 files changed, 45 insertions, 52 deletions
diff --git a/OpenSim/Data/MySQL/MySQLAssetData.cs b/OpenSim/Data/MySQL/MySQLAssetData.cs index 5d8da17..1488e1a 100644 --- a/OpenSim/Data/MySQL/MySQLAssetData.cs +++ b/OpenSim/Data/MySQL/MySQLAssetData.cs | |||
@@ -154,63 +154,59 @@ namespace OpenSim.Data.MySQL | |||
154 | /// </summary> | 154 | /// </summary> |
155 | /// <param name="asset">Asset UUID to create</param> | 155 | /// <param name="asset">Asset UUID to create</param> |
156 | /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> | 156 | /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks> |
157 | override public void StoreAsset(AssetBase asset) | 157 | override public bool StoreAsset(AssetBase asset) |
158 | { | 158 | { |
159 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 159 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
160 | { | 160 | { |
161 | dbcon.Open(); | 161 | dbcon.Open(); |
162 | 162 | ||
163 | string assetName = asset.Name; | ||
164 | if (asset.Name.Length > AssetBase.MAX_ASSET_NAME) | ||
165 | { | ||
166 | assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); | ||
167 | m_log.WarnFormat( | ||
168 | "[ASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
169 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); | ||
170 | } | ||
171 | |||
172 | string assetDescription = asset.Description; | ||
173 | if (asset.Description.Length > AssetBase.MAX_ASSET_DESC) | ||
174 | { | ||
175 | assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC); | ||
176 | m_log.WarnFormat( | ||
177 | "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
178 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); | ||
179 | } | ||
180 | |||
163 | using (MySqlCommand cmd = | 181 | using (MySqlCommand cmd = |
164 | new MySqlCommand( | 182 | new MySqlCommand( |
165 | "replace INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, asset_flags, CreatorID, data)" + | 183 | "replace INTO assets(id, name, description, assetType, local, temporary, create_time, access_time, asset_flags, CreatorID, data)" + |
166 | "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?CreatorID, ?data)", | 184 | "VALUES(?id, ?name, ?description, ?assetType, ?local, ?temporary, ?create_time, ?access_time, ?asset_flags, ?CreatorID, ?data)", |
167 | dbcon)) | 185 | dbcon)) |
168 | { | 186 | { |
169 | string assetName = asset.Name; | ||
170 | if (asset.Name.Length > AssetBase.MAX_ASSET_NAME) | ||
171 | { | ||
172 | assetName = asset.Name.Substring(0, AssetBase.MAX_ASSET_NAME); | ||
173 | m_log.WarnFormat( | ||
174 | "[ASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
175 | asset.Name, asset.ID, asset.Name.Length, assetName.Length); | ||
176 | } | ||
177 | |||
178 | string assetDescription = asset.Description; | ||
179 | if (asset.Description.Length > AssetBase.MAX_ASSET_DESC) | ||
180 | { | ||
181 | assetDescription = asset.Description.Substring(0, AssetBase.MAX_ASSET_DESC); | ||
182 | m_log.WarnFormat( | ||
183 | "[ASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add", | ||
184 | asset.Description, asset.ID, asset.Description.Length, assetDescription.Length); | ||
185 | } | ||
186 | |||
187 | try | 187 | try |
188 | { | 188 | { |
189 | using (cmd) | 189 | // create unix epoch time |
190 | { | 190 | int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); |
191 | // create unix epoch time | 191 | cmd.Parameters.AddWithValue("?id", asset.ID); |
192 | int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); | 192 | cmd.Parameters.AddWithValue("?name", assetName); |
193 | cmd.Parameters.AddWithValue("?id", asset.ID); | 193 | cmd.Parameters.AddWithValue("?description", assetDescription); |
194 | cmd.Parameters.AddWithValue("?name", assetName); | 194 | cmd.Parameters.AddWithValue("?assetType", asset.Type); |
195 | cmd.Parameters.AddWithValue("?description", assetDescription); | 195 | cmd.Parameters.AddWithValue("?local", asset.Local); |
196 | cmd.Parameters.AddWithValue("?assetType", asset.Type); | 196 | cmd.Parameters.AddWithValue("?temporary", asset.Temporary); |
197 | cmd.Parameters.AddWithValue("?local", asset.Local); | 197 | cmd.Parameters.AddWithValue("?create_time", now); |
198 | cmd.Parameters.AddWithValue("?temporary", asset.Temporary); | 198 | cmd.Parameters.AddWithValue("?access_time", now); |
199 | cmd.Parameters.AddWithValue("?create_time", now); | 199 | cmd.Parameters.AddWithValue("?CreatorID", asset.Metadata.CreatorID); |
200 | cmd.Parameters.AddWithValue("?access_time", now); | 200 | cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); |
201 | cmd.Parameters.AddWithValue("?CreatorID", asset.Metadata.CreatorID); | 201 | cmd.Parameters.AddWithValue("?data", asset.Data); |
202 | cmd.Parameters.AddWithValue("?asset_flags", (int)asset.Flags); | 202 | cmd.ExecuteNonQuery(); |
203 | cmd.Parameters.AddWithValue("?data", asset.Data); | 203 | return true; |
204 | cmd.ExecuteNonQuery(); | ||
205 | } | ||
206 | } | 204 | } |
207 | catch (Exception e) | 205 | catch (Exception e) |
208 | { | 206 | { |
209 | m_log.Error( | 207 | m_log.ErrorFormat("[ASSET DB]: MySQL failure creating asset {0} with name \"{1}\". Error: {2}", |
210 | string.Format( | 208 | asset.FullID, asset.Name, e.Message); |
211 | "[ASSET DB]: MySQL failure creating asset {0} with name {1}. Exception ", | 209 | return false; |
212 | asset.FullID, asset.Name) | ||
213 | , e); | ||
214 | } | 210 | } |
215 | } | 211 | } |
216 | } | 212 | } |
@@ -227,21 +223,18 @@ namespace OpenSim.Data.MySQL | |||
227 | { | 223 | { |
228 | try | 224 | try |
229 | { | 225 | { |
230 | using (cmd) | 226 | // create unix epoch time |
231 | { | 227 | int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); |
232 | // create unix epoch time | 228 | cmd.Parameters.AddWithValue("?id", asset.ID); |
233 | int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow); | 229 | cmd.Parameters.AddWithValue("?access_time", now); |
234 | cmd.Parameters.AddWithValue("?id", asset.ID); | 230 | cmd.ExecuteNonQuery(); |
235 | cmd.Parameters.AddWithValue("?access_time", now); | ||
236 | cmd.ExecuteNonQuery(); | ||
237 | } | ||
238 | } | 231 | } |
239 | catch (Exception e) | 232 | catch (Exception e) |
240 | { | 233 | { |
241 | m_log.Error( | 234 | m_log.Error( |
242 | string.Format( | 235 | string.Format( |
243 | "[ASSETS DB]: Failure updating access_time for asset {0} with name {1}. Exception ", | 236 | "[ASSETS DB]: Failure updating access_time for asset {0} with name {1}. Exception ", |
244 | asset.FullID, asset.Name), | 237 | asset.FullID, asset.Name), |
245 | e); | 238 | e); |
246 | } | 239 | } |
247 | } | 240 | } |
@@ -364,4 +357,4 @@ namespace OpenSim.Data.MySQL | |||
364 | 357 | ||
365 | #endregion | 358 | #endregion |
366 | } | 359 | } |
367 | } \ No newline at end of file | 360 | } |