/// <summary> /// Fetch Asset <paramref name="assetID"/> from database /// </summary> /// <param name="assetID">Asset UUID to fetch</param> /// <returns>Return the asset</returns> /// <remarks>On failure : throw an exception and attempt to reconnect to database</remarks> override protected AssetBase FetchStoredAsset(UUID assetID) { AssetBase asset = null; lock (_dbConnection) { _dbConnection.CheckConnection(); MySqlCommand cmd = new MySqlCommand( "SELECT name, description, assetType, local, temporary, data FROM assets WHERE id=?id", _dbConnection.Connection); cmd.Parameters.AddWithValue("?id", assetID.ToString()); try { using (MySqlDataReader dbReader = cmd.ExecuteReader(CommandBehavior.SingleRow)) { if (dbReader.Read()) { asset = new AssetBase(); asset.Data = (byte[])dbReader["data"]; asset.Description = (string)dbReader["description"]; asset.FullID = assetID; try { asset.Local = (bool)dbReader["local"]; } catch (InvalidCastException) { asset.Local = false; } asset.Name = (string)dbReader["name"]; asset.Type = (sbyte)dbReader["assetType"]; } dbReader.Close(); cmd.Dispose(); } if (asset != null) { UpdateAccessTime(asset); } } catch (Exception e) { m_log.ErrorFormat( "[ASSETS DB]: MySql failure fetching asset {0}" + Environment.NewLine + e.ToString() + Environment.NewLine + "Reconnecting", assetID); _dbConnection.Reconnect(); } } return(asset); }
/// <summary> /// Saves a log item to the database /// </summary> /// <param name="serverDaemon">The daemon triggering the event</param> /// <param name="target">The target of the action (region / agent UUID, etc)</param> /// <param name="methodCall">The method call where the problem occured</param> /// <param name="arguments">The arguments passed to the method</param> /// <param name="priority">How critical is this?</param> /// <param name="logMessage">The message to log</param> public void saveLog(string serverDaemon, string target, string methodCall, string arguments, int priority, string logMessage) { try { database.insertLogRow(serverDaemon, target, methodCall, arguments, priority, logMessage); } catch { database.Reconnect(); } }
/// <summary> /// Returns a list of items in a specified folder /// </summary> /// <param name="folderID">The folder to search</param> /// <returns>A list containing inventory items</returns> public List <InventoryItemBase> getInventoryInFolder(UUID folderID) { try { lock (database) { List <InventoryItemBase> items = new List <InventoryItemBase>(); database.CheckConnection(); MySqlCommand result = new MySqlCommand("SELECT * FROM inventoryitems WHERE parentFolderID = ?uuid", database.Connection); result.Parameters.AddWithValue("?uuid", folderID.ToString()); MySqlDataReader reader = result.ExecuteReader(); while (reader.Read()) { // A null item (because something went wrong) breaks everything in the folder InventoryItemBase item = readInventoryItem(reader); if (item != null) { items.Add(item); } } reader.Close(); result.Dispose(); return(items); } } catch (Exception e) { database.Reconnect(); m_log.Error(e.ToString()); return(null); } }