Skip to content

Commit

Permalink
Fixed incompatibility in DB2 adapter with the new limit/offset approach
Browse files Browse the repository at this point in the history
#1718 [Maik Schmidt]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1850 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Jul 17, 2005
1 parent bb62568 commit 9870396
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 11 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* Fixed incompatibility in DB2 adapter with the new limit/offset approach #1718 [Maik Schmidt]

* Added :select option to find which can specify a different value than the default *, like find(:all, :select => "first_name, last_name"), if you either only want to select part of the columns or exclude columns otherwise included from a join #1338 [Stefan Kaes]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,15 @@ def insert_record(record)
when @association_foreign_key
attributes[column.name] = record.quoted_id
else
value = record[column.name]
value = @owner.send(:quote, record[column.name], column)
attributes[column.name] = value unless value.nil?
end
attributes
end

sql =
"INSERT INTO #{@join_table} (#{@owner.send(:quoted_column_names, attributes).join(', ')}) " +
"VALUES (#{attributes.values.collect { |value| @owner.send(:quote, value) }.join(', ')})"
"VALUES (#{attributes.values.join(', ')})"

@owner.connection.execute(sql)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,8 @@ def quote(value, column = nil)
when String
if column && column.type == :binary
"'#{quote_string(column.string_to_binary(value))}'" # ' (for ruby-mode)
elsif column && [:integer, :float].include?(column.type)
value.to_s
else
"'#{quote_string(value)}'" # ' (for ruby-mode)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def self.db2_connection(config) # :nodoc:
end

module ConnectionAdapters
# The DB2 adapter works with the C-based CLI driver (http://raa.ruby-lang.org/project/ruby-db2/).
# The DB2 adapter works with the C-based CLI driver (http://rubyforge.org/projects/ruby-dbi/)
#
# Options:
#
Expand Down Expand Up @@ -91,12 +91,9 @@ def quote_string(string)
string.gsub(/'/, "''") # ' (for ruby-mode)
end

def add_limit_with_offset!(sql, limit, offset)
raise ArgumentError, 'add_limit_with_offset! not implemented'
end

def add_limit_without_offset!(sql, limit)
sql << " FETCH FIRST #{limit} ROWS ONLY"
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?
end

def columns(table_name, name = nil)
Expand Down Expand Up @@ -128,7 +125,7 @@ def select(sql, name = nil)
stmt = nil
log(sql, name) do
stmt = DB2::Statement.new(@connection)
stmt.exec_direct("#{sql} with ur")
stmt.exec_direct("#{sql.gsub(/=\s*null/i, 'IS NULL')} with ur")
end

rows = []
Expand Down
2 changes: 1 addition & 1 deletion activerecord/test/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_update_all
end

def test_update_many
topic_data = { "1" => { "content" => "1 updated" }, "2" => { "content" => "2 updated" } }
topic_data = { 1 => { "content" => "1 updated" }, 2 => { "content" => "2 updated" } }
updated = Topic.update(topic_data.keys, topic_data.values)

assert_equal 2, updated.size
Expand Down
2 changes: 2 additions & 0 deletions activerecord/test/fixtures/db_definitions/db2.drop.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,6 @@ DROP TABLE authors;
DROP TABLE tasks;
DROP TABLE categories;
DROP TABLE categories_posts;
DROP TABLE fk_test_has_pk;
DROP TABLE fk_test_has_fk;

0 comments on commit 9870396

Please sign in to comment.