/************************************************************************************
*
* Umbraco Data Layer
* MIT Licensed work
* ©2008 Ruben Verborgh
*
***********************************************************************************/
using System;
using System.Collections.Generic;
using System.Text;
namespace umbraco.DataLayer
{
///
/// Exception generated in an SQL helper.
///
public class SqlHelperException : UmbracoException
{
#region Private Fields
/*
* Make command text and parameters available when in debug mode.
* (General debug mode, not only data layer debug mode: exceptions that occur in commands
* are most likely not due to errors in the data layer itself, but in the calling method.)
*/
#if DEBUG
/// The text of the command that resulted in the exception.
private readonly string m_CommandText;
/// The parameters of the command that resulted in the exception.
private readonly IParameter[] m_Parameters;
#endif // DEBUG
#endregion
#region Public Properties
/*
* Make command text and parameters available when in debug mode.
* (General debug mode, not only data layer debug mode: exceptions that occur in commands
* are most likely not due to errors in the data layer itself, but in the calling method.)
*/
#if DEBUG
///
/// Returns the text of the command that resulted in the exception.
///
/// The command text.
/// Attention! Use for debugging purposes only.
public string CommandText
{
get { return m_CommandText; }
}
///
/// Gets the parameters of the command that resulted in the exception.
///
/// The command parameters.
/// Attention! Use for debugging purposes only.
public IParameter[] Parameters
{
get { return m_Parameters; }
}
#endif // DEBUG
#endregion
#region Public Constructors
///
/// Initializes a new instance of the class.
///
/// The method where the exception occurred.
/// The command text. Only used in debug mode.
/// The command parameters. Only used in debug mode.
/// The inner exception.
///
/// *Never* place the command text inside the exception message,
/// since the message could be shown on a level with lower security.
/// Especially dangerous with faulty command texts (code injection),
/// or commands with inline parameters. (information leak)
/// (So there's another reason to use real parameters.)
///
public SqlHelperException(string method, string commandText, IParameter[] parameters, Exception innerException)
: base(String.Format("SQL helper exception in {0}", method), innerException)
{
#if DEBUG
// Save command and parameters
m_CommandText = commandText;
m_Parameters = parameters;
#endif // DEBUG
}
#endregion
}
}