PGSQLXAssetData.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Collections.Generic;
  29. using System.Data;
  30. using System.IO;
  31. using System.IO.Compression;
  32. using System.Reflection;
  33. using System.Security.Cryptography;
  34. using System.Text;
  35. using log4net;
  36. using OpenMetaverse;
  37. using OpenSim.Framework;
  38. using OpenSim.Data;
  39. using Npgsql;
  40. namespace OpenSim.Data.PGSQL
  41. {
  42. public class PGSQLXAssetData : IXAssetDataPlugin
  43. {
  44. private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
  45. protected virtual Assembly Assembly
  46. {
  47. get { return GetType().Assembly; }
  48. }
  49. /// <summary>
  50. /// Number of days that must pass before we update the access time on an asset when it has been fetched.
  51. /// </summary>
  52. private const int DaysBetweenAccessTimeUpdates = 30;
  53. private bool m_enableCompression = false;
  54. private PGSQLManager m_database;
  55. private string m_connectionString;
  56. private object m_dbLock = new object();
  57. /// <summary>
  58. /// We can reuse this for all hashing since all methods are single-threaded through m_dbBLock
  59. /// </summary>
  60. private HashAlgorithm hasher = new SHA256CryptoServiceProvider();
  61. #region IPlugin Members
  62. public string Version { get { return "1.0.0.0"; } }
  63. /// <summary>
  64. /// <para>Initialises Asset interface</para>
  65. /// <para>
  66. /// <list type="bullet">
  67. /// <item>Loads and initialises the PGSQL storage plugin.</item>
  68. /// <item>Warns and uses the obsolete pgsql_connection.ini if connect string is empty.</item>
  69. /// <item>Check for migration</item>
  70. /// </list>
  71. /// </para>
  72. /// </summary>
  73. /// <param name="connect">connect string</param>
  74. public void Initialise(string connect)
  75. {
  76. m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************");
  77. m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************");
  78. m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************");
  79. m_log.ErrorFormat("[PGSQL XASSETDATA]: THIS PLUGIN IS STRICTLY EXPERIMENTAL.");
  80. m_log.ErrorFormat("[PGSQL XASSETDATA]: DO NOT USE FOR ANY DATA THAT YOU DO NOT MIND LOSING.");
  81. m_log.ErrorFormat("[PGSQL XASSETDATA]: DATABASE TABLES CAN CHANGE AT ANY TIME, CAUSING EXISTING DATA TO BE LOST.");
  82. m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************");
  83. m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************");
  84. m_log.ErrorFormat("[PGSQL XASSETDATA]: ***********************************************************");
  85. m_connectionString = connect;
  86. m_database = new PGSQLManager(m_connectionString);
  87. using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
  88. {
  89. dbcon.Open();
  90. Migration m = new Migration(dbcon, Assembly, "XAssetStore");
  91. m.Update();
  92. }
  93. }
  94. public void Initialise()
  95. {
  96. throw new NotImplementedException();
  97. }
  98. public void Dispose() { }
  99. /// <summary>
  100. /// The name of this DB provider
  101. /// </summary>
  102. public string Name
  103. {
  104. get { return "PGSQL XAsset storage engine"; }
  105. }
  106. #endregion
  107. #region IAssetDataPlugin Members
  108. /// <summary>
  109. /// Fetch Asset <paramref name="assetID"/> from database
  110. /// </summary>
  111. /// <param name="assetID">Asset UUID to fetch</param>
  112. /// <returns>Return the asset</returns>
  113. /// <remarks>On failure : throw an exception and attempt to reconnect to database</remarks>
  114. public AssetBase GetAsset(UUID assetID)
  115. {
  116. // m_log.DebugFormat("[PGSQL XASSET DATA]: Looking for asset {0}", assetID);
  117. AssetBase asset = null;
  118. lock (m_dbLock)
  119. {
  120. using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
  121. {
  122. dbcon.Open();
  123. using (NpgsqlCommand cmd = new NpgsqlCommand(
  124. @"SELECT name, description, access_time, ""AssetType"", local, temporary, asset_flags, creatorid, data
  125. FROM XAssetsMeta
  126. JOIN XAssetsData ON XAssetsMeta.hash = XAssetsData.Hash WHERE id=:ID",
  127. dbcon))
  128. {
  129. cmd.Parameters.Add(m_database.CreateParameter("ID", assetID));
  130. try
  131. {
  132. using (NpgsqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  133. {
  134. if (dbReader.Read())
  135. {
  136. asset = new AssetBase(
  137. assetID,
  138. (string)dbReader["name"],
  139. Convert.ToSByte(dbReader["AssetType"]),
  140. dbReader["creatorid"].ToString());
  141. asset.Data = (byte[])dbReader["data"];
  142. asset.Description = (string)dbReader["description"];
  143. string local = dbReader["local"].ToString();
  144. if (local.Equals("1") || local.Equals("true", StringComparison.InvariantCultureIgnoreCase))
  145. asset.Local = true;
  146. else
  147. asset.Local = false;
  148. asset.Temporary = Convert.ToBoolean(dbReader["temporary"]);
  149. asset.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
  150. if (m_enableCompression)
  151. {
  152. using (GZipStream decompressionStream = new GZipStream(new MemoryStream(asset.Data), CompressionMode.Decompress))
  153. {
  154. MemoryStream outputStream = new MemoryStream();
  155. WebUtil.CopyStream(decompressionStream, outputStream, int.MaxValue);
  156. // int compressedLength = asset.Data.Length;
  157. asset.Data = outputStream.ToArray();
  158. // m_log.DebugFormat(
  159. // "[XASSET DB]: Decompressed {0} {1} to {2} bytes from {3}",
  160. // asset.ID, asset.Name, asset.Data.Length, compressedLength);
  161. }
  162. }
  163. UpdateAccessTime(asset.Metadata, (int)dbReader["access_time"]);
  164. }
  165. }
  166. }
  167. catch (Exception e)
  168. {
  169. m_log.Error(string.Format("[PGSQL XASSET DATA]: Failure fetching asset {0}", assetID), e);
  170. }
  171. }
  172. }
  173. }
  174. return asset;
  175. }
  176. /// <summary>
  177. /// Create an asset in database, or update it if existing.
  178. /// </summary>
  179. /// <param name="asset">Asset UUID to create</param>
  180. /// <remarks>On failure : Throw an exception and attempt to reconnect to database</remarks>
  181. public void StoreAsset(AssetBase asset)
  182. {
  183. // m_log.DebugFormat("[XASSETS DB]: Storing asset {0} {1}", asset.Name, asset.ID);
  184. lock (m_dbLock)
  185. {
  186. using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
  187. {
  188. dbcon.Open();
  189. using (NpgsqlTransaction transaction = dbcon.BeginTransaction())
  190. {
  191. string assetName = asset.Name;
  192. if (asset.Name.Length > 64)
  193. {
  194. assetName = asset.Name.Substring(0, 64);
  195. m_log.WarnFormat(
  196. "[XASSET DB]: Name '{0}' for asset {1} truncated from {2} to {3} characters on add",
  197. asset.Name, asset.ID, asset.Name.Length, assetName.Length);
  198. }
  199. string assetDescription = asset.Description;
  200. if (asset.Description.Length > 64)
  201. {
  202. assetDescription = asset.Description.Substring(0, 64);
  203. m_log.WarnFormat(
  204. "[XASSET DB]: Description '{0}' for asset {1} truncated from {2} to {3} characters on add",
  205. asset.Description, asset.ID, asset.Description.Length, assetDescription.Length);
  206. }
  207. if (m_enableCompression)
  208. {
  209. MemoryStream outputStream = new MemoryStream();
  210. using (GZipStream compressionStream = new GZipStream(outputStream, CompressionMode.Compress, false))
  211. {
  212. // Console.WriteLine(WebUtil.CopyTo(new MemoryStream(asset.Data), compressionStream, int.MaxValue));
  213. // We have to close the compression stream in order to make sure it writes everything out to the underlying memory output stream.
  214. compressionStream.Close();
  215. byte[] compressedData = outputStream.ToArray();
  216. asset.Data = compressedData;
  217. }
  218. }
  219. byte[] hash = hasher.ComputeHash(asset.Data);
  220. UUID asset_id;
  221. UUID.TryParse(asset.ID, out asset_id);
  222. // m_log.DebugFormat(
  223. // "[XASSET DB]: Compressed data size for {0} {1}, hash {2} is {3}",
  224. // asset.ID, asset.Name, hash, compressedData.Length);
  225. try
  226. {
  227. using (NpgsqlCommand cmd =
  228. new NpgsqlCommand(
  229. @"insert INTO XAssetsMeta(id, hash, name, description, ""AssetType"", local, temporary, create_time, access_time, asset_flags, creatorid)
  230. Select :ID, :Hash, :Name, :Description, :AssetType, :Local, :Temporary, :CreateTime, :AccessTime, :AssetFlags, :CreatorID
  231. where not exists( Select id from XAssetsMeta where id = :ID);
  232. update XAssetsMeta
  233. set id = :ID, hash = :Hash, name = :Name, description = :Description,
  234. ""AssetType"" = :AssetType, local = :Local, temporary = :Temporary, create_time = :CreateTime,
  235. access_time = :AccessTime, asset_flags = :AssetFlags, creatorid = :CreatorID
  236. where id = :ID;
  237. ",
  238. dbcon))
  239. {
  240. // create unix epoch time
  241. int now = (int)Utils.DateTimeToUnixTime(DateTime.UtcNow);
  242. cmd.Parameters.Add(m_database.CreateParameter("ID", asset_id));
  243. cmd.Parameters.Add(m_database.CreateParameter("Hash", hash));
  244. cmd.Parameters.Add(m_database.CreateParameter("Name", assetName));
  245. cmd.Parameters.Add(m_database.CreateParameter("Description", assetDescription));
  246. cmd.Parameters.Add(m_database.CreateParameter("AssetType", asset.Type));
  247. cmd.Parameters.Add(m_database.CreateParameter("Local", asset.Local));
  248. cmd.Parameters.Add(m_database.CreateParameter("Temporary", asset.Temporary));
  249. cmd.Parameters.Add(m_database.CreateParameter("CreateTime", now));
  250. cmd.Parameters.Add(m_database.CreateParameter("AccessTime", now));
  251. cmd.Parameters.Add(m_database.CreateParameter("CreatorID", asset.Metadata.CreatorID));
  252. cmd.Parameters.Add(m_database.CreateParameter("AssetFlags", (int)asset.Flags));
  253. cmd.ExecuteNonQuery();
  254. }
  255. }
  256. catch (Exception e)
  257. {
  258. m_log.ErrorFormat("[ASSET DB]: PGSQL failure creating asset metadata {0} with name \"{1}\". Error: {2}",
  259. asset.FullID, asset.Name, e.Message);
  260. transaction.Rollback();
  261. return;
  262. }
  263. if (!ExistsData(dbcon, transaction, hash))
  264. {
  265. try
  266. {
  267. using (NpgsqlCommand cmd =
  268. new NpgsqlCommand(
  269. @"INSERT INTO XAssetsData(hash, data) VALUES(:Hash, :Data)",
  270. dbcon))
  271. {
  272. cmd.Parameters.Add(m_database.CreateParameter("Hash", hash));
  273. cmd.Parameters.Add(m_database.CreateParameter("Data", asset.Data));
  274. cmd.ExecuteNonQuery();
  275. }
  276. }
  277. catch (Exception e)
  278. {
  279. m_log.ErrorFormat("[XASSET DB]: PGSQL failure creating asset data {0} with name \"{1}\". Error: {2}",
  280. asset.FullID, asset.Name, e.Message);
  281. transaction.Rollback();
  282. return;
  283. }
  284. }
  285. transaction.Commit();
  286. }
  287. }
  288. }
  289. }
  290. /// <summary>
  291. /// Updates the access time of the asset if it was accessed above a given threshhold amount of time.
  292. /// </summary>
  293. /// <remarks>
  294. /// This gives us some insight into assets which haven't ben accessed for a long period. This is only done
  295. /// over the threshold time to avoid excessive database writes as assets are fetched.
  296. /// </remarks>
  297. /// <param name='asset'></param>
  298. /// <param name='accessTime'></param>
  299. private void UpdateAccessTime(AssetMetadata assetMetadata, int accessTime)
  300. {
  301. DateTime now = DateTime.UtcNow;
  302. if ((now - Utils.UnixTimeToDateTime(accessTime)).TotalDays < DaysBetweenAccessTimeUpdates)
  303. return;
  304. lock (m_dbLock)
  305. {
  306. using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
  307. {
  308. dbcon.Open();
  309. NpgsqlCommand cmd =
  310. new NpgsqlCommand(@"update XAssetsMeta set access_time=:AccessTime where id=:ID", dbcon);
  311. try
  312. {
  313. UUID asset_id;
  314. UUID.TryParse(assetMetadata.ID, out asset_id);
  315. using (cmd)
  316. {
  317. // create unix epoch time
  318. cmd.Parameters.Add(m_database.CreateParameter("id", asset_id));
  319. cmd.Parameters.Add(m_database.CreateParameter("access_time", (int)Utils.DateTimeToUnixTime(now)));
  320. cmd.ExecuteNonQuery();
  321. }
  322. }
  323. catch (Exception e)
  324. {
  325. m_log.ErrorFormat(
  326. "[XASSET PGSQL DB]: Failure updating access_time for asset {0} with name {1} : {2}",
  327. assetMetadata.ID, assetMetadata.Name, e.Message);
  328. }
  329. }
  330. }
  331. }
  332. /// <summary>
  333. /// We assume we already have the m_dbLock.
  334. /// </summary>
  335. /// TODO: need to actually use the transaction.
  336. /// <param name="dbcon"></param>
  337. /// <param name="transaction"></param>
  338. /// <param name="hash"></param>
  339. /// <returns></returns>
  340. private bool ExistsData(NpgsqlConnection dbcon, NpgsqlTransaction transaction, byte[] hash)
  341. {
  342. // m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid);
  343. bool exists = false;
  344. using (NpgsqlCommand cmd = new NpgsqlCommand(@"SELECT hash FROM XAssetsData WHERE hash=:Hash", dbcon))
  345. {
  346. cmd.Parameters.Add(m_database.CreateParameter("Hash", hash));
  347. try
  348. {
  349. using (NpgsqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  350. {
  351. if (dbReader.Read())
  352. {
  353. // m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid);
  354. exists = true;
  355. }
  356. }
  357. }
  358. catch (Exception e)
  359. {
  360. m_log.ErrorFormat(
  361. "[XASSETS DB]: PGSql failure in ExistsData fetching hash {0}. Exception {1}{2}",
  362. hash, e.Message, e.StackTrace);
  363. }
  364. }
  365. return exists;
  366. }
  367. /// <summary>
  368. /// Check if the assets exist in the database.
  369. /// </summary>
  370. /// <param name="uuids">The assets' IDs</param>
  371. /// <returns>For each asset: true if it exists, false otherwise</returns>
  372. public bool[] AssetsExist(UUID[] uuids)
  373. {
  374. if (uuids.Length == 0)
  375. return new bool[0];
  376. HashSet<UUID> exist = new HashSet<UUID>();
  377. string ids = "'" + string.Join("','", uuids) + "'";
  378. string sql = string.Format(@"SELECT id FROM XAssetsMeta WHERE id IN ({0})", ids);
  379. using (NpgsqlConnection conn = new NpgsqlConnection(m_connectionString))
  380. {
  381. conn.Open();
  382. using (NpgsqlCommand cmd = new NpgsqlCommand(sql, conn))
  383. {
  384. using (NpgsqlDataReader reader = cmd.ExecuteReader())
  385. {
  386. while (reader.Read())
  387. {
  388. UUID id = DBGuid.FromDB(reader["id"]);
  389. exist.Add(id);
  390. }
  391. }
  392. }
  393. }
  394. bool[] results = new bool[uuids.Length];
  395. for (int i = 0; i < uuids.Length; i++)
  396. results[i] = exist.Contains(uuids[i]);
  397. return results;
  398. }
  399. /// <summary>
  400. /// Check if the asset exists in the database
  401. /// </summary>
  402. /// <param name="uuid">The asset UUID</param>
  403. /// <returns>true if it exists, false otherwise.</returns>
  404. public bool ExistsAsset(UUID uuid)
  405. {
  406. // m_log.DebugFormat("[ASSETS DB]: Checking for asset {0}", uuid);
  407. bool assetExists = false;
  408. lock (m_dbLock)
  409. {
  410. using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
  411. {
  412. dbcon.Open();
  413. using (NpgsqlCommand cmd = new NpgsqlCommand(@"SELECT id FROM XAssetsMeta WHERE id=:ID", dbcon))
  414. {
  415. cmd.Parameters.Add(m_database.CreateParameter("id", uuid));
  416. try
  417. {
  418. using (NpgsqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow))
  419. {
  420. if (dbReader.Read())
  421. {
  422. // m_log.DebugFormat("[ASSETS DB]: Found asset {0}", uuid);
  423. assetExists = true;
  424. }
  425. }
  426. }
  427. catch (Exception e)
  428. {
  429. m_log.Error(string.Format("[XASSETS DB]: PGSql failure fetching asset {0}", uuid), e);
  430. }
  431. }
  432. }
  433. }
  434. return assetExists;
  435. }
  436. /// <summary>
  437. /// Returns a list of AssetMetadata objects. The list is a subset of
  438. /// the entire data set offset by <paramref name="start" /> containing
  439. /// <paramref name="count" /> elements.
  440. /// </summary>
  441. /// <param name="start">The number of results to discard from the total data set.</param>
  442. /// <param name="count">The number of rows the returned list should contain.</param>
  443. /// <returns>A list of AssetMetadata objects.</returns>
  444. public List<AssetMetadata> FetchAssetMetadataSet(int start, int count)
  445. {
  446. List<AssetMetadata> retList = new List<AssetMetadata>(count);
  447. lock (m_dbLock)
  448. {
  449. using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
  450. {
  451. dbcon.Open();
  452. NpgsqlCommand cmd = new NpgsqlCommand( @"SELECT name, description, access_time, ""AssetType"", temporary, id, asset_flags, creatorid
  453. FROM XAssetsMeta
  454. LIMIT :start, :count", dbcon);
  455. cmd.Parameters.Add(m_database.CreateParameter("start", start));
  456. cmd.Parameters.Add(m_database.CreateParameter("count", count));
  457. try
  458. {
  459. using (NpgsqlDataReader dbReader = cmd.ExecuteReader())
  460. {
  461. while (dbReader.Read())
  462. {
  463. AssetMetadata metadata = new AssetMetadata();
  464. metadata.Name = (string)dbReader["name"];
  465. metadata.Description = (string)dbReader["description"];
  466. metadata.Type = Convert.ToSByte(dbReader["AssetType"]);
  467. metadata.Temporary = Convert.ToBoolean(dbReader["temporary"]);
  468. metadata.Flags = (AssetFlags)Convert.ToInt32(dbReader["asset_flags"]);
  469. metadata.FullID = DBGuid.FromDB(dbReader["id"]);
  470. metadata.CreatorID = dbReader["creatorid"].ToString();
  471. // We'll ignore this for now - it appears unused!
  472. // metadata.SHA1 = dbReader["hash"]);
  473. UpdateAccessTime(metadata, (int)dbReader["access_time"]);
  474. retList.Add(metadata);
  475. }
  476. }
  477. }
  478. catch (Exception e)
  479. {
  480. m_log.Error("[XASSETS DB]: PGSql failure fetching asset set" + Environment.NewLine + e.ToString());
  481. }
  482. }
  483. }
  484. return retList;
  485. }
  486. public bool Delete(string id)
  487. {
  488. // m_log.DebugFormat("[XASSETS DB]: Deleting asset {0}", id);
  489. lock (m_dbLock)
  490. {
  491. using (NpgsqlConnection dbcon = new NpgsqlConnection(m_connectionString))
  492. {
  493. dbcon.Open();
  494. using (NpgsqlCommand cmd = new NpgsqlCommand(@"delete from XAssetsMeta where id=:ID", dbcon))
  495. {
  496. cmd.Parameters.Add(m_database.CreateParameter(id, id));
  497. cmd.ExecuteNonQuery();
  498. }
  499. // TODO: How do we deal with data from deleted assets? Probably not easily reapable unless we
  500. // keep a reference count (?)
  501. }
  502. }
  503. return true;
  504. }
  505. #endregion
  506. }
  507. }