aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Data/MSSQL/MSSQLAssetData.cs
diff options
context:
space:
mode:
authorMelanie2010-05-26 10:38:46 +0100
committerMelanie2010-05-26 10:56:24 +0100
commit1c7f60ab493dffe44ab0517e4a6101fe5d909e28 (patch)
tree72b6a478d32d968ad7f5f3d6d11955bee9662926 /OpenSim/Data/MSSQL/MSSQLAssetData.cs
parentChange the way alpha is interpreted on prim text. Manris #4723 (diff)
parentMinor correction to AssetTests.cs (diff)
downloadopensim-SC-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.zip
opensim-SC-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.gz
opensim-SC-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.bz2
opensim-SC-1c7f60ab493dffe44ab0517e4a6101fe5d909e28.tar.xz
Merge branch 'unitests'
Signed-off-by: Melanie <melanie@t-data.com>
Diffstat (limited to 'OpenSim/Data/MSSQL/MSSQLAssetData.cs')
-rw-r--r--OpenSim/Data/MSSQL/MSSQLAssetData.cs106
1 files changed, 32 insertions, 74 deletions
diff --git a/OpenSim/Data/MSSQL/MSSQLAssetData.cs b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
index 8475b22..c7488d8 100644
--- a/OpenSim/Data/MSSQL/MSSQLAssetData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLAssetData.cs
@@ -121,15 +121,16 @@ namespace OpenSim.Data.MSSQL
121 if (reader.Read()) 121 if (reader.Read())
122 { 122 {
123 AssetBase asset = new AssetBase( 123 AssetBase asset = new AssetBase(
124 new UUID((Guid)reader["id"]), 124 DBGuid.FromDB(reader["id"]),
125 (string)reader["name"], 125 (string)reader["name"],
126 Convert.ToSByte(reader["assetType"]), 126 Convert.ToSByte(reader["assetType"]),
127 String.Empty 127 reader["creatorid"].ToString()
128 ); 128 );
129 // Region Main 129 // Region Main
130 asset.Description = (string)reader["description"]; 130 asset.Description = (string)reader["description"];
131 asset.Local = Convert.ToBoolean(reader["local"]); 131 asset.Local = Convert.ToBoolean(reader["local"]);
132 asset.Temporary = Convert.ToBoolean(reader["temporary"]); 132 asset.Temporary = Convert.ToBoolean(reader["temporary"]);
133 asset.Flags = (AssetFlags)(Convert.ToInt32(reader["asset_flags"]));
133 asset.Data = (byte[])reader["data"]; 134 asset.Data = (byte[])reader["data"];
134 return asset; 135 return asset;
135 } 136 }
@@ -144,26 +145,19 @@ namespace OpenSim.Data.MSSQL
144 /// <param name="asset">the asset</param> 145 /// <param name="asset">the asset</param>
145 override public void StoreAsset(AssetBase asset) 146 override public void StoreAsset(AssetBase asset)
146 { 147 {
147 if (ExistsAsset(asset.FullID)) 148
148 UpdateAsset(asset); 149 string sql =
149 else 150 @"IF EXISTS(SELECT * FROM assets WHERE id=@id)
150 InsertAsset(asset); 151 UPDATE assets set name = @name, description = @description, assetType = @assetType,
151 } 152 local = @local, temporary = @temporary, creatorid = @creatorid, data = @data
152 153 WHERE id=@id
153 154 ELSE
154 private void InsertAsset(AssetBase asset) 155 INSERT INTO assets
155 { 156 ([id], [name], [description], [assetType], [local],
156 if (ExistsAsset(asset.FullID)) 157 [temporary], [create_time], [access_time], [creatorid], [asset_flags], [data])
157 { 158 VALUES
158 return; 159 (@id, @name, @description, @assetType, @local,
159 } 160 @temporary, @create_time, @access_time, @creatorid, @asset_flags, @data)";
160
161 string sql = @"INSERT INTO assets
162 ([id], [name], [description], [assetType], [local],
163 [temporary], [create_time], [access_time], [data])
164 VALUES
165 (@id, @name, @description, @assetType, @local,
166 @temporary, @create_time, @access_time, @data)";
167 161
168 string assetName = asset.Name; 162 string assetName = asset.Name;
169 if (asset.Name.Length > 64) 163 if (asset.Name.Length > 64)
@@ -191,6 +185,8 @@ namespace OpenSim.Data.MSSQL
191 command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary)); 185 command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
192 command.Parameters.Add(m_database.CreateParameter("access_time", now)); 186 command.Parameters.Add(m_database.CreateParameter("access_time", now));
193 command.Parameters.Add(m_database.CreateParameter("create_time", now)); 187 command.Parameters.Add(m_database.CreateParameter("create_time", now));
188 command.Parameters.Add(m_database.CreateParameter("asset_flags", (int)asset.Flags));
189 command.Parameters.Add(m_database.CreateParameter("creatorid", asset.Metadata.CreatorID));
194 command.Parameters.Add(m_database.CreateParameter("data", asset.Data)); 190 command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
195 conn.Open(); 191 conn.Open();
196 try 192 try
@@ -199,57 +195,11 @@ namespace OpenSim.Data.MSSQL
199 } 195 }
200 catch(Exception e) 196 catch(Exception e)
201 { 197 {
202 m_log.Error("[ASSET DB]: Error inserting item :" + e.Message); 198 m_log.Error("[ASSET DB]: Error storing item :" + e.Message);
203 } 199 }
204 } 200 }
205 } 201 }
206 202
207 /// <summary>
208 /// Update asset in m_database
209 /// </summary>
210 /// <param name="asset">the asset</param>
211 private void UpdateAsset(AssetBase asset)
212 {
213 string sql = @"UPDATE assets set id = @id, name = @name, description = @description, assetType = @assetType,
214 local = @local, temporary = @temporary, data = @data
215 WHERE id = @keyId;";
216
217 string assetName = asset.Name;
218 if (asset.Name.Length > 64)
219 {
220 assetName = asset.Name.Substring(0, 64);
221 m_log.Warn("[ASSET DB]: Name field truncated from " + asset.Name.Length + " to " + assetName.Length + " characters on update");
222 }
223
224 string assetDescription = asset.Description;
225 if (asset.Description.Length > 64)
226 {
227 assetDescription = asset.Description.Substring(0, 64);
228 m_log.Warn("[ASSET DB]: Description field truncated from " + asset.Description.Length + " to " + assetDescription.Length + " characters on update");
229 }
230
231 using (SqlConnection conn = new SqlConnection(m_connectionString))
232 using (SqlCommand command = new SqlCommand(sql, conn))
233 {
234 command.Parameters.Add(m_database.CreateParameter("id", asset.FullID));
235 command.Parameters.Add(m_database.CreateParameter("name", assetName));
236 command.Parameters.Add(m_database.CreateParameter("description", assetDescription));
237 command.Parameters.Add(m_database.CreateParameter("assetType", asset.Type));
238 command.Parameters.Add(m_database.CreateParameter("local", asset.Local));
239 command.Parameters.Add(m_database.CreateParameter("temporary", asset.Temporary));
240 command.Parameters.Add(m_database.CreateParameter("data", asset.Data));
241 command.Parameters.Add(m_database.CreateParameter("@keyId", asset.FullID));
242 conn.Open();
243 try
244 {
245 command.ExecuteNonQuery();
246 }
247 catch (Exception e)
248 {
249 m_log.Error(e.ToString());
250 }
251 }
252 }
253 203
254// 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()
255// private void UpdateAccessTime(AssetBase asset) 205// private void UpdateAccessTime(AssetBase asset)
@@ -295,26 +245,34 @@ namespace OpenSim.Data.MSSQL
295 public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count) 245 public override List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
296 { 246 {
297 List<AssetMetadata> retList = new List<AssetMetadata>(count); 247 List<AssetMetadata> retList = new List<AssetMetadata>(count);
298 string sql = @"SELECT (name,description,assetType,temporary,id), Row = ROW_NUMBER() 248 string sql = @"WITH OrderedAssets AS
299 OVER (ORDER BY (some column to order by)) 249 (
300 WHERE Row >= @Start AND Row < @Start + @Count"; 250 SELECT id, name, description, assetType, temporary, creatorid,
251 RowNumber = ROW_NUMBER() OVER (ORDER BY id)
252 FROM assets
253 )
254 SELECT *
255 FROM OrderedAssets
256 WHERE RowNumber BETWEEN @start AND @stop;";
301 257
302 using (SqlConnection conn = new SqlConnection(m_connectionString)) 258 using (SqlConnection conn = new SqlConnection(m_connectionString))
303 using (SqlCommand cmd = new SqlCommand(sql, conn)) 259 using (SqlCommand cmd = new SqlCommand(sql, conn))
304 { 260 {
305 cmd.Parameters.Add(m_database.CreateParameter("start", start)); 261 cmd.Parameters.Add(m_database.CreateParameter("start", start));
306 cmd.Parameters.Add(m_database.CreateParameter("count", count)); 262 cmd.Parameters.Add(m_database.CreateParameter("stop", start + count - 1));
307 conn.Open(); 263 conn.Open();
308 using (SqlDataReader reader = cmd.ExecuteReader()) 264 using (SqlDataReader reader = cmd.ExecuteReader())
309 { 265 {
310 while (reader.Read()) 266 while (reader.Read())
311 { 267 {
312 AssetMetadata metadata = new AssetMetadata(); 268 AssetMetadata metadata = new AssetMetadata();
313 metadata.FullID = new UUID((Guid)reader["id"]); 269 metadata.FullID = DBGuid.FromDB(reader["id"]);
314 metadata.Name = (string)reader["name"]; 270 metadata.Name = (string)reader["name"];
315 metadata.Description = (string)reader["description"]; 271 metadata.Description = (string)reader["description"];
316 metadata.Type = Convert.ToSByte(reader["assetType"]); 272 metadata.Type = Convert.ToSByte(reader["assetType"]);
317 metadata.Temporary = Convert.ToBoolean(reader["temporary"]); 273 metadata.Temporary = Convert.ToBoolean(reader["temporary"]);
274 metadata.CreatorID = (string)reader["creatorid"];
275 retList.Add(metadata);
318 } 276 }
319 } 277 }
320 } 278 }