Commits on Aug 3, 2009
Commits on Jul 30, 2009
Commits on Jul 28, 2009
Commits on Jul 27, 2009
  1. Add button graphic, display on press page

    jeremyevans committed Jul 27, 2009
    While here, add an entry for the association_proxies plugin to the
    plugin page.
Commits on Jul 23, 2009
  1. Handle insert better with prepared statements on MSSQL using the JDBC…

    jeremyevans committed Jul 23, 2009
    … adapter.
    While here, make sure to log the SQL statement used to get the
    identity value for the inserted record.
  2. Add an assocation_proxies plugin that uses proxies for associations

    jeremyevans committed Jul 23, 2009
    My design philosophy with Sequel has been that proxies make the code
    more difficult to understand, and should be avoided unless necessary.
    I still feel that the fact that Sequel doesn't use proxies for
    associations is a good thing.  However, Sequel does try to be
    flexible, and this plugin shows how easy it is to modify Sequel to
    use proxies for associations if you so desire.
    The association proxies implemented by this commit are minimal in
    terms of scope.  All they do is pass array methods to the array of
    associated objects, and other methods to the association dataset.
    This has the advantage that you can call dataset methods directly
    on the association method, without all of the complexity entailed by
    ActiveRecord's proxy implementation.  For example, you still need to
    use the add/remove/remove_all methods on the object to modify the
    association.  I'll consider patches to this plugin to add more
    advanced behavior, but don't plan on adding additional support
    Using this plugin should not break backwards compatibility except in
    extreme cases.  One thing that could be broken by it is code that
    expects NoMethodError when the object returned by the association
    method is sent a method is the array of associated objects doesn't
    respond to, but that the association's dataset does.  Another is code
    that expects the association to be cached just by calling the
    associated method, without calling any methods on the object
    returned. Because the array methods are given priority over
    the dataset methods, if you are just using array methods, this plugin
    should not have an effect.
    To ease implementation, the private class method
    def_association_method has been split from
    def_association_dataset_methods.  Also, the Sequel::BasicObject class
    is added if ruby 1.9 is not being used.  Because of the way scoping
    works in ruby, Sequel will use the ::Sequel::BasicObject class as the
    base class for AssociationProxy and VirtualRow on 1.8, and the
    ::BasicObject class on 1.9.
  3. Add RubyKaigi 2009 presentation link to website

    jeremyevans committed Jul 23, 2009
    While here, ignore all *_presentation entries in www/public/static,
    instead of just the LA Ruby Conf one.
Commits on Jul 22, 2009
  1. Add to several existing unittests and add some new tests all related …

    clivecrous authored and jeremyevans committed Jul 19, 2009
    …to testing the _remove_all_* hooks
Commits on Jul 16, 2009
  1. Have the add_*/remove_*/remove_all_* methods take additional argument…

    clivecrous committed Jul 16, 2009
    …s, and pass those arguments down to _add_*/_remove_*/_remove_all_*.
    This patch, amongst other things, would allow one to update columns for joining tables within _add_ methods when working with many_to_many associations, for example:
    class Foo
       def _add_bar(bar, values={})
    (:foo_id=>id, :bar_id=>
    The idea for this patch was first discussed in this thread:
Commits on Jul 13, 2009
  1. Support savepoints on MSSQL using the ODBC and JDBC adapters

    jeremyevans committed Jul 13, 2009
    MSSQL doesn't use the standard savepoint syntax, and doesn't support
    The ADO adapter doesn't support transactions at all, so this does
    not affect MSSQL support on that adapter.
  2. Move convert_tinyint_to_bool method from Sequel to Sequel::MySQL

    jeremyevans committed Jul 9, 2009
    This is a backwards incompatible change, but I think it is for the
    best.  Since the native MySQL adapter is the only adapter that
    converts the tinyint type to boolean, it's the only adapter that
    should have this method.  Other databases, such as MSSQL, have both
    a tinyint type and another type for booleans (MSSQL uses bit), so
    having the tinyint conversion on by default there is a bad idea.
    In addition to moving the method, the implementation has changed a
    bit as well.  Now, only tinyint(1) columns are considered boolean,
    so if you have a tinyint(4) column (the default tinyint size), it
    is not considered boolean.
    Due to limitations in the native MySQL driver, all tinyint column
    values are converted to booleans upon retrieval, not just tinyint(1)
    column values.
    Appropriately, Sequel now uses the tinyint(1) type for TrueClass and
    FalseClass generic types.  Unfortunately, Sequel previously just used
    tinyint instead of tinyint(1), so databases created with the previous
    generic type support using TrueClass or FalseClass on MySQL databases
    will now result in those columns being considered integer columns.
    These changes could break applications.  Care should be taken when
    This commit also adds support for the following types to the schema
    parser and schema dumper: nchar, nvarchar, ntext, smalldatetime,
    smallmoney, binary, and varbinary.
Commits on Jul 11, 2009
  1. Model associations now default to associating to classes in the same …

    jeremyevans committed Jul 11, 2009
    …scope (Fixes #274)
    This changes the default for the :class_name option to use a model in
    the same scope as the current model.  This is a slight breakage of
    backwards compatibility, but should only affect users who are
    associating a model inside a module to a model outside the module.
    Defaulting to an object in the same scope leads to less surprising
    This patch also is a cleaner implementation, since the code no longer
    varies per association type.
Commits on Jul 10, 2009
  1. Support offsets on MSSQL using ROW_NUMBER window function

    jeremyevans committed Jul 10, 2009
    Since MSSQL doesn't support OFFSET natively, it has to be emulated
    by running the query in a subquery and using the ROW_NUMBER window
    function to only return the rows desired.  This is a bit ugly, but
    does work (with integration tests added to check).
    Note that MSSQL requires that you provide an order if you are going
    to use the offset feature.  Most use cases for a limit with an offset
    are going to provide an order, so I don't think this is too much of
    an imposition.
    Because there isn't a good way to not return the ROW_NUMBER field,
    Dataset#each is modified to remove the ROW_NUMBER field if an
    offset is used.
    This commit adds Dataset#unlimited, similar to unfiltered and
    While here, comment the shared MSSQL adapter.
Commits on Jul 8, 2009
  1. Make Dataset#from_self take an options hash and respect an :alias opt…

    jeremyevans committed Jul 8, 2009
    …ion, giving the alias to use
  2. Make the JDBC adapter accept a :convert_types option to turn off Java…

    jeremyevans committed Jul 8, 2009
    … type conversion and double performance
    This gives the user the choice to turn off conversion from Java types
    to ruby types, in order to roughly double the performance when
    fetching rows.  This can be set at both the database and dataset
      DB = Sequel.jdbc('jdbc:postgresql://host/database',
      DB.convert_types = true
      ds = DB[:table]
      ds.convert_types = true
    If you turn off Java type conversion, Date, DateTime, Time, and
    BigDecimal fields will probably be returned as Java types, which
    have a different API than ruby types.  I recommend only turning
    it off if there is a bottleneck in your application, and then
    only for the dataset that is the bottleneck.  Since Sequel allows
    you to modify the setting at the dataset level, that's fairly easy
    to do.
    Note that the setting is not a database option like :from, its a
    setting like quote_identifiers, and modifies the dataset directly
    instead of returning a modified copy, so use with care.
  3. Slight increase in ConnectionPool performance

    jeremyevans committed Jul 8, 2009
    This is a fairly simple refactoring that makes things a little more
    verbose, but performs better.  I tried converting the ConnectionPool
    to use a Monitor and ConditionVariable, but the performance was
    actually worse than the original code (at least on ruby 1.8 and
    I benchmarked all three ways (original, ConditionVariable, and this
    commit), and this commit was the fastest in every case (ruby 1.8,
    ruby 1.9, and jruby).
Commits on Jul 7, 2009
  1. More improvements for Microsoft SQL Server

    jeremyevans committed Jul 7, 2009
    This commit has a whole bunch of small improvments for MSSQL.  Now,
    integration testing on MSSQL results in:
    * ado: 117 examples, 23 failures
    * jdbc: 119 examples, 14 failures
    * odbc: 117 examples, 12 failures
    For the ado adapter, Database#transaction now supports
    Sequel::Rollback.  It also doesn't give an error if a dataset fetch
    returns no rows.  The MSSQL subadapter now returns autoincremented
    primary keys as integers instead of strings.
    DateTime/Time formatting in the ODBC adapter was refactored and
    should now be easier to understand.
    The MSSQL shared adapter now uses the correct datetime and blob
    formats.  It also uses the correct drop_index syntax.
    Model#save now no longer includes primary key fields in the update
    call.  This could potentially result in an error if a primary key
    field is modified, but the previous behavior was probably incorrect.
    Primary key fields should not be modified.
    SQL::WindowFunction is now a subclass of GenericExpression instead
    of Expression.  This allows it to be treated like any other function,
    so you can alias it, cast it, etc..
  2. Much better support for Microsoft SQL Server

    jeremyevans committed Jul 7, 2009
    This substantial commit provides much better support for Microsoft
    SQL Server.  Specific MSSQL subadapters were added for the ado, odbc,
    and jdbc adapters.  Mostly the subadapters involve getting insert
    working properly to return the last inserted id.
    While making these changes I've noticed that the ado adapter has huge
    problems, enough so that I wouldn't recommend that anyone use it.  It
    doesn't use a stable native connection, which means it can't work
    correctly with transactions.  It requires a pretty ugly hack to get
    insert to return the id inserted.
    Transactions on ado now unconditionally yield nil.  I thought about
    them raising an exception instead, but that would make the ado
    adapter not work well with models (without fiddling).  It's possible
    the behavior will be changed in the future.
    As bad as the ado adapter is now, it's still much better than before.
    Before, the ado adapter would run all queries twice when fetching
    rows, and if you did any nonidempotent actions inside the SQL, you'd
    have problems (as I found out when I used the ugly hack to get
    insert to return the id inserted).
    The ado and odbc adapters now catch the native exceptions and raise
    Sequel::DatabaseError exceptions.  Also, the behavior to handle
    blank identifiers has been standardized.  Sequel will now assume an
    identifier of 'untitled' if a blank identifier is given.
    The shared MSSQL adapter now supports Database#tables and
    Database#schema, using the INFORMATION_SCHEMA views (very similarly
    to what was used in Sequel 2.0).  Now, it also supports add_column,
    rename_column, set_columns_type, set_column_null, and
    The shared MSSQL's schema method doesn't include primary key info, so
    some of the model logic changed so that it doesn't try to set
    no primary key unless all schema hashes include a primary key entry.
    The shared MSSQL adapter now uses the datetime type instead of the
    timestamp type for generic datetimes, and uses bit and image for
    boolean and file types.  It uses 0 and 1 for false and true, and
    no longer attempts to use IS TRUE.
    The odbc adapter's literal_time method has been fixed.
    In order to ease the connection to MSSQL servers with instances
    using a connection string, Sequel now will unescape URL parts. So the
    following now works:
    The ado adapter specs were removed, because the ado adapter itself
    doesn't really have any specific behavior that should be tested.  Now
    that Sequel has the generic integration tests, those should be used
    instead.  I removed the spec_ado rake task. and replaced it with a
    spec_firebird rake task.
    Here's the results for integration testing on MSSQL with each
    * ado: 115 examples, 42 failures
    * jdbc: 117 examples, 22 failures
    * odbc: 115 examples, 19 failures
    Many of the remaining failures are due to the fact that some tests
    try to insert values into an autoincrementing primary key field,
    which MSSQL doesn't allow.  Those tests should be refactored unless
    they are explicitly testing that feature.
Commits on Jul 6, 2009
  1. Support altering a columns type, null status, or default on SQLite

    jeremyevans committed Jul 6, 2009
    This commit adds a generic duplicate_table private method for SQLite
    Databases, which allows easier support for emulating the ALTER TABLE
    commands that SQLite doesn't support natively (which is pretty much
    all of them).
    In addition to supporting set_column_type, set_column_allow_null,
    and set_column_default, it also supports add_primary_key, and
    supports adding unique columns.  It does not support adding
    constraints, however, since Sequel doesn't parse out constraints.
    This commit refactors the drop_column and rename_column code to
    use the new duplicate_table functionality, which significantly
    reduces the amount of code required.  It removes the columns_for
    private Database method, which is no longer used.
    To allow easier creation of tables directly from parsed schema
    information, column_definition_sql now supports :allow_null in
    addition to :null for specifying the NULL/NOT NULL status of
    a column.  :null is preferred if present.
    Many integration tests were added to test out these features.
Commits on Jul 5, 2009
  1. Mysql shared adapter overwrites changes from migration files

    nougad authored and jeremyevans committed Jul 5, 2009
    For example in this modification the new default value is
    overwritten by the old one.
    alter_table :incoming_entries do
      rename_column :priority, :severity, :default => "ASDF"
Commits on Jul 2, 2009
  1. Bump version to 3.2.0

    jeremyevans committed Jul 2, 2009
Commits on Jun 29, 2009
  1. n the STI plugin, don't overwrite the STI field if it is already set

    jeremyevans committed Jun 29, 2009
    This allows the following to work as expected:
      class Person < Sequel::Model
        plugin :single_table_inheritance, :kind
      class Manager < Person
      Person.create(:kind => "Manager")
  2. Add support for Common Table Expressions, which use the SQL WITH clause

    jeremyevans committed Jun 29, 2009
    CTEs are supported by MSSQL 2005+, DB2 7+, Firebird 2.1+, Oracle 9+,
    and PostgreSQL 8.4+.  They allow you to specify inline views that
    the SELECT query can reference, and also support a recursive mode
    that allows tables in the WITH clause to reference themselves. This
    allows things not normally possible in standard SQL, like loading all
    descendents in a tree structure in a single query.
    The standard with clause takes an alias and a dataset:
      ds = DB[:vw]
      ds.with(:vw, DB[:table].filter{col < 1})
      # WITH vw AS (SELECT * FROM table WHERE col < 1) SELECT * FROM vw
    The recursive with clause usage takes an alias, a nonrecursive
    dataset, and a recursive dataset:
        DB[:tree].join(:vw, :id=>:parent_id).
                  select(:vw__id, :vw__parent_id))
      # WITH RECURSIVE vw AS (SELECT * FROM "tree"
      #     WHERE ("id" = 1)
      #     UNION ALL
      #     SELECT "vw"."id", "vw"."parent_id"
      #     FROM "tree"
      #     INNER JOIN "vw" ON ("vw"."id" = "tree"."parent_id"))
      # SELECT * FROM "vw"
    I've only tested this on an PostgreSQL 8.4 release candidate, but
    based on my research it should support MSSQL, DB2, and Firebird.
    Oracle apparently uses a different method for recursive queries.
    This commit contains some fixes for the window functions committed
    previously.  Like now, it actually works on ruby 1.9.  The
    Dataset#supports_window_functions? method is now defined and
    defaults to false, and the adapters that support window
    functions override it.  If you attempt to use a window function
    on an unsupported dataset, an Error will be raised.
    Sequel's default is to support common table expressions, so the
    databases that don't support CTEs have been modified to not use the
    with clause if they previously used the default clauses.
    The MSSQL adapter was already using the :with option for setting
    NOLOCK on the query, so I changed the setting to use :table_options.
    Because the clauses the PostgreSQL adapter will use depends on the
    server version, I changed the code for getting the server version
    to use static SQL in order to avoid infinite recursion.
    PostgreSQL dataset's explain and analyze methods were broken since
    3.0, this commit fixes them and adds a simple spec.
    In order to implement the with_recursive method easily, the compound
    dataset methods (union, except, and intersect) now take an options
    hash instead of a true/false flag.  The previous true/false flag is
    still supported for backwards compatibility.  You can now specify it
    with the :all option, and there is now a :from_self option that you
    can set to false if you don't want to return a from_self dataset.
    This commit adds the qualify and with dataset methods to