/************************************************************************************ * * Umbraco Data Layer * MIT Licensed work * ©2008 Ruben Verborgh * ***********************************************************************************/ using System; using System.Data; using System.Data.SqlClient; using System.Xml; using SH = Microsoft.ApplicationBlocks.Data.SqlHelper; using System.Diagnostics; namespace umbraco.DataLayer.SqlHelpers.SqlServer { /// /// Sql Helper for an SQL Server database. /// public class SqlServerHelper : SqlHelper { /// /// Initializes a new instance of the class. /// /// The connection string. public SqlServerHelper(string connectionString) : base(connectionString) { m_Utility = new SqlServerUtility(this); } /// /// Creates a new parameter for use with this specific implementation of ISqlHelper. /// /// Name of the parameter. /// Value of the parameter. /// A new parameter of the correct type. /// Abstract factory pattern public override IParameter CreateParameter(string parameterName, object value) { return new SqlServerParameter(parameterName, value); } /// /// Executes a command that returns a single value. /// /// The command text. /// The parameters. /// The return value of the command. protected override object ExecuteScalar(string commandText, SqlParameter[] parameters) { #if DEBUG && DebugDataLayer // Log Query Execution Trace.TraceInformation(GetType().Name + " SQL ExecuteScalar: " + commandText); #endif return SH.ExecuteScalar(ConnectionString, CommandType.Text, commandText, parameters); } /// /// Executes a command and returns the number of rows affected. /// /// The command text. /// The parameters. /// /// The number of rows affected by the command. /// protected override int ExecuteNonQuery(string commandText, SqlParameter[] parameters) { #if DEBUG && DebugDataLayer // Log Query Execution Trace.TraceInformation(GetType().Name + " SQL ExecuteNonQuery: " + commandText); #endif return SH.ExecuteNonQuery(ConnectionString, CommandType.Text, commandText, parameters); } /// /// Executes a command and returns a records reader containing the results. /// /// The command text. /// The parameters. /// /// A data reader containing the results of the command. /// protected override IRecordsReader ExecuteReader(string commandText, SqlParameter[] parameters) { #if DEBUG && DebugDataLayer // Log Query Execution Trace.TraceInformation(GetType().Name + " SQL ExecuteReader: " + commandText); #endif return new SqlServerDataReader(SH.ExecuteReader(ConnectionString, CommandType.Text, commandText, parameters)); } } }