From af0df03fd3bd020edbdeb00a18d11129fef1a60b Mon Sep 17 00:00:00 2001 From: Marcel Molina Date: Wed, 12 Oct 2005 23:42:54 +0000 Subject: Update DB2 adapter. Closes #2206. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2546 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/CHANGELOG | 2 ++ .../connection_adapters/db2_adapter.rb | 37 ++++++++++++++++++++-- .../test/fixtures/db_definitions/db2.drop.sql | 1 + 3 files changed, 38 insertions(+), 2 deletions(-) (limited to 'activerecord') diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index d38390110f..5f3c738b77 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Update DB2 adapter. #2206. [contact@maik-schmidt.de] + * Corrections to SQLServer native data types. #2267. [rails.20.clarry@spamgourmet.com] * Deprecated ActiveRecord::Base.threaded_connection in favor of ActiveRecord::Base.allow_concurrency. diff --git a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb index 58dd04a784..ab13494153 100644 --- a/activerecord/lib/active_record/connection_adapters/db2_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/db2_adapter.rb @@ -92,8 +92,25 @@ begin end def add_limit_offset!(sql, options) - sql << " FETCH FIRST #{options[:limit]} ROWS ONLY" if options[:limit] and !options[:limit].nil? - raise ArgumentError, 'add_limit_offset! not implemented.' if options[:offset] and !options[:offset].nil? + if options[:limit] and !options[:limit].nil? + # "FETCH FIRST 0 ROWS ONLY" is not allowed, so we have + # to use a cheap trick. + if options[:limit] == 0 + if sql =~ /WHERE/i + sql.sub!(/WHERE/i, 'WHERE 1 = 2 AND ') + elsif + sql =~ /ORDER\s+BY/i + sql.sub!(/ORDER\s+BY/i, 'WHERE 1 = 2 ORDER BY') + else + sql << 'WHERE 1 = 2' + end + else + sql << " FETCH FIRST #{options[:limit]} ROWS ONLY" + end + end + if options[:offset] and !options[:offset].nil? + raise ArgumentError, ':offset option is not yet supported!' + end end def columns(table_name, name = nil) @@ -112,6 +129,22 @@ begin result end + def native_database_types + { + :primary_key => "int generated by default as identity primary key", + :string => { :name => "varchar", :limit => 255 }, + :text => { :name => "clob", :limit => 32768 }, + :integer => { :name => "int" }, + :float => { :name => "float" }, + :datetime => { :name => "timestamp" }, + :timestamp => { :name => "timestamp" }, + :time => { :name => "time" }, + :date => { :name => "date" }, + :binary => { :name => "blob", :limit => 32768 }, + :boolean => { :name => "decimal", :limit => 1 } + } + end + private def last_insert_id diff --git a/activerecord/test/fixtures/db_definitions/db2.drop.sql b/activerecord/test/fixtures/db_definitions/db2.drop.sql index 07bffb6019..b0ff4b94c6 100644 --- a/activerecord/test/fixtures/db_definitions/db2.drop.sql +++ b/activerecord/test/fixtures/db_definitions/db2.drop.sql @@ -4,6 +4,7 @@ DROP TABLE topics; DROP TABLE developers; DROP TABLE projects; DROP TABLE developers_projects; +DROP TABLE orders; DROP TABLE customers; DROP TABLE orders; DROP TABLE movies; -- cgit v1.2.3