/// <exception cref="ProviderException"> /// An exception has occured while executing the query. /// </exception> public bool Execute(string name, out string state) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(sql_connection_provider_.Schema + kExecute) .SetType(CommandType.StoredProcedure) .AddParameter(kNameParameter, name) .Build(); try { conn.Open(); object obj = cmd.ExecuteScalar(); if (obj != null) { state = (string)obj; return(true); } } catch (SqlException e) { logger_.Error(string.Format( R.Log_MethodThrowsException, "Execute", kClassName), e); throw new ProviderException(e); } state = null; return(false); } }
public int Execute(string state_name, string table_name, bool likely = false) { using (var scope = new TransactionScope(SupressTransactions ? TransactionScopeOption.Suppress : TransactionScopeOption.Required)) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText("delete from " + table_name + " where state_name " + (likely ? " like " : "=") + "@name") .SetType(CommandType.Text) .AddParameter("@name", state_name) .Build(); try { conn.Open(); int affected = cmd.ExecuteNonQuery(); scope.Complete(); return(affected); } catch (SqlException e) { logger_.Error( StringResources.Log_MethodThrowsException.Fmt("Execute", kClassName), e); throw e.AsProviderException(); } } } }
public bool Execute <T>(string name, string table_name, T state) { using (var scope = new TransactionScope(SupressTransactions ? TransactionScopeOption.Suppress : TransactionScopeOption.Required)) { using ( SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(@" update " + table_name + @" set state = state + @state" + @" where state_name = @name") .SetType(CommandType.Text) .AddParameter("@name", name) .AddParameterWithValue("@state", state) .Build(); try { conn.Open(); scope.Complete(); return(cmd.ExecuteNonQuery() > 0); } catch (SqlException e) { throw e.AsProviderException(); } } } }
public void Execute(string state_name, string table_name, object state) { using (var scope = new TransactionScope(SupressTransactions ? TransactionScopeOption.Suppress : TransactionScopeOption.Required)) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(@" insert into " + table_name + @"(state_name, state) values(@name, @state)") .SetType(CommandType.Text) .AddParameter("@name", state_name) .AddParameterWithValue("@state", state) .Build(); try { conn.Open(); cmd.ExecuteNonQuery(); scope.Complete(); } catch (SqlException e) { throw e.AsProviderException(); } } } }
public T ExecuteQuery <T>(string query, Func <IDataReader, T> mapper, Action <CommandBuilder> set_parameters, CommandType command_type) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(query) .SetType(command_type) .Set(set_parameters) .Build(); try { conn.Open(); using (IDataReader reader = cmd.ExecuteReader()) { return(mapper(reader)); } } catch (SqlException e) { logger_.Error( StringResources .Log_MethodThrowsException .Fmt("ExecuteQuery", kClassName), e); throw e.AsProviderException(); } } }
public bool Execute <T>(string state_name, string table_name, out T state, bool remove = false) { using (var scope = new TransactionScope(SupressTransactions ? TransactionScopeOption.Suppress : TransactionScopeOption.Required)) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(GetText(table_name, false, remove, false)) .SetType(CommandType.Text) .AddParameter("@name", state_name) .Build(); try { conn.Open(); object obj = cmd.ExecuteScalar(); if (obj == null) { state = default(T); scope.Complete(); return(false); } state = (T)obj; scope.Complete(); return(true); } catch (SqlException e) { logger_.Error( StringResources.Log_MethodThrowsException.Fmt("Execute", kClassName), e); throw e.AsProviderException(); } } } }
/// <inheritdoc/> public void Execute(string name, string state) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(sql_connection_provider_.Schema + kExecute) .SetType(CommandType.StoredProcedure) .AddParameter(kNameParameter, name) .AddParameter(kStateParameter, state) .Build(); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlException e) { logger_.Error( string.Format(R.Log_MethodThrowsException, "Execute", kClassName), e); throw new ProviderException(e); } } }
public IHiLoRange Execute(string key) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(sql_connection_provider_.Schema + kExecute) .SetType(CommandType.StoredProcedure) .AddParameter(kKeyParameter, key) .Build(); try { conn.Open(); using (IDataReader reader = cmd.ExecuteReader()) { return(mapper_.Map(reader)); } } catch (SqlException e) { logger_.Error(string.Format( StringResources.Log_MethodThrowsException, "Execute", kClassName), e); throw new ProviderException(e); } } }