예제 #1
0
        private IDbCommand CreateExecutableCommand(IDbConnection connection)
        {
            IDbCommand command = _factory.CreateQuery(_command.CommandText);

            try {
                command.CommandType = _command.CommandType;
                command.Connection  = connection;
                foreach (IDataParameter parameter in _command.Parameters)
                {
                    IDataParameter parameterCopy = command.CreateParameter();
                    parameterCopy.ParameterName = parameter.ParameterName;
                    parameterCopy.Value         = parameter.Value;
                    parameterCopy.Direction     = parameter.Direction;
                    command.Parameters.Add(parameterCopy);
                }
            } catch {
                if (command != null)
                {
                    // must dispose of command in case of failure
                    command.Dispose();
                }
                throw;
            }
            return(command);
        }
예제 #2
0
 /// <summary>
 /// Create a new query command.
 /// </summary>
 /// <param name="query">SQL query string.</param>
 /// <param name="readonly"><see langword="True"/> if the query is read-only.</param>
 /// <returns>New Query instance.</returns>
 public DataCommand NewQuery(string query, bool @readonly)
 {
     if (@readonly && string.IsNullOrEmpty(_readonlyconnection))
     {
         throw new DreamException("No read-only connection string has been defined.");
     }
     return(new DataCommand(_factory, this, @readonly ? _readonlyconnection : _connection, _factory.CreateQuery(query)));
 }
 /// <summary>
 /// Create a new query command.
 /// </summary>
 /// <param name="query">SQL query string.</param>
 /// <param name="readonly"><see langword="True"/> if the query is read-only.</param>
 /// <returns>New Query instance.</returns>
 public DataCommand NewQuery(string query, bool @readonly)
 {
     return(new DataCommand(_factory, this, @readonly ? _readonlyconnection : _connection, _factory.CreateQuery(query)));
 }