Permalink
Browse files

r3303@asus: jeremy | 2005-11-23 17:14:31 -0800

 Apply [3051], [3052], [3053], [3059] to stable.  Brings the Firebird adapter to 1.0.  References #1874.


git-svn-id: http://svn-commit.rubyonrails.org/rails/branches/stable@3177 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9c05146 commit 15839d56d01a1a9f60bb57314c722efcfead644d @jeremy jeremy committed Nov 24, 2005
Showing with 882 additions and 65 deletions.
  1. +1 −0 actionpack/test/controller/active_record_assertions_test.rb
  2. +2 −0 activerecord/CHANGELOG
  3. +1 −1 activerecord/Rakefile
  4. +1 −1 activerecord/lib/active_record.rb
  5. +1 −1 activerecord/lib/active_record/associations.rb
  6. +13 −6 activerecord/lib/active_record/base.rb
  7. +8 −0 activerecord/lib/active_record/connection_adapters/abstract_adapter.rb
  8. +425 −0 activerecord/lib/active_record/connection_adapters/firebird_adapter.rb
  9. +1 −1 activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb
  10. +13 −6 activerecord/lib/active_record/validations.rb
  11. +2 −0 activerecord/test/abstract_unit.rb
  12. +2 −2 activerecord/test/associations_go_eager_test.rb
  13. +6 −6 activerecord/test/associations_test.rb
  14. +3 −3 activerecord/test/base_test.rb
  15. +3 −3 activerecord/test/binary_test.rb
  16. +24 −0 activerecord/test/connections/native_firebird/connection.rb
  17. +16 −0 activerecord/test/default_test_firebird.rb
  18. +1 −1 activerecord/test/deprecated_associations_test.rb
  19. +1 −1 activerecord/test/finder_test.rb
  20. +1 −1 activerecord/test/fixtures/comment.rb
  21. +3 −1 activerecord/test/fixtures/company.rb
  22. +54 −0 activerecord/test/fixtures/db_definitions/firebird.drop.sql
  23. +259 −0 activerecord/test/fixtures/db_definitions/firebird.sql
  24. +2 −0 activerecord/test/fixtures/db_definitions/firebird2.drop.sql
  25. +6 −0 activerecord/test/fixtures/db_definitions/firebird2.sql
  26. +32 −30 activerecord/test/fixtures_test.rb
  27. +1 −1 activerecord/test/inheritance_test.rb
@@ -23,6 +23,7 @@
# Set up company fixtures.
$LOAD_PATH << "#{path_to_ar}/test"
+QUOTED_TYPE = ActiveRecord::Base.connection.quote_column_name('type') unless Object.const_defined?(:QUOTED_TYPE)
require 'fixtures/company'
File.read("#{path_to_ar}/test/fixtures/db_definitions/sqlite.sql").split(';').each do |sql|
ActiveRecord::Base.connection.execute(sql) unless sql.blank?
@@ -1,5 +1,7 @@
*SVN*
+* Introducing the Firebird adapter. Quote columns and use attribute_condition more consistently. Setup guide: http://wiki.rubyonrails.com/rails/pages/Firebird+Adapter #1874 [Ken Kunz <kennethkunz@gmail.com>]
+
* Fixed bug where using update_attribute after pushing a record to a habtm association of the object caused duplicate rows in the join table. #2888 [colman@rominato.com, Florian Weber]
* Add tasks to create, drop and rebuild the MySQL and PostgreSQL test databases. [Marcel Molina Jr.]
@@ -27,7 +27,7 @@ task :default => [ :test_mysql, :test_sqlite, :test_postgresql ]
# Run the unit tests
-for adapter in %w( mysql postgresql sqlite sqlite3 sqlserver sqlserver_odbc db2 oci )
+for adapter in %w( mysql postgresql sqlite sqlite3 firebird sqlserver sqlserver_odbc db2 oci )
Rake::TestTask.new("test_#{adapter}") { |t|
t.libs << "test" << "test/connections/native_#{adapter}"
t.pattern = "test/*_test{,_#{adapter}}.rb"
@@ -66,7 +66,7 @@
end
unless defined?(RAILS_CONNECTION_ADAPTERS)
- RAILS_CONNECTION_ADAPTERS = %w(mysql postgresql sqlite sqlserver db2 oci)
+ RAILS_CONNECTION_ADAPTERS = %w(mysql postgresql sqlite firebird sqlserver db2 oci)
end
RAILS_CONNECTION_ADAPTERS.each do |adapter|
@@ -1002,7 +1002,7 @@ def add_sti_conditions!(sql, reflections)
end
def column_aliases(schema_abbreviations)
- schema_abbreviations.collect { |cn, tc| "#{tc.join(".")} AS #{cn}" }.join(", ")
+ schema_abbreviations.collect { |cn, tc| "#{tc[0]}.#{connection.quote_column_name tc[1]} AS #{cn}" }.join(", ")
end
def association_join(reflection)
@@ -706,9 +706,11 @@ def set_inheritance_column( value=nil, &block )
# given block. This is required for Oracle and is useful for any
# database which relies on sequences for primary key generation.
#
- # Setting the sequence name when using other dbs will have no effect.
- # If a sequence name is not explicitly set when using Oracle, it will
- # default to the commonly used pattern of: #{table_name}_seq
+ # If a sequence name is not explicitly set when using Oracle or Firebird,
+ # it will default to the commonly used pattern of: #{table_name}_seq
+ #
+ # If a sequence name is not explicitly set when using PostgreSQL, it
+ # will discover the sequence corresponding to your primary key for you.
#
# Example:
#
@@ -962,8 +964,9 @@ def add_conditions!(sql, conditions)
end
def type_condition
- type_condition = subclasses.inject("#{table_name}.#{inheritance_column} = '#{name.demodulize}' ") do |condition, subclass|
- condition << "OR #{table_name}.#{inheritance_column} = '#{subclass.name.demodulize}' "
+ quoted_inheritance_column = connection.quote_column_name(inheritance_column)
+ type_condition = subclasses.inject("#{table_name}.#{quoted_inheritance_column} = '#{name.demodulize}' ") do |condition, subclass|
+ condition << "OR #{table_name}.#{quoted_inheritance_column} = '#{subclass.name.demodulize}' "
end
" (#{type_condition}) "
@@ -1017,7 +1020,7 @@ def extract_attribute_names_from_match(match)
def construct_conditions_from_arguments(attribute_names, arguments)
conditions = []
- attribute_names.each_with_index { |name, idx| conditions << "#{table_name}.#{name} #{attribute_condition(arguments[idx])} " }
+ attribute_names.each_with_index { |name, idx| conditions << "#{table_name}.#{connection.quote_column_name(name)} #{attribute_condition(arguments[idx])} " }
[ conditions.join(" AND "), *arguments[0...attribute_names.length] ]
end
@@ -1457,6 +1460,10 @@ def update
# Creates a new record with values matching those of the instance attributes.
def create
+ if self.id.nil? and connection.prefetch_primary_key?(self.class.table_name)
+ self.id = connection.next_sequence_value(self.class.sequence_name)
+ end
+
self.id = connection.insert(
"INSERT INTO #{self.class.table_name} " +
"(#{quoted_column_names.join(', ')}) " +
@@ -39,6 +39,14 @@ def supports_migrations?
false
end
+ # Should primary key values be selected from their corresponding
+ # sequence before the insert statement? If true, next_sequence_value
+ # is called before each insert to set the record's primary key.
+ # This is false for all adapters but Firebird.
+ def prefetch_primary_key?(table_name = nil)
+ false
+ end
+
def reset_runtime #:nodoc:
rt = @runtime
@runtime = 0
Oops, something went wrong.

0 comments on commit 15839d5

Please sign in to comment.