예제 #1
0
        public bool Execute <T>(ComparisonOperator op, string name, string table_name,
                                T state, T comparand)
        {
            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" + @"
where state_name " + op.Symbol() + @" @name
  and state = @comparand")
                                         .SetType(CommandType.Text)
                                         .AddParameter("@name", name)
                                         .AddParameterWithValue("@state", state)
                                         .AddParameterWithValue("@comparand", comparand)
                                         .Build();
                        try {
                            conn.Open();
                            scope.Complete();
                            return(cmd.ExecuteNonQuery() > 0);
                        } catch (SqlException e) {
                            throw e.AsProviderException();
                        }
                    }
            }
        }