aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLAssetData.cs
diff options
context:
space:
mode:
authorAlexRa2010-05-23 11:26:53 +0300
committerAlexRa2010-05-23 11:48:19 +0300
commit9976cb93ce351f45dea77e3389e0159b866757ae (patch)
tree7fd2d151b128cb036b683cba86262e47f1968fa6 /OpenSim/Data/MSSQL/MSSQLAssetData.cs
parentSplit migrations for RegionStore and EstateStore (see WARNING!) (diff)
downloadopensim-SC_OLD-9976cb93ce351f45dea77e3389e0159b866757ae.zip
opensim-SC_OLD-9976cb93ce351f45dea77e3389e0159b866757ae.tar.gz
opensim-SC_OLD-9976cb93ce351f45dea77e3389e0159b866757ae.tar.bz2
opensim-SC_OLD-9976cb93ce351f45dea77e3389e0159b866757ae.tar.xz
Further corrections to MS SQL stores (now passes all tests)
Besides, AssetData is slightly optimized to StoreAsset in one request ("IF EXISTS() UPDATE ... ELSE INSERT ...") The main change in the MS SQL Inventory implem. is that it now return empty list (or whatever) when called with UUID.Zero, which is consistent with how the code for other DBs work. I did no changes at all in XInventory, as there is no test set for them.
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLAssetData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLAssetData.cs87
1 files changed, 17 insertions, 70 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
index ec9d4f6..c7488d8 100644
--- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
@@ -145,26 +145,19 @@ namespace OpenSim.Data.MSSQL
145 /// <param name="asset">the asset</param> 145 /// <param name="asset">the asset</param>
146 override public void StoreAsset(AssetBase asset) 146 override public void StoreAsset(AssetBase asset)
147 { 147 {
148 if (ExistsAsset(asset.FullID)) 148
149 UpdateAsset(asset); 149 string sql =
150 else 150 @"IF EXISTS(SELECT * FROM assets WHERE id=@id)
151 InsertAsset(asset); 151 UPDATE assets set name = @name, description = @description, assetType = @assetType,
152 } 152 local = @local, temporary = @temporary, creatorid = @creatorid, data = @data
153 153 WHERE id=@id
154 154 ELSE
155 private void InsertAsset(AssetBase asset) 155 INSERT INTO assets
156 { 156 ([id], [name], [description], [assetType], [local],
157 if (ExistsAsset(asset.FullID)) 157 [temporary], [create_time], [access_time], [creatorid], [asset_flags], [data])
158 { 158 VALUES
159 return; 159 (@id, @name, @description, @assetType, @local,
160 } 160 @temporary, @create_time, @access_time, @creatorid, @asset_flags, @data)";
161
162 string sql = @"INSERT INTO assets
163 ([id], [name], [description], [assetType], [local],
164 [temporary], [create_time], [access_time], [creatorid], [asset_flags], [data])
165 VALUES
166 (@id, @name, @description, @assetType, @local,
167 @temporary, @create_time, @access_time, @creatorid, @asset_flags, @data)";
168 161
169 string assetName = asset.Name; 162 string assetName = asset.Name;
170 if (asset.Name.Length > 64) 163 if (asset.Name.Length > 64)
@@ -202,58 +195,11 @@ namespace OpenSim.Data.MSSQL
202 } 195 }
203 catch(Exception e) 196 catch(Exception e)
204 { 197 {
205 m_log.Error("[ASSET DB]: Error inserting item :" + e.Message); 198 m_log.Error("[ASSET DB]: Error storing item :" + e.Message);
206 } 199 }
207 } 200 }
208 } 201 }
209 202
210 /// <summary>
211 /// Update asset in m_database
212 /// </summary>
213 /// <param name="asset">the asset</param>
214 private void UpdateAsset(AssetBase asset)
215 {
216 string sql = @"UPDATE assets set name = @name, description = @description, assetType = @assetType,
217 local = @local, temporary = @temporary, data = @data
218 , creatorid = @creatorid
219 WHERE id = @keyId;";
220
221 string assetName = asset.Name;
222 if (asset.Name.Length > 64)
223 {
224 assetName = asset.Name.Substring(0, 64);
225 m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on update");
226 }
227
228 string assetDescription = asset.Description;
229 if (asset.Description.Length > 64)
230 {
231 assetDescription = asset.Description.Substring(0, 64);
232 m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on update");
233 }
234
235 using (SqlConnection conn = new SqlConnection(m_connectionString))
236 using (SqlCommand command = new SqlCommand(sql, conn))
237 {
238 command.Parameters.Add(m_database.CreateParameter("keyId", asset.FullID));
239 command.Parameters.Add(m_database.CreateParameter("name", assetName));
240 command.Parameters.Add(m_database.CreateParameter("description", assetDescription));
241 command.Parameters.Add(m_database.CreateParameter("assetType", asset.Type));
242 command.Parameters.Add(m_database.CreateParameter("local", asset.Local));
243 command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
244 command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
245 command.Parameters.Add(m_database.CreateParameter("creatorid", asset.Metadata.CreatorID));
246 conn.Open();
247 try
248 {
249 command.ExecuteNonQuery();
250 }
251 catch (Exception e)
252 {
253 m_log.Error(e.ToString());
254 }
255 }
256 }
257 203
258// Commented out since currently unused - this probably should be called in GetAsset() 204// Commented out since currently unused - this probably should be called in GetAsset()
259// private void UpdateAccessTime(AssetBase asset) 205// private void UpdateAccessTime(AssetBase asset)
@@ -302,7 +248,7 @@ namespace OpenSim.Data.MSSQL
302 string sql = @"WITH OrderedAssets AS 248 string sql = @"WITH OrderedAssets AS
303 ( 249 (
304 SELECT id, name, description, assetType, temporary, creatorid, 250 SELECT id, name, description, assetType, temporary, creatorid,
305 Row = ROW_NUMBER() OVER (ORDER BY id) 251 RowNumber = ROW_NUMBER() OVER (ORDER BY id)
306 FROM assets 252 FROM assets
307 ) 253 )
308 SELECT * 254 SELECT *
@@ -320,12 +266,13 @@ namespace OpenSim.Data.MSSQL
320 while (reader.Read()) 266 while (reader.Read())
321 { 267 {
322 AssetMetadata metadata = new AssetMetadata(); 268 AssetMetadata metadata = new AssetMetadata();
323 metadata.FullID = new UUID((Guid)reader["id"]); 269 metadata.FullID = DBGuid.FromDB(reader["id"]);
324 metadata.Name = (string)reader["name"]; 270 metadata.Name = (string)reader["name"];
325 metadata.Description = (string)reader["description"]; 271 metadata.Description = (string)reader["description"];
326 metadata.Type = Convert.ToSByte(reader["assetType"]); 272 metadata.Type = Convert.ToSByte(reader["assetType"]);
327 metadata.Temporary = Convert.ToBoolean(reader["temporary"]); 273 metadata.Temporary = Convert.ToBoolean(reader["temporary"]);
328 metadata.CreatorID = (string)reader["creatorid"]; 274 metadata.CreatorID = (string)reader["creatorid"];
275 retList.Add(metadata);
329 } 276 }
330 } 277 }
331 } 278 }