Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails4: merges commits done at master branch into rails4 branch #251

Merged
merged 23 commits into from
Nov 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e142c42
Dump indexes on virtual columns using the column's name instead of th…
unclebilly Aug 27, 2012
9a1b98c
don't update lobs that haven't changed or are attr_readonly
substars Oct 3, 2011
38e7b72
Fix broken column remove inside a change_table block.
tomasv Sep 9, 2012
c2e3ecb
Merge pull request #216 from tomasv/master
yahonda Sep 13, 2012
e726343
Merge pull request #211 from govdelivery/virt_col_index
yahonda Oct 1, 2012
101816d
Merge pull request #212 from govdelivery/lob_write_caching2
ebeigarts Oct 1, 2012
22ed405
Update README.md
ankitdhingra Oct 29, 2012
ea66792
Support dirty tracking with rails 3.2.9.rc1
ebeigarts Oct 31, 2012
df8bfe8
Merge pull request #237 from ankitdhingra/patch-1
ebeigarts Oct 31, 2012
e8820ca
Clear test database before running rake spec
ebeigarts Oct 31, 2012
8b07595
Fix pending specs on Oracle 10g
ebeigarts Oct 31, 2012
e35a4a0
Fix pending specs on Oracle 10g properly
ebeigarts Oct 31, 2012
c6ea8d9
Update History.md
ebeigarts Nov 6, 2012
c80560a
Release 1.4.2.rc1
ebeigarts Nov 13, 2012
305283a
Remove_column should raise an ArgumentError when no columns are passed
yahonda Nov 13, 2012
9b65f00
Address 2 failues since numeric_changes_from_zero_to_string? method i…
yahonda Jun 21, 2012
8d838f4
Address test_integer_zero_to_integer_zero_not_marked_as_changed failure
yahonda Aug 2, 2012
6fd6f20
Merge pull request #246 from yahonda/remove_column_should_have_columns
yahonda Nov 13, 2012
2ba2b90
Merge pull request #247 from yahonda/numeric_column_changes_v142
yahonda Nov 13, 2012
a5b4dbf
Fix rails issue 6819.
kennyj Jun 23, 2012
2781f04
Address 2 failures since c4601179541a9fc2e3cd7828335cefe54f26969a mer…
yahonda Jun 26, 2012
dd4eafa
Merge pull request #248 from yahonda/rails6819_v142
yahonda Nov 13, 2012
3ae8245
Merge branch 'master' into rails4_merges_master
yahonda Nov 20, 2012
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion History.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
### 1.4.1 / 2011-01-27
### 1.4.2.rc1 / 2012-11-13

* Enhancements:
* Wordlist option for context index [#154]
* Fall back to directly connecting via OracleDriver on JRuby [#163]
* Allow slash-prefixed database name in database.yml for using a service [#201]
* Bug fixes:
* Fixed explain plans to work with JDBC and OCI8 [#146]
* Fixed various issues with virtual columns [#159]
* Fixed SQL structure dump with function indexes [#161]
* Fixed broken column remove inside a change_table block [#216]
* Dump indexes on virtual columns using the column's name instead of the column expression [#211]
* Don't update lobs that haven't changed or are attr_readonly [#212]
* Support dirty tracking with rails 3.2.9

### 1.4.1 / 2012-01-27

* Enhancements:
* Support for Rails 3.2
Expand Down
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,6 @@ For example it can be used to force foreign key constraint on polymorphic associ
add_foreign_key :comments, :photos, :column => :subject_photo_id
add_foreign_key :comments, :events, :column => :subject_event_id

In the current adapter version it is not possible to set index on virtual column, because it is not correctly dumped to schema.rb.
This restriction will be removed in the future version.

For backward compatibility reasons it is possible to use `:default` option in the `create_table` instead of `:as` option.
But this is deprecated and may be removed in the future version.

Expand Down Expand Up @@ -344,7 +341,7 @@ Please verify that
require 'rubygems'
gem 'activerecord'
gem 'activerecord-oracle_enhanced-adapter'
require 'activerecord'
require 'active_record'
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced", :database => "database",:username => "user",:password => "password")

and see if it is successful (use your correct database, username and password)
Expand Down
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ RSpec::Core::RakeTask.new(:rcov) do |t|
t.rcov_opts = ['--exclude', '/Library,spec/']
end

desc "Clear test database"
task :clear do
require "./spec/spec_helper"
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
require "active_support/core_ext"
ActiveRecord::Base.connection.execute_structure_dump(ActiveRecord::Base.connection.full_drop)
ActiveRecord::Base.connection.execute("PURGE RECYCLEBIN") rescue nil
end

# Clear test database before running spec and rcov
task :spec => :clear
task :rcov => :clear

task :default => :spec

require 'rdoc/task'
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.1
1.4.2.rc1
4 changes: 2 additions & 2 deletions activerecord-oracle_enhanced-adapter.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

Gem::Specification.new do |s|
s.name = %q{activerecord-oracle_enhanced-adapter}
s.version = "1.4.1"
s.version = "1.4.2.rc1"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = [%q{Raimonds Simanovskis}]
s.date = %q{2012-01-27}
s.date = %q{2012-11-13}
s.description = %q{Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases.
This adapter is superset of original ActiveRecord Oracle adapter.
}
Expand Down
24 changes: 18 additions & 6 deletions lib/active_record/connection_adapters/oracle_enhanced_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -890,20 +890,20 @@ def insert_fixture(fixture, table_name) #:nodoc:

klass = klass.constantize rescue nil
if klass.respond_to?(:ancestors) && klass.ancestors.include?(ActiveRecord::Base)
write_lobs(table_name, klass, fixture)
write_lobs(table_name, klass, fixture, klass.lob_columns)
end
end

# Writes LOB values from attributes, as indicated by the LOB columns of klass.
def write_lobs(table_name, klass, attributes) #:nodoc:
# Writes LOB values from attributes for specified columns
def write_lobs(table_name, klass, attributes, columns) #:nodoc:
# is class with composite primary key>
is_with_cpk = klass.respond_to?(:composite?) && klass.composite?
if is_with_cpk
id = klass.primary_key.map {|pk| attributes[pk.to_s] }
else
id = quote(attributes[klass.primary_key])
end
klass.columns.select { |col| col.sql_type =~ /LOB$/i }.each do |col|
columns.each do |col|
value = attributes[col.name]
# changed sequence of next two lines - should check if value is nil before converting to yaml
next if value.nil? || (value == '')
Expand Down Expand Up @@ -965,11 +965,14 @@ def indexes(table_name, name = nil) #:nodoc:
SELECT LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness,
i.index_type, i.ityp_owner, i.ityp_name, i.parameters,
LOWER(i.tablespace_name) AS tablespace_name,
LOWER(c.column_name) AS column_name, e.column_expression
LOWER(c.column_name) AS column_name, e.column_expression,
atc.virtual_column
FROM all_indexes#{db_link} i
JOIN all_ind_columns#{db_link} c ON c.index_name = i.index_name AND c.index_owner = i.owner
LEFT OUTER JOIN all_ind_expressions#{db_link} e ON e.index_name = i.index_name AND
e.index_owner = i.owner AND e.column_position = c.column_position
LEFT OUTER JOIN all_tab_cols#{db_link} atc ON i.table_name = atc.table_name AND
c.column_name = atc.column_name AND i.owner = atc.owner AND atc.hidden_column = 'NO'
WHERE i.owner = '#{owner}'
AND i.table_owner = '#{owner}'
AND NOT EXISTS (SELECT uc.index_name FROM all_constraints uc
Expand Down Expand Up @@ -1004,7 +1007,16 @@ def indexes(table_name, name = nil) #:nodoc:
row['tablespace_name'] == default_tablespace_name ? nil : row['tablespace_name'], [])
current_index = row['index_name']
end
all_schema_indexes.last.columns << (row['column_expression'] || row['column_name'].downcase)

# Functional index columns and virtual columns both get stored as column expressions,
# but re-creating a virtual column index as an expression (instead of using the virtual column's name)
# results in a ORA-54018 error. Thus, we only want the column expression value returned
# when the column is not virtual.
if row['column_expression'] && row['virtual_column'] != 'YES'
all_schema_indexes.last.columns << row['column_expression']
else
all_schema_indexes.last.columns << row['column_name'].downcase
end
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def virtual?
@virtual
end

def lob?
self.sql_type =~ /LOB$/i
end

# convert something to a boolean
# added y as boolean value
def self.value_to_boolean(value) #:nodoc:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,10 @@ def _field_changed?(attr, old, value)
if ActiveRecord::Base.method_defined?(:changed?)
ActiveRecord::Base.class_eval do
include ActiveRecord::ConnectionAdapters::OracleEnhancedDirty::InstanceMethods
# Starting with rails 3.2.9 the method #field_changed?
# was renamed to #_field_changed?
if private_method_defined?(:field_changed?)
alias_method :field_changed?, :_field_changed?
end
end
end
25 changes: 19 additions & 6 deletions lib/active_record/connection_adapters/oracle_enhanced_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ def table_comment
connection.table_comment(self.table_name)
end

def lob_columns
columns.select do |column|
column.respond_to?(:lob?) && column.lob?
end
end

def virtual_columns
columns.select do |column|
column.respond_to?(:virtual?) && column.virtual?
Expand All @@ -71,16 +77,23 @@ def arel_attributes_with_values(attribute_names)

private

def record_changed_lobs
@changed_lob_columns = self.class.lob_columns.select{|col| self.send(:"#{col.name}_changed?") && !self.class.readonly_attributes.to_a.include?(col.name)}
end

# After setting large objects to empty, select the OCI8::LOB
# and write back the data.
def update
super
if connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
!(
(self.class.respond_to?(:custom_create_method) && self.class.custom_create_method) ||
(self.class.respond_to?(:custom_update_method) && self.class.custom_update_method)
)
connection.write_lobs(self.class.table_name, self.class, attributes)
!(
(self.class.respond_to?(:custom_create_method) && self.class.custom_create_method) ||
(self.class.respond_to?(:custom_update_method) && self.class.custom_update_method)
)
record_changed_lobs
super
connection.write_lobs(self.class.table_name, self.class, attributes, @changed_lob_columns || self.class.lob_columns)
else
super
end
end
end
Expand Down
Binary file added lib/ojdbc6.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -917,6 +917,14 @@ class ::TestEmployee < ActiveRecord::Base; end
class ::Test2Employee < ActiveRecord::Base
serialize :comments
end
class ::TestEmployeeReadOnlyClob < ActiveRecord::Base
if self.respond_to?(:table_name=)
self.table_name = "test_employees"
else
set_table_name = "test_employees"
end
attr_readonly :comments
end
end

after(:all) do
Expand All @@ -926,6 +934,7 @@ class ::Test2Employee < ActiveRecord::Base
@conn.execute "DROP SEQUENCE test2_employees_seq"
Object.send(:remove_const, "TestEmployee")
Object.send(:remove_const, "Test2Employee")
Object.send(:remove_const, "TestEmployeeReadOnlyClob")
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
end

Expand All @@ -944,6 +953,21 @@ class ::Test2Employee < ActiveRecord::Base
@employee.should be_valid
end

it "should respect attr_readonly setting for CLOB column" do
@employee = TestEmployeeReadOnlyClob.create!(
:first_name => "First",
:comments => "initial"
)
@employee.should be_valid
@employee.reload
@employee.comments.should == 'initial'
@employee.comments = "changed"
@employee.save.should == true
@employee.reload
@employee.comments.should == 'initial'
end


it "should create record with CLOB data" do
@employee = TestEmployee.create!(
:first_name => "First",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,24 @@ class TestEmployee < ActiveRecord::Base
@employee.should_not be_changed
end

it "should not update unchanged CLOBs" do
@employee = TestEmployee.create!(
:comments => "initial"
)
@employee.save!.should be_true
@employee.reload
@employee.comments.should == 'initial'

oci_conn = @conn.instance_variable_get('@connection')
class << oci_conn
def write_lob(lob, value, is_binary = false); raise "don't do this'"; end
end
@employee.save!.should_not raise_exception(RuntimeError, "don't do this'")
class << oci_conn
remove_method :write_lob
end
end

end

end
Original file line number Diff line number Diff line change
Expand Up @@ -347,33 +347,40 @@ def drop_test_posts_table

describe 'virtual columns' do
before(:all) do
pending "Not supported in this database version" unless @oracle11g
schema_define do
create_table :test_names, force: true do |t|
t.string :first_name
t.string :last_name
t.virtual :full_name, as: "first_name || ', ' || last_name"
t.virtual :short_name, as: "COALESCE(first_name, last_name)", type: :string, limit: 300
t.virtual :abbrev_name, as: "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", type: "VARCHAR(100)"
t.column :full_name_length, :virtual, as: "length(first_name || ', ' || last_name)", type: :integer
t.virtual :field_with_leading_space, as: "' ' || first_name || ' '", limit: 300, type: :string
if @oracle11g
schema_define do
create_table :test_names, :force => true do |t|
t.string :first_name
t.string :last_name
t.virtual :full_name, :as => "first_name || ', ' || last_name"
t.virtual :short_name, :as => "COALESCE(first_name, last_name)", :type => :string, :limit => 300
t.virtual :abbrev_name, :as => "SUBSTR(first_name,1,50) || ' ' || SUBSTR(last_name,1,1) || '.'", :type => "VARCHAR(100)"
t.column :full_name_length, :virtual, :as => "length(first_name || ', ' || last_name)", :type => :integer
t.virtual :field_with_leading_space, :as => "' ' || first_name || ' '", :limit => 300, :type => :string
end
end
else
pending "Not supported in this database version"
end
end

before(:each) do
class ::TestName < ActiveRecord::Base
if self.respond_to?(:table_name=)
self.table_name = "test_names"
else
set_table_name "test_names"
if @oracle11g
class ::TestName < ActiveRecord::Base
if self.respond_to?(:table_name=)
self.table_name = "test_names"
else
set_table_name "test_names"
end
end
end
end

after(:all) do
schema_define do
drop_table :test_names
if @oracle11g
schema_define do
drop_table :test_names
end
end
end

Expand Down Expand Up @@ -405,6 +412,27 @@ class ::TestName < ActiveRecord::Base
col.virtual_column_data_default.should_not =~ /:as/
end
end

context "with index on virtual column" do
before(:all) do
if @oracle11g
schema_define do
add_index 'test_names', 'field_with_leading_space', :name => "index_on_virtual_col"
end
end
end
after(:all) do
if @oracle11g
schema_define do
remove_index 'test_names', :name => 'index_on_virtual_col'
end
end
end
it 'should dump correctly' do
standard_dump.should_not =~ /add_index "test_names".+FIRST_NAME.+$/
standard_dump.should =~ /add_index "test_names".+field_with_leading_space.+$/
end
end
end

end
Loading