Changeset 4291
- Timestamp:
- 04/27/06 22:39:45 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/base.rb (modified) (3 diffs)
- trunk/activerecord/lib/active_record/calculations.rb (modified) (1 diff)
- trunk/activerecord/lib/active_record/connection_adapters/frontbase_adapter.rb (added)
- trunk/activerecord/lib/active_record/fixtures.rb (modified) (1 diff)
- trunk/activerecord/Rakefile (modified) (2 diffs)
- trunk/activerecord/test/adapter_test.rb (modified) (2 diffs)
- trunk/activerecord/test/base_test.rb (modified) (2 diffs)
- trunk/activerecord/test/connections/native_frontbase (added)
- trunk/activerecord/test/connections/native_frontbase/connection.rb (added)
- trunk/activerecord/test/deprecated_finder_test.rb (modified) (1 diff)
- trunk/activerecord/test/finder_test.rb (modified) (1 diff)
- trunk/activerecord/test/fixtures/db_definitions/frontbase.drop.sql (added)
- trunk/activerecord/test/fixtures/db_definitions/frontbase.sql (added)
- trunk/activerecord/test/fixtures/db_definitions/frontbase2.drop.sql (added)
- trunk/activerecord/test/fixtures/db_definitions/frontbase2.sql (added)
- trunk/activerecord/test/migration_test.rb (modified) (2 diffs)
- trunk/activerecord/test/pk_test.rb (modified) (1 diff)
- trunk/activerecord/test/reflection_test.rb (modified) (1 diff)
- trunk/activerecord/test/threaded_connections_test.rb (modified) (2 diffs)
- trunk/activerecord/test/transactions_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r4285 r4291 1 1 *SVN* 2 3 * Add support for FrontBase (http://www.frontbase.com/) with a new adapter thanks to the hard work of one Mike Laster. Closes #4093. [mlaster@metavillage.com] 2 4 3 5 * Add warning about the proper way to validate the presence of a foreign key. Closes #4147. [Francois Beausoleil <francois.beausoleil@gmail.com>] trunk/activerecord/lib/active_record.rb
r3932 r4291 69 69 70 70 unless defined?(RAILS_CONNECTION_ADAPTERS) 71 RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase )71 RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase frontbase ) 72 72 end 73 73 trunk/activerecord/lib/active_record/base.rb
r4281 r4291 756 756 end 757 757 758 def quote( object) #:nodoc:759 connection.quote( object)758 def quote(value, column = nil) #:nodoc: 759 connection.quote(value,column) 760 760 end 761 761 … … 948 948 def find_one(id, options) 949 949 conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions] 950 options.update :conditions => "#{table_name}.#{primary_key} = #{ sanitize(id)}#{conditions}"950 options.update :conditions => "#{table_name}.#{primary_key} = #{quote(id,columns_hash[primary_key])}#{conditions}" 951 951 952 952 if result = find_initial(options) … … 959 959 def find_some(ids, options) 960 960 conditions = " AND (#{sanitize_sql(options[:conditions])})" if options[:conditions] 961 ids_list = ids.map { |id| sanitize(id) }.join(',')961 ids_list = ids.map { |id| quote(id,columns_hash[primary_key]) }.join(',') 962 962 options.update :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}" 963 963 trunk/activerecord/lib/active_record/calculations.rb
r4269 r4291 174 174 add_conditions!(sql, options[:conditions], scope) 175 175 add_limited_ids_condition!(sql, options, join_dependency) if join_dependency && !using_limitable_reflections?(join_dependency.reflections) && ((scope && scope[:limit]) || options[:limit]) 176 sql << " GROUP BY #{options[:group_field]} " if options[:group] 177 sql << " HAVING #{options[:having]} " if options[:group] && options[:having] 176 sql << " GROUP BY #{options[:group_alias]} " if options[:group] 177 178 if options[:group] && options[:having] 179 # FrontBase requires identifiers in the HAVING clause and chokes on function calls 180 if Base.connection.adapter_name == 'FrontBase' 181 options[:having].downcase! 182 options[:having].gsub!(/#{operation}\s*\(\s*#{column_name}\s*\)/, aggregate_alias) 183 end 184 185 sql << " HAVING #{options[:having]} " 186 end 187 178 188 sql << " ORDER BY #{options[:order]} " if options[:order] 179 189 add_limit!(sql, options, scope) trunk/activerecord/lib/active_record/fixtures.rb
r3896 r4291 393 393 394 394 def value_list 395 @fixture.values.map { |v| ActiveRecord::Base.connection.quote(v).gsub('\\n', "\n").gsub('\\r', "\r") }.join(", ") 395 klass = @class_name.constantize rescue nil 396 397 list = @fixture.inject([]) do |fixtures, (key, value)| 398 col = klass.columns_hash[key] unless klass.nil? 399 fixtures << ActiveRecord::Base.connection.quote(value, col).gsub('\\n', "\n").gsub('\\r', "\r") 400 end 401 list * ', ' 396 402 end 397 403 trunk/activerecord/Rakefile
r4271 r4291 28 28 # Run the unit tests 29 29 30 for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oracle sybase openbase )30 for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oracle sybase openbase frontbase ) 31 31 Rake::TestTask.new("test_#{adapter}") { |t| 32 32 t.libs << "test" << "test/connections/native_#{adapter}" … … 71 71 desc 'Rebuild the PostgreSQL test databases' 72 72 task :rebuild_postgresql_databases => [:drop_postgresql_databases, :build_postgresql_databases] 73 74 desc 'Build the FrontBase test databases' 75 task :build_frontbase_databases => :rebuild_frontbase_databases 76 77 desc 'Rebuild the FrontBase test databases' 78 task :rebuild_frontbase_databases do 79 build_frontbase_database = Proc.new do |db_name, sql_definition_file| 80 %( 81 STOP DATABASE #{db_name}; 82 DELETE DATABASE #{db_name}; 83 CREATE DATABASE #{db_name}; 84 85 CONNECT TO #{db_name} AS SESSION_NAME USER _SYSTEM; 86 SET COMMIT FALSE; 87 88 CREATE USER RAILS; 89 CREATE SCHEMA RAILS AUTHORIZATION RAILS; 90 COMMIT; 91 92 SET SESSION AUTHORIZATION RAILS; 93 SCRIPT '#{sql_definition_file}'; 94 95 COMMIT; 96 97 DISCONNECT ALL; 98 ) 99 end 100 create_activerecord_unittest = build_frontbase_database['activerecord_unittest', File.join(SCHEMA_PATH, 'frontbase.sql')] 101 create_activerecord_unittest2 = build_frontbase_database['activerecord_unittest2', File.join(SCHEMA_PATH, 'frontbase2.sql')] 102 execute_frontbase_sql = Proc.new do |sql| 103 system(<<-SHELL) 104 /Library/FrontBase/bin/sql92 <<-SQL 105 #{sql} 106 SQL 107 SHELL 108 end 109 execute_frontbase_sql[create_activerecord_unittest] 110 execute_frontbase_sql[create_activerecord_unittest2] 111 end 73 112 74 113 # Generate the RDoc documentation trunk/activerecord/test/adapter_test.rb
r4152 r4291 67 67 require 'fixtures/movie' 68 68 require 'fixtures/subscriber' 69 69 70 def test_reset_empty_table_with_custom_pk 70 71 Movie.delete_all … … 73 74 end 74 75 75 def test_reset_table_with_non_integer_pk 76 Subscriber.delete_all 77 Subscriber.connection.reset_pk_sequence! 'subscribers' 78 79 sub = Subscriber.new(:name => 'robert drake') 80 sub.id = 'bob drake' 81 assert_nothing_raised { sub.save! } 76 if ActiveRecord::Base.connection.adapter_name != "FrontBase" 77 def test_reset_table_with_non_integer_pk 78 Subscriber.delete_all 79 Subscriber.connection.reset_pk_sequence! 'subscribers' 80 sub = Subscriber.new(:name => 'robert drake') 81 sub.id = 'bob drake' 82 assert_nothing_raised { sub.save! } 83 end 82 84 end 83 85 end trunk/activerecord/test/base_test.rb
r4274 r4291 1095 1095 assert_equal res, res3 1096 1096 1097 res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments c WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id"1097 res4 = Post.count_by_sql "SELECT COUNT(p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id" 1098 1098 res5 = nil 1099 1099 assert_nothing_raised do 1100 res5 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=c .post_id",1101 :joins => "p, comments c ",1100 res5 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id", 1101 :joins => "p, comments co", 1102 1102 :select => "p.id") 1103 1103 end … … 1105 1105 assert_equal res4, res5 1106 1106 1107 res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments c WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=c.post_id"1107 res6 = Post.count_by_sql "SELECT COUNT(DISTINCT p.id) FROM posts p, comments co WHERE p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id" 1108 1108 res7 = nil 1109 1109 assert_nothing_raised do 1110 res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=c .post_id",1111 :joins => "p, comments c ",1110 res7 = Post.count(:conditions => "p.#{QUOTED_TYPE} = 'Post' AND p.id=co.post_id", 1111 :joins => "p, comments co", 1112 1112 :select => "p.id", 1113 1113 :distinct => true) trunk/activerecord/test/deprecated_finder_test.rb
r3382 r4291 2 2 require 'fixtures/company' 3 3 require 'fixtures/topic' 4 require 'fixtures/reply' 4 5 require 'fixtures/entrant' 5 6 require 'fixtures/developer' trunk/activerecord/test/finder_test.rb
r3949 r4291 12 12 def test_find 13 13 assert_equal(topics(:first).title, Topic.find(1).title) 14 end 15 16 # find should handle strings that come from URLs 17 # (example: Category.find(params[:id])) 18 def test_find_with_string 19 assert_equal(Topic.find(1).title,Topic.find("1").title) 14 20 end 15 21 trunk/activerecord/test/migration_test.rb
r4239 r4291 59 59 # quoting 60 60 assert_nothing_raised { Person.connection.add_index("people", ["key"], :name => "key", :unique => true) } 61 assert_nothing_raised { Person.connection.remove_index("people", :name => "key" ) }61 assert_nothing_raised { Person.connection.remove_index("people", :name => "key", :unique => true) } 62 62 63 63 # Sybase adapter does not support indexes on :boolean columns … … 462 462 end 463 463 464 def test_create_table_with_binary_column 465 Person.connection.drop_table :binary_testings rescue nil 466 467 assert_nothing_raised { 468 Person.connection.create_table :binary_testings do |t| 469 t.column "data", :binary, :default => "", :null => false 464 # FrontBase does not support default values on BLOB/CLOB columns 465 unless current_adapter?(:FrontBaseAdapter) 466 def test_create_table_with_binary_column 467 Person.connection.drop_table :binary_testings rescue nil 468 469 assert_nothing_raised { 470 Person.connection.create_table :binary_testings do |t| 471 t.column "data", :binary, :default => "", :null => false 472 end 473 } 474 475 columns = Person.connection.columns(:binary_testings) 476 data_column = columns.detect { |c| c.name == "data" } 477 478 if current_adapter?(:OracleAdapter) 479 assert_equal "empty_blob()", data_column.default 480 else 481 assert_equal "", data_column.default 470 482 end 471 } 472 473 columns = Person.connection.columns(:binary_testings) 474 data_column = columns.detect { |c| c.name == "data" } 475 476 if current_adapter?(:OracleAdapter) 477 assert_equal "empty_blob()", data_column.default 478 else 479 assert_equal "", data_column.default 480 end 481 482 Person.connection.drop_table :binary_testings rescue nil 483 end 484 483 484 Person.connection.drop_table :binary_testings rescue nil 485 end 486 end 485 487 def test_migrator_with_duplicates 486 488 assert_raises(ActiveRecord::DuplicateMigrationVersionError) do trunk/activerecord/test/pk_test.rb
r3035 r4291 1 1 require "#{File.dirname(__FILE__)}/abstract_unit" 2 2 require 'fixtures/topic' 3 require 'fixtures/reply' 3 4 require 'fixtures/subscriber' 4 5 require 'fixtures/movie' trunk/activerecord/test/reflection_test.rb
r4237 r4291 45 45 assert_equal :string, @first.column_for_attribute("title").type 46 46 assert_equal 255, @first.column_for_attribute("title").limit 47 end 48 49 def test_column_null_not_null 50 subscriber = Subscriber.find(:first) 51 assert subscriber.column_for_attribute("name").null 52 assert !subscriber.column_for_attribute("nick").null 47 53 end 48 54 trunk/activerecord/test/threaded_connections_test.rb
r3862 r4291 2 2 require 'fixtures/topic' 3 3 4 class ThreadedConnectionsTest < Test::Unit::TestCase 5 self.use_transactional_fixtures = false 4 unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name 5 class ThreadedConnectionsTest < Test::Unit::TestCase 6 self.use_transactional_fixtures = false 6 7 7 fixtures :topics8 fixtures :topics 8 9 9 10 def setup … … 26 27 ActiveRecord::Base.establish_connection(@connection) 27 28 28 5.times do 29 Thread.new do 30 Topic.find :first 31 @connections << ActiveRecord::Base.active_connections.values.first 32 end.join 29 5.times do 30 Thread.new do 31 Topic.find :first 32 @connections << ActiveRecord::Base.active_connections.values.first 33 end.join 34 end 35 end 36 37 def test_threaded_connections 38 gather_connections(true) 39 assert_equal @connections.uniq.length, 5 40 end 41 42 def test_unthreaded_connections 43 gather_connections(false) 44 assert_equal @connections.uniq.length, 1 33 45 end 34 46 end 35 36 def test_threaded_connections37 gather_connections(true)38 assert_equal @connections.uniq.length, 539 end40 41 def test_unthreaded_connections42 gather_connections(false)43 assert_equal @connections.uniq.length, 144 end45 47 end trunk/activerecord/test/transactions_test.rb
r2417 r4291 1 1 require 'abstract_unit' 2 2 require 'fixtures/topic' 3 require 'fixtures/reply' 3 4 require 'fixtures/developer' 4 5