Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4291

Show
Ignore:
Timestamp:
04/27/06 22:39:45 (2 years ago)
Author:
marcel
Message:

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]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r4285 r4291  
    11*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] 
    24 
    35* 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  
    6969 
    7070unless 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
    7272end 
    7373 
  • trunk/activerecord/lib/active_record/base.rb

    r4281 r4291  
    756756      end 
    757757 
    758       def quote(object) #:nodoc: 
    759         connection.quote(object
     758      def quote(value, column = nil) #:nodoc: 
     759        connection.quote(value,column
    760760      end 
    761761 
     
    948948        def find_one(id, options) 
    949949          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}" 
    951951 
    952952          if result = find_initial(options) 
     
    959959        def find_some(ids, options) 
    960960          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(',') 
    962962          options.update :conditions => "#{table_name}.#{primary_key} IN (#{ids_list})#{conditions}" 
    963963 
  • trunk/activerecord/lib/active_record/calculations.rb

    r4269 r4291  
    174174          add_conditions!(sql, options[:conditions], scope) 
    175175          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 
    178188          sql << " ORDER BY #{options[:order]} "       if options[:order] 
    179189          add_limit!(sql, options, scope) 
  • trunk/activerecord/lib/active_record/fixtures.rb

    r3896 r4291  
    393393 
    394394  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 * ', ' 
    396402  end 
    397403 
  • trunk/activerecord/Rakefile

    r4271 r4291  
    2828# Run the unit tests 
    2929 
    30 for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oracle sybase openbase
     30for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oracle sybase openbase frontbase
    3131  Rake::TestTask.new("test_#{adapter}") { |t| 
    3232    t.libs << "test" << "test/connections/native_#{adapter}" 
     
    7171desc 'Rebuild the PostgreSQL test databases' 
    7272task :rebuild_postgresql_databases => [:drop_postgresql_databases, :build_postgresql_databases] 
     73 
     74desc 'Build the FrontBase test databases' 
     75task :build_frontbase_databases => :rebuild_frontbase_databases  
     76 
     77desc 'Rebuild the FrontBase test databases' 
     78task :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] 
     111end 
    73112 
    74113# Generate the RDoc documentation 
  • trunk/activerecord/test/adapter_test.rb

    r4152 r4291  
    6767    require 'fixtures/movie' 
    6868    require 'fixtures/subscriber' 
     69     
    6970    def test_reset_empty_table_with_custom_pk 
    7071      Movie.delete_all 
     
    7374    end 
    7475 
    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 
    8284    end 
    8385  end 
  • trunk/activerecord/test/base_test.rb

    r4274 r4291  
    10951095    assert_equal res, res3 
    10961096     
    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" 
    10981098    res5 = nil 
    10991099    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", 
    11021102                        :select => "p.id") 
    11031103    end 
     
    11051105    assert_equal res4, res5  
    11061106 
    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" 
    11081108    res7 = nil 
    11091109    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", 
    11121112                        :select => "p.id", 
    11131113                        :distinct => true) 
  • trunk/activerecord/test/deprecated_finder_test.rb

    r3382 r4291  
    22require 'fixtures/company' 
    33require 'fixtures/topic' 
     4require 'fixtures/reply' 
    45require 'fixtures/entrant' 
    56require 'fixtures/developer' 
  • trunk/activerecord/test/finder_test.rb

    r3949 r4291  
    1212  def test_find 
    1313    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) 
    1420  end 
    1521   
  • trunk/activerecord/test/migration_test.rb

    r4239 r4291  
    5959      # quoting 
    6060      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) } 
    6262 
    6363      # Sybase adapter does not support indexes on :boolean columns 
     
    462462    end 
    463463 
    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 
    470482        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 
    485487    def test_migrator_with_duplicates 
    486488      assert_raises(ActiveRecord::DuplicateMigrationVersionError) do 
  • trunk/activerecord/test/pk_test.rb

    r3035 r4291  
    11require "#{File.dirname(__FILE__)}/abstract_unit" 
    22require 'fixtures/topic' 
     3require 'fixtures/reply' 
    34require 'fixtures/subscriber' 
    45require 'fixtures/movie' 
  • trunk/activerecord/test/reflection_test.rb

    r4237 r4291  
    4545    assert_equal :string, @first.column_for_attribute("title").type 
    4646    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 
    4753  end 
    4854 
  • trunk/activerecord/test/threaded_connections_test.rb

    r3862 r4291  
    22require 'fixtures/topic' 
    33 
    4 class ThreadedConnectionsTest < Test::Unit::TestCase 
    5   self.use_transactional_fixtures = false 
     4unless %w(FrontBase).include? ActiveRecord::Base.connection.adapter_name 
     5  class ThreadedConnectionsTest < Test::Unit::TestCase 
     6    self.use_transactional_fixtures = false 
    67 
    7   fixtures :topics 
     8    fixtures :topics 
    89 
    910  def setup 
     
    2627    ActiveRecord::Base.establish_connection(@connection) 
    2728     
    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 
    3345    end 
    3446  end 
    35  
    36   def test_threaded_connections 
    37     gather_connections(true) 
    38     assert_equal @connections.uniq.length, 5 
    39   end 
    40  
    41   def test_unthreaded_connections 
    42     gather_connections(false) 
    43     assert_equal @connections.uniq.length, 1 
    44   end 
    4547end 
  • trunk/activerecord/test/transactions_test.rb

    r2417 r4291  
    11require 'abstract_unit' 
    22require 'fixtures/topic' 
     3require 'fixtures/reply' 
    34require 'fixtures/developer' 
    45