Commits on Aug 27, 2008
  1. Use INSERT ... RETURNING ... with PostgreSQL 8.2 and higher

    This makes the PostgreSQL adapter use INSERT ... RETURNING ... if it
    is connected to an 8.2.0 or later server.  This should provide a
    performance boost, as it doesn't require extra queries being issued
    to determine the value of the inserted primary key.
    This also makes the Database object clear the cache for @primary_keys
    and @primary_key_sequences when drop_table is called.  It adds a
    Database#primary_key public method for determining the primary key
    for a given table. If also adds a Dataset#server_version private
    method to make things more testable.
    committed Aug 27, 2008
  2. Document general but adapter specific return values for fetch_rows, d…

    …elete, insert, and update
    committed Aug 27, 2008
  3. Make insert_sql, delete_sql, and update_sql respect the :sql option

    Before this commit, all of the following would raise errors:
      DB["INSERT INTO blah (id) VALUES (1)"].insert_sql
      DB["DELETE FROM blah"].delete_sql
      DB["UPDATE blah SET num = 1"].update_sql
    Now, these just return the SQL given.  This implies:
      ds = DB["..."]
      ds.update_sql.should == ds.delete_sql
    committed Aug 27, 2008
  4. Default to converting 2 digit years

    Before, Sequel would treat 06/07/08 as being in the year 0008 instead
    of 2008, at least when using the Date and DateTime classes.  This
    commit changes that so that 2 digit years are treated as year + 1900
    if year >= 69 or year + 2000 if year < 69.  To get back the old
      Sequel.convert_two_digit_years = false
    If you are using ruby 1.9, you should watch out, as the date parsing
    differs from ruby 1.8:
      Date.parse('01/02/08', true).to_s # ruby 1.8 => "2008-01-02"
      Date.parse('01/02/08', true).to_s # ruby 1.9 => "2001-02-08"
    committed Aug 27, 2008
Commits on Aug 26, 2008
  1. Make the PostgreSQL adapter with the pg driver use async_exec, so it …

    …doesn't block the entire interpreter
    committed Aug 26, 2008
Commits on Aug 24, 2008
Commits on Aug 22, 2008
  1. Added support for composite primary key, composite foreign key and un…

    …ique constraints to Schema::Generator and Schema::AlterTableGenerator
    jarredholman committed Aug 22, 2008
Commits on Aug 20, 2008
Commits on Aug 19, 2008
  1. Disallow abuse of SQL function syntax for types (use :type=>:varchar,…

    … :size=>255 instead of :type=>:varchar[255])
    This commit also refactors type_literal to return the entire literal
    value for the type, instead of just the base type (so it includes
    any length and/or UNSIGNED specifiers).  It also makes type_literal
    In addition, this fixes an issue with renaming or changing the type
    of a varchar column on MySQL, if you wanted the size to be different
    than 255.
    committed Aug 19, 2008
Commits on Aug 18, 2008
  1. Quote index names when creating or dropping indexes

    This also refactors some schema creation methods.  It quotes tables
    and columns as well as indexes in the schema creation methods that
    the MySQL adapter overrides.  It adds a couple new methods,
    drop_index_sql and column_references_sql, which eliminates some
    duplication in the MySQL adapter.
    committed Aug 18, 2008
Commits on Aug 16, 2008
Commits on Aug 13, 2008
  1. Don't have column accessor methods override plugin instance methods

    This commit changes where the column accessor methods are defined.
    Instead of defining them directly in the class, this defines them in
    an anonymous module that is included in the class.  Because columns
    accessors are generally defined when the class is created (before
    the plugin has been added), the plugin instance methods module will
    be included after the column accessor module, so it will take
    precedence.  Because the column accessor methods don't override
    existing instance methods, if a plugin has already been added, using
    set_dataset after a plugin has been added (e.g. in a subclass) won't
    create column accessors that override the plugin's instance methods.
    This commit should also have a minor speedup in the general case, by
    recognizing when a dataset is inherited and omitting some redundent
    code in that case.
    While here, simplify the code for Sequel::Model().
    committed Aug 13, 2008
  2. Allow validation of multiple attributes at once, with built in suppor…

    …t for uniqueness checking of multiple columns
    This commit allows you to support validating multiple attributes at
      validates_each([:column1, :column2]) do |obj, attributes, values|
        # attributes = [:column1, :column2]
        # values = [obj.send(:column1), obj.send(:column2)]
    Support was added to validates_uniqueness_of to work on multiple
    values at once:
      validates_uniqueness_of([:column1, :column2])
    This is quite different from the following code:
      validates_uniqueness_of(:column1, :column2)
    Which makes sure the each value is unique to its column, instead of
    the combination of values being unique.
    This will give a validation error message if an entry already exists
    in the database that has the same value for column1 and column2.  It
    works for any number of columns.
    validates_uniqueness_of now supports an :allow_nil option that will
    skip checking if the values of all columns are nil.  Previously, it
    automatically skipped the validation if the value was blank.
    There was also a slight memory reduction by reusing the default proc
    if :if is not specified.
    committed Aug 13, 2008
Commits on Aug 12, 2008
  1. In PostgreSQL adapter, fix inserting a row with a primary key value i…

    …nside a transaction
    This bug took quite a while to find and fix.  It was compounded by
    the fact that there were multiple bugs in the underlying
    1) Errors raised by PostgreSQL weren't getting reraised inside
    2) Determining the sequence names was not done correctly.
    This caused weird errors, such as the code raising an error stating
    there was already an error on the transaction, without showing
    an error or even that a query was issued.  To fix this and similar
    issues, have the connection log the SQL it issues to find primary
    keys, sequences, and sequence values, just like the Database object
    logs the SQL.
    To make sure that inserting a row with a primary key value works
    inside transactions, figure out the primary key first and see if
    it contained in the values hash.  If not, figure out what the
    sequence is for the table, and get the last sequence value used.
    This is done because trying to get the last sequence value first
    if the sequence wasn't yet used on the connection causes PostgreSQL
    to abort the transaction.  It would return an invalid result
    instead of aborting the transaction if the connection had previously
    been used to insert a row into the same table, without an easy way
    to detect things.
    Fix the SQL used for finding primary keys and sequences so that
    unnecessary columns aren't returned.
    Keep track of sequences at the Database level instead of the
    connection level.
    Make insert_result, primary_key_for_table, and
    primary_key_sequence_for_table private methods.
    The :table option when inserting is now unquoted (generally a symbol),
    instead of the quoted string used previously.
    committed Aug 12, 2008
Commits on Aug 11, 2008
  1. Allow :join_table association option to have a string value

    Before, using a string value would result in very weird error
    messages, because of the implementation of the many_to_many
    add_/remove_/remove_all_ methods.  Have those methods use
    database.dataset.from(join_table) instead of
    database[join_table], which should work.  The documentation will
    remain the same, and I don't guarantee that using a string will work
    in future versions.  The main reason for this commit is so if you do
    use a string, you won't get an error message that doesn't make sense.
    committed Aug 11, 2008
Commits on Aug 7, 2008
Commits on Aug 6, 2008
  1. Make Dataset#single_value work when graphing, which fixes count and p…

    …aginate on graphed datasets
    committed Aug 6, 2008
  2. Bump version to 2.4.0

    committed Aug 6, 2008
Commits on Aug 5, 2008
  1. Use boof's website design for

    Instead of just hosting the RDoc at, have an
    actual website, based on boof's design for
    However, drop the Rails project and instead create a plain html site
    generated with a simple script, a single template, and ERB.
    Also, add a fifth main feature to the README, showing off the
    improvements coming in 2.4.0.
    committed Aug 5, 2008
Commits on Aug 4, 2008
  1. Add support for read-only slave/writable master databases and databas…

    …e sharding
    The support is described in the sharding.rdoc file included with this
    commit. This commit makes significant changes to every adapter in
    order to support this new functionality.  I only have the ability to
    test PostgreSQL, MySQL, and SQLite (both via the native drivers and
    via JDBC), so it's possible I could have broken something on other
    adapters.  If you use another adapter, please test this and see if it
    breaks anything.  I try to be fairly careful whenever I change
    something I can't test, but it's always possible I made an error.
    This commit makes the following internal changes:
    * The Database and Dataset execute and execute_dui methods now take
      an options hash.  The prepared statement support was integrated
      into this hash, resulting in a simpler implementation.
    * The connection pool internals were changed significantly to allow
      connections to different servers.  The previous methods all still
      work the same way, but now take an optional server argument
      specifying which server to use.
    * Many low_level methods (transaction, test_connection, synchronize,
      tables) take an optional server argument to specify the server to
    * Some adapter database and dataset methods were made private.
    * Adapter Dataset #fetch_rows methods that used Database#synchronize
      explicitly were modified to use Dataset#execute with a block.
      Adapter Database #execute methods were modified for these adapters
      to yield inside of #synchronize.
    * Database#connect now requires a server argument.  The included
      adapters use this with the new private Database#server_opts method
      that allows overriding the default opts with the server specific
    * The JDBC and MySQL adapters were significantly refactored.
    * The PostgreSQL adapter #execute_insert now takes a hash of options
      instead of table and values arguments.
    * Adapters with specific support for named prepared statements now
      consider the use of a symbol as the first argument to execute
      to indicant the call of a prepared statement.  The
      execute_prepared_statement method in these adapters is now private.
    * Adapter execute_select statements were removed in place of execute,
      with the original use of execute changed to execute_dui.  This
      follows the convention of using execute for SELECT queries, and
      execute_dui for DELETE/UPDATE/INSERT queries.
    * Removes adapter_skeleton adapter.  The existing adapters provide
      better examples of how things should be done compared to this
      example file.
    * No longer defines model methods for non-public dataset methods
      specified in plugins.
    committed Aug 4, 2008
Commits on Jul 31, 2008
  1. Huge changes, mostly to add prepared statement/bound variable support

    This is a huge commit.  I general prefer to commit in smaller chunks,
    but this is a major feature that will have a large effect on the
    future of Sequel, and I didn't wan't to commit before I knew that
    the code was flexible enough to work on multiple database types, and
    that it didn't break existing code.
    This commit adds support for prepared statements and bound variables.
    Included is a prepared_statement.rdoc file, review that to get an
    idea of usage.  This has been tested on PostgreSQL, MySQL, and
    SQLite, both with the native drivers and with the JDBC drivers.  For
    other databases, it emulates support using interpolation.
    Along with the prepared statement support comes complete, but not
    necessarily good, documentation for the PostgreSQL, MySQL, SQLite,
    and JDBC adapters.
    There were numerous minor changes made as well:
    * MSSQL should be better supported on JDBC, though I haven't tested
    * Statement execution on JDBC and SQLite was refactored to reduce
      code duplication.
    * JDBC support for inserting records was refactored to reduce code
    * Dataset got private execute and execute_dui methods, that send the
      the SQL to the database.  The adapters that had special database
      #execute methods had similar changes to their datasets.
    * Mysql::Result#convert_type is now a private method.
    * Mysql::Result#each_array was removed, probably a leftover from the
      old arrays with keys code.
    * All databases now have a @transactions instance variable set on
      initialization, saving code inside #transaction.
    * Native support for prepared statements when using PostgreSQL can be
      determined by seeing if SEQUEL_POSTGRES_USES_PG is defined and
    * Postgres::Adapter#connected was removed.
    * #serial_primary_key_options was removed from the MySQL and SQLite
      adapters, since it was the same as the default.
    * Postgres::Database#locks was refactored.
    * Use block_given? and yield instead of block[] in some places.
    * Database#log_info takes an additional args argument, used for
      logging bound variables.
    * The InvalidExpression, InvalidFilter, InvalidJoinType, and
      WorkerStop exceptions were removed.
    * Using Model[true] and Model[false] no longer results in an error.
      This was probably more helpful with the ParseTree expression
      syntax (which used == for equality), but shouldn't be helpful now.
    * Using a full outer join on MySQL raises a generic Error instead of
    committed Jul 31, 2008
Commits on Jul 29, 2008