diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-03 21:57:03 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2006-06-03 21:57:03 +0000 |
commit | cb62f06dcf11f440d917cd4862c0786a213a5252 (patch) | |
tree | 6f74e77d11c725ba36f90f8a0934ff9d897d7325 /activerecord | |
parent | 9c0fb70e1e37242f098c0ab0c0c045f26ed9aa8d (diff) | |
download | rails-cb62f06dcf11f440d917cd4862c0786a213a5252.tar.gz rails-cb62f06dcf11f440d917cd4862c0786a213a5252.tar.bz2 rails-cb62f06dcf11f440d917cd4862c0786a213a5252.zip |
Fixed issues with BLOB limits, charsets, and booleans for Firebird (closes #5194, #5191, #5189) [kennethkunz@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4424 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord')
4 files changed, 25 insertions, 21 deletions
diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 73e6e88dfe..a04b81144e 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Fixed issues with BLOB limits, charsets, and booleans for Firebird #5194, #5191, #5189 [kennethkunz@gmail.com] + * Fixed usage of :limit and with_scope when the association in scope is a 1:m #5208 [alex@purefiction.net] * Fixed migration trouble with SQLite when NOT NULL is used in the new definition #5215 [greg@lapcominc.com] diff --git a/activerecord/lib/active_record/connection_adapters/firebird_adapter.rb b/activerecord/lib/active_record/connection_adapters/firebird_adapter.rb index b7b0736f78..da3333d003 100644 --- a/activerecord/lib/active_record/connection_adapters/firebird_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/firebird_adapter.rb @@ -4,15 +4,12 @@ require 'active_record/connection_adapters/abstract_adapter' module FireRuby # :nodoc: all class Database - def self.new_from_params(database, host, port, service) - db_string = "" - if host - db_string << host - db_string << "/#{service || port}" if service || port - db_string << ":" - end - db_string << database - new(db_string) + def self.new_from_params(database, host, port, service, charset) + host_string = [host, service, port].compact.first(2).join("/") if host + db_string = [host_string, database].join(":") + db = new(db_string) + db.character_set = charset + db end end end @@ -26,13 +23,13 @@ module ActiveRecord 'The Firebird adapter requires FireRuby version 0.4.0 or greater; you appear ' << 'to be running an older version -- please update FireRuby (gem install fireruby).' end - config = config.symbolize_keys + config.symbolize_keys! unless config.has_key?(:database) raise ArgumentError, "No database specified. Missing argument: database." end - options = config[:charset] ? { CHARACTER_SET => config[:charset] } : {} - connection_params = [config[:username], config[:password], options] - db = FireRuby::Database.new_from_params(*config.values_at(:database, :host, :port, :service)) + db_params = config.values_at(:database, :host, :port, :service, :charset) + connection_params = config.values_at(:username, :password) + db = FireRuby::Database.new_from_params(*db_params) connection = db.connect(*connection_params) ConnectionAdapters::FirebirdAdapter.new(connection, logger, connection_params) end @@ -47,7 +44,7 @@ module ActiveRecord @firebird_type = FireRuby::SQLType.to_base_type(type, sub_type).to_s super(name.downcase, nil, @firebird_type, !null_flag) @default = parse_default(default_source) if default_source - @limit = type == 'BLOB' ? BLOB_MAX_LENGTH : length + @limit = @firebird_type == 'BLOB' ? BLOB_MAX_LENGTH : length @domain, @sub_type, @precision, @scale = domain, sub_type, precision, scale end @@ -76,12 +73,8 @@ module ActiveRecord end end - def type_cast(value) - if type == :boolean - value == true or value == ActiveRecord::ConnectionAdapters::FirebirdAdapter.boolean_domain[:true] - else - super - end + def self.value_to_boolean(value) + %W(#{FirebirdAdapter.boolean_domain[:true]} true t 1).include? value.to_s.downcase end private diff --git a/activerecord/test/connection_test_firebird.rb b/activerecord/test/connection_test_firebird.rb new file mode 100644 index 0000000000..4760a46dbc --- /dev/null +++ b/activerecord/test/connection_test_firebird.rb @@ -0,0 +1,8 @@ +require 'abstract_unit' + +class ConnectionTest < Test::Unit::TestCase + def test_charset_properly_set + fb_conn = ActiveRecord::Base.connection.instance_variable_get(:@connection) + assert_equal 'UTF8', fb_conn.database.character_set + end +end diff --git a/activerecord/test/connections/native_firebird/connection.rb b/activerecord/test/connections/native_firebird/connection.rb index c861d952d3..b7d47940f7 100644 --- a/activerecord/test/connections/native_firebird/connection.rb +++ b/activerecord/test/connections/native_firebird/connection.rb @@ -12,7 +12,8 @@ ActiveRecord::Base.establish_connection( :host => "localhost", :username => "rails", :password => "rails", - :database => db1 + :database => db1, + :charset => "UTF8" ) Course.establish_connection( |