diff options
Diffstat (limited to 'OpenSim/Data/SQLite/SQLiteAssetData.cs')
-rw-r--r-- | OpenSim/Data/SQLite/SQLiteAssetData.cs | 80 |
1 files changed, 57 insertions, 23 deletions
diff --git a/OpenSim/Data/SQLite/SQLiteAssetData.cs b/OpenSim/Data/SQLite/SQLiteAssetData.cs index 373c903..723544a 100644 --- a/OpenSim/Data/SQLite/SQLiteAssetData.cs +++ b/OpenSim/Data/SQLite/SQLiteAssetData.cs | |||
@@ -30,7 +30,12 @@ using System.Data; | |||
30 | using System.Reflection; | 30 | using System.Reflection; |
31 | using System.Collections.Generic; | 31 | using System.Collections.Generic; |
32 | using log4net; | 32 | using log4net; |
33 | using Mono.Data.Sqlite; | 33 | #if CSharpSqlite |
34 | using Community.CsharpSqlite.Sqlite; | ||
35 | #else | ||
36 | using Mono.Data.Sqlite; | ||
37 | #endif | ||
38 | |||
34 | using OpenMetaverse; | 39 | using OpenMetaverse; |
35 | using OpenSim.Framework; | 40 | using OpenSim.Framework; |
36 | 41 | ||
@@ -44,14 +49,19 @@ namespace OpenSim.Data.SQLite | |||
44 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); | 49 | // private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
45 | 50 | ||
46 | private const string SelectAssetSQL = "select * from assets where UUID=:UUID"; | 51 | private const string SelectAssetSQL = "select * from assets where UUID=:UUID"; |
47 | private const string SelectAssetMetadataSQL = "select Name, Description, Type, Temporary, UUID from assets limit :start, :count"; | 52 | private const string SelectAssetMetadataSQL = "select Name, Description, Type, Temporary, asset_flags, UUID, CreatorID from assets limit :start, :count"; |
48 | private const string DeleteAssetSQL = "delete from assets where UUID=:UUID"; | 53 | private const string DeleteAssetSQL = "delete from assets where UUID=:UUID"; |
49 | private const string InsertAssetSQL = "insert into assets(UUID, Name, Description, Type, Local, Temporary, Data) values(:UUID, :Name, :Description, :Type, :Local, :Temporary, :Data)"; | 54 | private const string InsertAssetSQL = "insert into assets(UUID, Name, Description, Type, Local, Temporary, asset_flags, CreatorID, Data) values(:UUID, :Name, :Description, :Type, :Local, :Temporary, :Flags, :CreatorID, :Data)"; |
50 | private const string UpdateAssetSQL = "update assets set Name=:Name, Description=:Description, Type=:Type, Local=:Local, Temporary=:Temporary, Data=:Data where UUID=:UUID"; | 55 | private const string UpdateAssetSQL = "update assets set Name=:Name, Description=:Description, Type=:Type, Local=:Local, Temporary=:Temporary, asset_flags=:Flags, CreatorID=:CreatorID, Data=:Data where UUID=:UUID"; |
51 | private const string assetSelect = "select * from assets"; | 56 | private const string assetSelect = "select * from assets"; |
52 | 57 | ||
53 | private SqliteConnection m_conn; | 58 | private SqliteConnection m_conn; |
54 | 59 | ||
60 | protected virtual Assembly Assembly | ||
61 | { | ||
62 | get { return GetType().Assembly; } | ||
63 | } | ||
64 | |||
55 | override public void Dispose() | 65 | override public void Dispose() |
56 | { | 66 | { |
57 | if (m_conn != null) | 67 | if (m_conn != null) |
@@ -78,8 +88,7 @@ namespace OpenSim.Data.SQLite | |||
78 | m_conn = new SqliteConnection(dbconnect); | 88 | m_conn = new SqliteConnection(dbconnect); |
79 | m_conn.Open(); | 89 | m_conn.Open(); |
80 | 90 | ||
81 | Assembly assem = GetType().Assembly; | 91 | Migration m = new Migration(m_conn, Assembly, "AssetStore"); |
82 | Migration m = new Migration(m_conn, assem, "AssetStore"); | ||
83 | m.Update(); | 92 | m.Update(); |
84 | 93 | ||
85 | return; | 94 | return; |
@@ -119,7 +128,7 @@ namespace OpenSim.Data.SQLite | |||
119 | /// Create an asset | 128 | /// Create an asset |
120 | /// </summary> | 129 | /// </summary> |
121 | /// <param name="asset">Asset Base</param> | 130 | /// <param name="asset">Asset Base</param> |
122 | override public void StoreAsset(AssetBase asset) | 131 | override public bool StoreAsset(AssetBase asset) |
123 | { | 132 | { |
124 | //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); | 133 | //m_log.Info("[ASSET DB]: Creating Asset " + asset.FullID.ToString()); |
125 | if (ExistsAsset(asset.FullID)) | 134 | if (ExistsAsset(asset.FullID)) |
@@ -136,9 +145,12 @@ namespace OpenSim.Data.SQLite | |||
136 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); | 145 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); |
137 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); | 146 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); |
138 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); | 147 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); |
148 | cmd.Parameters.Add(new SqliteParameter(":Flags", asset.Flags)); | ||
149 | cmd.Parameters.Add(new SqliteParameter(":CreatorID", asset.Metadata.CreatorID)); | ||
139 | cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); | 150 | cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); |
140 | 151 | ||
141 | cmd.ExecuteNonQuery(); | 152 | cmd.ExecuteNonQuery(); |
153 | return true; | ||
142 | } | 154 | } |
143 | } | 155 | } |
144 | } | 156 | } |
@@ -154,9 +166,12 @@ namespace OpenSim.Data.SQLite | |||
154 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); | 166 | cmd.Parameters.Add(new SqliteParameter(":Type", asset.Type)); |
155 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); | 167 | cmd.Parameters.Add(new SqliteParameter(":Local", asset.Local)); |
156 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); | 168 | cmd.Parameters.Add(new SqliteParameter(":Temporary", asset.Temporary)); |
169 | cmd.Parameters.Add(new SqliteParameter(":Flags", asset.Flags)); | ||
170 | cmd.Parameters.Add(new SqliteParameter(":CreatorID", asset.Metadata.CreatorID)); | ||
157 | cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); | 171 | cmd.Parameters.Add(new SqliteParameter(":Data", asset.Data)); |
158 | 172 | ||
159 | cmd.ExecuteNonQuery(); | 173 | cmd.ExecuteNonQuery(); |
174 | return true; | ||
160 | } | 175 | } |
161 | } | 176 | } |
162 | } | 177 | } |
@@ -208,20 +223,6 @@ namespace OpenSim.Data.SQLite | |||
208 | } | 223 | } |
209 | 224 | ||
210 | /// <summary> | 225 | /// <summary> |
211 | /// Delete an asset from database | ||
212 | /// </summary> | ||
213 | /// <param name="uuid"></param> | ||
214 | public void DeleteAsset(UUID uuid) | ||
215 | { | ||
216 | using (SqliteCommand cmd = new SqliteCommand(DeleteAssetSQL, m_conn)) | ||
217 | { | ||
218 | cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString())); | ||
219 | |||
220 | cmd.ExecuteNonQuery(); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | /// <summary> | ||
225 | /// | 226 | /// |
226 | /// </summary> | 227 | /// </summary> |
227 | /// <param name="row"></param> | 228 | /// <param name="row"></param> |
@@ -234,13 +235,15 @@ namespace OpenSim.Data.SQLite | |||
234 | AssetBase asset = new AssetBase( | 235 | AssetBase asset = new AssetBase( |
235 | new UUID((String)row["UUID"]), | 236 | new UUID((String)row["UUID"]), |
236 | (String)row["Name"], | 237 | (String)row["Name"], |
237 | Convert.ToSByte(row["Type"]) | 238 | Convert.ToSByte(row["Type"]), |
239 | (String)row["CreatorID"] | ||
238 | ); | 240 | ); |
239 | 241 | ||
240 | asset.Description = (String) row["Description"]; | 242 | asset.Description = (String) row["Description"]; |
241 | asset.Local = Convert.ToBoolean(row["Local"]); | 243 | asset.Local = Convert.ToBoolean(row["Local"]); |
242 | asset.Temporary = Convert.ToBoolean(row["Temporary"]); | 244 | asset.Temporary = Convert.ToBoolean(row["Temporary"]); |
243 | asset.Data = (byte[]) row["Data"]; | 245 | asset.Flags = (AssetFlags)Convert.ToInt32(row["asset_flags"]); |
246 | asset.Data = (byte[])row["Data"]; | ||
244 | return asset; | 247 | return asset; |
245 | } | 248 | } |
246 | 249 | ||
@@ -253,6 +256,8 @@ namespace OpenSim.Data.SQLite | |||
253 | metadata.Description = (string) row["Description"]; | 256 | metadata.Description = (string) row["Description"]; |
254 | metadata.Type = Convert.ToSByte(row["Type"]); | 257 | metadata.Type = Convert.ToSByte(row["Type"]); |
255 | metadata.Temporary = Convert.ToBoolean(row["Temporary"]); // Not sure if this is correct. | 258 | metadata.Temporary = Convert.ToBoolean(row["Temporary"]); // Not sure if this is correct. |
259 | metadata.Flags = (AssetFlags)Convert.ToInt32(row["asset_flags"]); | ||
260 | metadata.CreatorID = row["CreatorID"].ToString(); | ||
256 | 261 | ||
257 | // Current SHA1s are not stored/computed. | 262 | // Current SHA1s are not stored/computed. |
258 | metadata.SHA1 = new byte[] {}; | 263 | metadata.SHA1 = new byte[] {}; |
@@ -337,6 +342,35 @@ namespace OpenSim.Data.SQLite | |||
337 | get { return "SQLite Asset storage engine"; } | 342 | get { return "SQLite Asset storage engine"; } |
338 | } | 343 | } |
339 | 344 | ||
345 | // TODO: (AlexRa): one of these is to be removed eventually (?) | ||
346 | |||
347 | /// <summary> | ||
348 | /// Delete an asset from database | ||
349 | /// </summary> | ||
350 | /// <param name="uuid"></param> | ||
351 | public bool DeleteAsset(UUID uuid) | ||
352 | { | ||
353 | lock (this) | ||
354 | { | ||
355 | using (SqliteCommand cmd = new SqliteCommand(DeleteAssetSQL, m_conn)) | ||
356 | { | ||
357 | cmd.Parameters.Add(new SqliteParameter(":UUID", uuid.ToString())); | ||
358 | cmd.ExecuteNonQuery(); | ||
359 | } | ||
360 | } | ||
361 | return true; | ||
362 | } | ||
363 | |||
364 | public override bool Delete(string id) | ||
365 | { | ||
366 | UUID assetID; | ||
367 | |||
368 | if (!UUID.TryParse(id, out assetID)) | ||
369 | return false; | ||
370 | |||
371 | return DeleteAsset(assetID); | ||
372 | } | ||
373 | |||
340 | #endregion | 374 | #endregion |
341 | } | 375 | } |
342 | } | 376 | } |