public bool Execute(string name, string table_name, long state) { using ( new TransactionScope(SupressTransactions ? TransactionScopeOption.Suppress : TransactionScopeOption.Required)) { using ( SqlCeConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(@" update " + table_name + @" set state = @state" + @" where name = @name and state < @state") .SetType(CommandType.Text) .AddParameter("@name", name) .AddParameterWithValue("@state", state) .Build(); try { conn.Open(); return cmd.ExecuteNonQuery() > 0; } catch (SqlCeException e) { throw e.AsProviderException(); } } } }
protected virtual string Execute(IQuery query, IDictionary<string, string> parameters, IConnectionProvider provider) { using (IDbConnection connection = provider.CreateConnection()) using (var builder = new CommandBuilder(connection)) { builder .SetText(query.QueryText) .SetType(GetCommandType(query.Options)) .SetTimeout(query.Options .GetInteger(Strings.kCommandTimeoutOption, 30)); BindParameters(builder, query.Parameters, parameters); string preferred_json_collection = query.Options .GetString(Strings.kJsonCollectionOption, Strings.kDefaultJsonCollection); IDbCommand cmd = builder.Build(); connection.Open(); string response = (query.QueryMethod == QueryMethod.Get) ? ExecuteReader(cmd, query, preferred_json_collection) : ExecuteNonQuery(cmd, query, preferred_json_collection); connection.Close(); return response; } }
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(); } } } }
void ExecuteInternal(string table_name, string state_type) { using (SqlCeConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(@" create table " + table_name + @"( name nvarchar(1024) unique, state " + state_type + ")") .SetType(CommandType.Text) .Build(); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlCeException e) { e.AsProviderException(); } } }
public bool Execute(string table_name) { using (SqlCeConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(@" select table_name from information_schema.tables where table_name = @name") .SetType(CommandType.Text) .AddParameter("@name", table_name) .Build(); try { conn.Open(); return cmd.ExecuteScalar() != null; } catch (SqlCeException e) { throw e.AsProviderException(); } } }
public void Execute() { using (SqlCeConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(kExecute) .SetType(CommandType.Text) .Build(); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlCeException e) { logger_.Error( StringResources.Log_MethodThrowsException.Fmt("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); } } }
public bool Execute(out IdleTimeInfo idle_time_info) { using (SqlCeConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(kExecute) .SetType(CommandType.Text) .Build(); try { conn.Open(); using (IDataReader reader = cmd.ExecuteReader()) { return mapper_.Map(reader, out idle_time_info); } } catch (SqlException e) { logger_.Error( StringResources.Log_MethodThrowsException.Fmt("Execute", kClassName), e); throw new ProviderException(e); } } }
public void Execute(IdleTimeInfo idle_time_info) { using (SqlCeConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(kExecute) .SetType(CommandType.Text) .AddParameter("@lastInputTime", idle_time_info.LastInputTime) .AddParameter("@machineUpTime", idle_time_info.MachineUpTime) .AddParameter("@timestamp", idle_time_info.Timestamp) .Build(); try { conn.Open(); cmd.ExecuteNonQuery(); } catch (SqlCeException e) { logger_.Error( StringResources.Log_MethodThrowsException.Fmt("Execute", kClassName), e); throw new ProviderException(e); } } }
/// <inheritdoc/> public bool GetQuery(string name, out IQuery query) { using (SqlConnection conn = sql_connection_provider_.CreateConnection()) using (var builder = new CommandBuilder(conn)) { IDbCommand cmd = builder .SetText(sql_connection_provider_.Schema + kGetQuery) .SetType(CommandType.StoredProcedure) .AddParameter("@name", name, DbType.String, 260) .Build(); try { conn.Open(); using (IDataReader dr = cmd.ExecuteReader()) { query = CreateQueryFromDataReader(dr); return true; } } catch (SqlException e) { logger_.Error( string.Format(StringResources.Log_MethodThrowsException, kClassName, "GetQuery"), e); } } query = null; return false; }
void BindParameters(CommandBuilder builder, IEnumerable<string> names, IDictionary<string, string> values) { foreach (string name in names) { string value; if (!values.TryGetValue(name, out value)) { throw new KeyNotFoundException( string.Format(Resources.QueryExecutor_Missing_ParameterValue, name)); } builder.AddParameterWithValue(name, value); } }