Commits on Dec 1, 2009
  1. Bump version to 3.7.0

    committed Dec 1, 2009
Commits on Nov 30, 2009
  1. Add Dataset#sequence to the shared Oracle Adapter, for returning auto…

    …generated primary key values on insert (Fixes #280)
    Oracle is like PostgreSQL in that autogenerated primary key values
    are handled by sequences.  Unlike Sequel's shared PostgreSQL adapter,
    Sequel's shared Oracle adapter doesn't handle automatically
    determining the primary key value based on the table.  That may be
    possible to fix, but without access to an Oracle database it would
    be difficult.
    Dataset#sequence provides a workaround for the problem, allowing the
    manual specification of the sequence. Dataset#insert is then
    overridden to check for an associated sequence, and return the most
    recently inserted value upon insert.
    committed Nov 30, 2009
Commits on Nov 23, 2009
  1. Fix deleting from joined datasets on MySQL

    While here, no longer include joins in delete_from_sql by default.
    Since all of the adapters that support modifying joins override it,
    there's no reason to include it.
    Also, remove the order on the joined dataset in the integration
    test so that updating works on MySQL (which allows order clauses
    in update statements, but not when multiple tables are used).
    Note that MySQL allows deleting from multiple tables at once, but
    Sequel doesn't support this.  Sequel assumes the first table in
    FROM is the one being deleted from, and the rest are just for
    selecting rows.  This is for consistency with how Sequel works on
    PostgreSQL and MSSQL.
    committed Nov 23, 2009
Commits on Nov 22, 2009
Commits on Nov 21, 2009
  1. Bring support for modifying joined datasets into Sequel proper, suppo…

    …rted on MySQL and PostgreSQL
    Previously, the MSSQL adapter had specific support for deleting and
    updating joined datasets.  This commit brings support into standard
    Sequel, and supports it on MySQL and PostgreSQL. Note that support
    and semantics for updating joined datasets varies by database.
    This also contains changes to the MSSQL support as well, which should
    work better for datasets with multiple FROM tables.
    To ease implementation, add a Dataset#joined_dataset? private method.
    committed Nov 21, 2009
  2. No longer use native autoreconnection in the mysql adapter

    Native autoreconnection has problems with prepared statements, where
    a new native connection is used behind Sequel's back, so Sequel
    thinks the prepared statement has already been defined on the
    connection, when it fact it hasn't.  Any other changes that affect
    the state of the connection will be lost when native autoreconnection
    is used as well.
    Sequel's connection pool already handles reconnection if it detects a
    disconnection.  This commit also adds an additional exception message
    to recognize as a disconnect.
    committed Nov 21, 2009

    The main advantage here for most people is NOTNULL.  This allows the
    following to work:
      include Sequel::SQL::Constants
      DB[:table].where(:a=>'1', :b=>NOTNULL)
    Before, the shortest way to do this was:
    It may make the code more descriptive:
      # compared to
    This gives the option to use SQL terminology instead of ruby
    The other advantage of using the constants it that they handle
    operators and methods like other Sequel::SQL objects:
      NULL & SQLFALSE # BooleanExpression => "(NULL AND FALSE)"
      nil & false     # false
      NULL + :a       # NumericExpression => "(NULL + a)"
      nil + :a        # raises NoMethodError
      NULL.sql_string + :a  # StringExpression => "(NULL || a)"     # AliasedExpression => "NULL AS b"
    For complex systems that want to represent SQL boolean objects
    in ruby (where you don't know exactly how they'll be used), using
    the constants is recommended.
    In order not to be too verbose, including Sequel::SQL::Constants
    is recommended.  It's not done by default, but you can still
    reference the constants under the main Sequel module by default
    (e.g. Sequel::NULL).
    committed Nov 21, 2009
Commits on Nov 20, 2009
  1. Add Dataset #select_map, #select_order_map, and #select_hash

    select_map and select_order_map both return arrays of values for the
    column specified.  The column can be specified either via an argument
    or a block, similar to Dataset#get.  Both accept any valid objects as
    select_hash returns a hash.  It requires two symbol arguments, but
    can handle implicit qualifiers or aliases in the symbols.
    Neither of these methods offer any new functionality, they just cut
    down on the number of required key strokes:
      select_map(:column)       # select(:column).map(:column)
      select_order_map(:column) # select(:column).order(:column).
                                #  map(:column)
      select_hash(:key_column, :value_column)
      # select(:key_column, :value_column).
      #  to_hash(:key_column, :value_column)
    This makes it easier to get simple ruby arrays and hashes out of
    To implement select_hash, add private method Dataset#hash_key_symbol,
    which attempts to guess the hash key symbol that will be used for
    the given column symbol.
    While here, remove Dataset::GET_ERROR_MSG and Dataset::MAP_ERROR_MSG
    constants, replacing both with Dataset::ARG_BLOCK_ERROR_MSG.
    committed Nov 20, 2009
  2. Make Dataset#group_and_count handle arguments other than Symbols

    I think with a past change to handle implicit aliases in Symbol
    arguments, it no longer worked with other objects, as it assumed
    all arguments were Symbols.  That is not a valid assumption.
    Introduce Dataset#unaliased_identifier private method that
    handles both implicit aliases in symbols and AliasedExpression
    objects, returning the unaliased argument, and have group_and_count
    use it.
    committed Nov 20, 2009
  3. Add :only_if_modified option to validates_unique method in validation…

    …_helpers plugin
    Using this option should speed up the common case where the unique
    attribute is not modified for an existing record.  It is not on by
    default, since the following is possible:
      album = Album[1] # 'YJM'
      # Database is modified outside application:
      #   UPDATE albums SET name ='BB' WHERE id = 1
      #   UPDATE albums SET name = 'YJM' WHERE id = 2
      # Would violate uniqueness constraint by setting album 1's
      # name back to 'YJM'
    committed Nov 20, 2009
Commits on Nov 19, 2009
Commits on Nov 18, 2009
  1. In Model#save and destroy, don't rollback transactions you didn't ini…

    This fixes the issue where an outer transaction is present, and
    use_transactions is set for the model instance, and one of the
    before hooks returns false.  With the recent commits, that would
    rollback the outer transaction.
    This required refactoring so that save_failure now always raises,
    it doesn't check raise_on_save_failure.  Model#save and destroy
    now use checked_save_failure, which ignore the error raised by
    save_failure if raise_on_save_failure is true.
    While refactoring, I decided it was no longer worth using
    save_failure to handle validation failures, so the validation
    failures don't call it.  before_validation hook callers only call
    it if raise_on_save_failure is true, since they aren't wrapped
    by check_save_failure.
    This breaks backwards compatibility for callers of save_failure,
    which is a private method.
    While here, add checked_transaction private method that uses
    transactions if necessary.
    committed Nov 18, 2009
Commits on Nov 17, 2009
  1. Some minor cleanup to previous commit

    Instead of making use_transactions a special instance method, keep
    it as previously defined and add a use_transaction? private method
    that takes an option hash.  I think this is a bit cleaner.
    Also, make a few minor changes to the specs and update the
    committed Nov 17, 2009
  2. Ensure transactions around save and destroy are rolled back when a be…

    …fore hook returns false
    Three cases:
    1) raise_on_save_failure true: Existing behavior was correct;
    save_failure raises an exception that rolls back the transaction
    and is reraised.
    2) raise_on_save_failure false and use_transaction true: save_failure
    raises Rollback, which the transaction code will take care of.
    3) raise_on_save_failure false and use_transaction false: should just
    return false, as raising Rollback and catching it makes it impossible
    to differentiate between the a before hook returning false and a user
    raising Rollback in a before hook (which they expect to bubble up to
    their own transaction code).
    While here, support the :transaction option in destroy
    John Firebaugh committed with Nov 17, 2009
Commits on Nov 16, 2009
  1. On postgres, use bigserial type if :type=>Bignum is given as an optio…

    …n to primary_key
    This makes Sequel's shared postgres adapter act more similarly to the
    other adapters (e.g. mysql), which allow you to specify :type=>Bignum
    as a primary_key option to create an autoincrementing 64 bit integer
    primary key field.
    This also changes the schema dumper to specify the :type option to
    primary key if it isn't Integer.
    committed Nov 16, 2009
Commits on Nov 12, 2009
Commits on Nov 10, 2009
  1. Update CHANGELOG

    committed Nov 10, 2009
  2. fix for correctly reading options defined under the [client] tag in t…

    …he mysql configuration file
    crohr committed Nov 10, 2009
Commits on Nov 2, 2009
  1. Bump version to 3.6.0

    committed Nov 2, 2009
Commits on Oct 29, 2009
  1. Make the MSSQL shared adapter correctly parse the column schema infor…

    …mation for tables in the non-default database schema
    committed Oct 29, 2009
  2. Use save_changes instead of save when updating existing associated ob…

    …jects in the nested_attributes plugin
    This should be significantly faster for the case where you are
    displaying a complex form to the user, and they make no changes to
    the existing associated records when they submit it.
    This shouldn't have a negative effect on production code, unless
    save_changes doesn't work correctly for the associated objects.
    It may break test code that checks for specific SQL or columns in
    the update statement.
    committed Oct 29, 2009
  3. Allow Model#save_changes to accept an option hash that is passed to s…

    …ave, so you can save changes without validating
    committed Oct 29, 2009
Commits on Oct 28, 2009
  1. Make nested_attributes plugin add newly created objects to cached ass…

    …ociation array immediately
    The reasoning behind this is that if this isn't done, the current
    object has no way to access the nested attribute records until
    after the save.
    The general use case for nested_attributes is a web form that
    handles dependent records.  Without any access to the nested
    records, it is very difficult to handle validation failures
    and display nice error messages to the user if dependent records
    are not valid.
    This approach adds the newly created records to the cached array,
    so if validation fails, you can just iterate over the cached array,
    and it will have both previously existing and new records in it.
    This change does not affect many_to_one associations, since they
    don't have a cached association array, and setting the object
    in the cached association would probably cause issues.
    This also doesn't affect updating existing records, since those
    are already in the array.
    committed Oct 28, 2009
  2. Allow easier overriding of default options used in the validation_hel…

    …pers plugin
    This breaks backwards compatibility if you were relying on the
    change made on October 20 to set the default validation error
    messages.  This generalizes support for overriding any of the
    default options.  As before, you can override it on a global level:
        merge!(:message=>"incorrect format", :allow_missing=>true)
    You can also override it on a per class basis via:
      class Album < Sequel::Model
        plugin :validation_helpers
          :format=>{:message=>"incorrect format", :allow_missing=>true}}
        def default_validation_helpers_options(type)
          super.merge(DEFAULT_VALIDATION_OPTIONS[type] || {})
    This removes the MESSAGE_PROCS constant from the ValidationHelpers
    module, and removes the private instance method
    default_validation_error_message_proc.  It changes the API for
    validation_error_message and adds the
    default_validation_helpers_options and
    validatable_attributes_for_type private instance methods.
    I chose not to change the validatable_attributes API, even though
    it could be simplified now, because while the method is private,
    I expect there may be consumers other than the default validations.
    committed Oct 28, 2009
Commits on Oct 27, 2009
  1. Make add_ association method not add the associated object to the cac…

    …hed array if it's already there
    This makes the most sense for one_to_many associations, since those cannot
    be associated more than once.  For many_to_many associations, I think it
    is a better default, as it's a rare case that you want duplicate items
    in the association.  If you do want duplicate items for a many_to_many
    association and you want it to work well with caching, please bring it
    up on the Sequel mailing list and we'll work it out.
    Note that this exact thing was done for reciprocal associations, so
    Sequel is more consistent with this change.
    committed Oct 27, 2009
  2. Update CHANGELOG

    committed Oct 27, 2009