activerecord-oracle_enhanced-adapter 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of activerecord-oracle_enhanced-adapter might be problematic. Click here for more details.
data/History.txt
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
== 1.1.5 2008-07-27
|
2
|
+
|
3
|
+
* Bug fixes:
|
4
|
+
* Fixed that write_lobs callback works with partial_updates enabled (added additional record lock before writing BLOB data to database)
|
5
|
+
* Enhancements:
|
6
|
+
* Changed SQL SELECT in indexes method so that it will execute faster on some large data dictionaries
|
7
|
+
* Support for other date and time formats when assigning string to :date or :datetime column
|
8
|
+
|
1
9
|
== 1.1.4 2008-07-14
|
2
10
|
|
3
11
|
* Enhancements:
|
data/README.txt
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
Oracle "enhanced" ActiveRecord adapter contains useful additional methods for working with new and legacy Oracle databases
|
8
8
|
from Rails which are extracted from current real projects' monkey patches of original Oracle adapter.
|
9
9
|
|
10
|
-
See http://blog.rayapps.com for more information.
|
10
|
+
See http://blog.rayapps.com/category/oracle-enhanced for more information.
|
11
11
|
|
12
12
|
Look ar RSpec tests under spec directory for usage examples.
|
13
13
|
|
@@ -31,6 +31,10 @@ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_colu
|
|
31
31
|
should be emulated as booleans (and do not use NUMBER(1) as type for booleans which is default)
|
32
32
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
33
33
|
|
34
|
+
* specify other date and time formats that should be used when assigning string values to :date and :datetime columns, e.g.:
|
35
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = "%d.%m.%Y"
|
36
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = "%d.%m.%Y %H:%M:%S"
|
37
|
+
|
34
38
|
The following model class methods are available:
|
35
39
|
* specify which table columns should be ignored by ActiveRecord
|
36
40
|
ignore_table_columns :column1, :column2, :column3
|
@@ -57,6 +61,8 @@ set_delete_method do
|
|
57
61
|
)
|
58
62
|
end
|
59
63
|
|
64
|
+
Oracle enhanced adapter is also compatible with composite_primary_keys gem.
|
65
|
+
|
60
66
|
See History.txt for other enhancements to original Oracle adapter.
|
61
67
|
|
62
68
|
== REQUIREMENTS:
|
@@ -113,6 +113,32 @@ begin
|
|
113
113
|
(value.hour == 0 and value.min == 0 and value.sec == 0) ?
|
114
114
|
Date.new(value.year, value.month, value.day) : value
|
115
115
|
end
|
116
|
+
|
117
|
+
class <<self
|
118
|
+
protected
|
119
|
+
|
120
|
+
def fallback_string_to_date(string)
|
121
|
+
if OracleEnhancedAdapter.string_to_date_format || OracleEnhancedAdapter.string_to_time_format
|
122
|
+
return (string_to_date_or_time_using_format(string).to_date rescue super)
|
123
|
+
end
|
124
|
+
super
|
125
|
+
end
|
126
|
+
|
127
|
+
def fallback_string_to_time(string)
|
128
|
+
if OracleEnhancedAdapter.string_to_time_format || OracleEnhancedAdapter.string_to_date_format
|
129
|
+
return (string_to_date_or_time_using_format(string).to_time rescue super)
|
130
|
+
end
|
131
|
+
super
|
132
|
+
end
|
133
|
+
|
134
|
+
def string_to_date_or_time_using_format(string)
|
135
|
+
if OracleEnhancedAdapter.string_to_time_format && dt=Date._strptime(string, OracleEnhancedAdapter.string_to_time_format)
|
136
|
+
return Time.mktime(*dt.values_at(:year, :mon, :mday, :hour, :min, :sec, :zone, :wday))
|
137
|
+
end
|
138
|
+
DateTime.strptime(string, OracleEnhancedAdapter.string_to_date_format)
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
116
142
|
end
|
117
143
|
|
118
144
|
|
@@ -182,6 +208,10 @@ begin
|
|
182
208
|
bool ? "Y" : "N"
|
183
209
|
end
|
184
210
|
|
211
|
+
# RSI: use to set NLS specific date formats which will be used when assigning string to :date and :datetime columns
|
212
|
+
@@string_to_date_format = @@string_to_time_format = nil
|
213
|
+
cattr_accessor :string_to_date_format, :string_to_time_format
|
214
|
+
|
185
215
|
def adapter_name #:nodoc:
|
186
216
|
'OracleEnhanced'
|
187
217
|
end
|
@@ -378,9 +408,11 @@ begin
|
|
378
408
|
value = attributes[col.name]
|
379
409
|
value = value.to_yaml if col.text? && klass.serialized_attributes[col.name]
|
380
410
|
next if value.nil? || (value == '')
|
381
|
-
|
382
|
-
|
383
|
-
|
411
|
+
uncached do
|
412
|
+
lob = select_one("SELECT #{col.name} FROM #{table_name} WHERE #{klass.primary_key} = #{id} FOR UPDATE",
|
413
|
+
'Writable Large Object')[col.name]
|
414
|
+
lob.write value
|
415
|
+
end
|
384
416
|
end
|
385
417
|
end
|
386
418
|
|
@@ -403,10 +435,11 @@ begin
|
|
403
435
|
def indexes(table_name, name = nil) #:nodoc:
|
404
436
|
result = select_all(<<-SQL, name)
|
405
437
|
SELECT lower(i.index_name) as index_name, i.uniqueness, lower(c.column_name) as column_name
|
406
|
-
FROM
|
438
|
+
FROM all_indexes i, user_ind_columns c
|
407
439
|
WHERE i.table_name = '#{table_name.to_s.upcase}'
|
408
440
|
AND c.index_name = i.index_name
|
409
441
|
AND i.index_name NOT IN (SELECT uc.index_name FROM user_constraints uc WHERE uc.constraint_type = 'P')
|
442
|
+
AND i.owner = sys_context('userenv','session_user')
|
410
443
|
ORDER BY i.index_name, c.column_position
|
411
444
|
SQL
|
412
445
|
|
@@ -35,6 +35,10 @@ describe "OracleEnhancedAdapter schema dump" do
|
|
35
35
|
@new_conn.tables.should == @old_conn.tables
|
36
36
|
end
|
37
37
|
|
38
|
+
it "should return the same index list as original oracle adapter" do
|
39
|
+
@new_conn.indexes('employees').should == @old_conn.indexes('employees')
|
40
|
+
end
|
41
|
+
|
38
42
|
it "should return the same pk_and_sequence_for as original oracle adapter" do
|
39
43
|
@new_conn.tables.each do |t|
|
40
44
|
@new_conn.pk_and_sequence_for(t).should == @old_conn.pk_and_sequence_for(t)
|
@@ -98,6 +102,8 @@ describe "OracleEnhancedAdapter database session store" do
|
|
98
102
|
@session = CGI::Session::ActiveRecordStore::Session.find_by_session_id("222222")
|
99
103
|
@session.data = "other thing"
|
100
104
|
@session.save!
|
105
|
+
# second save should call again blob writing callback
|
106
|
+
@session.save!
|
101
107
|
@session = CGI::Session::ActiveRecordStore::Session.find_by_session_id("222222")
|
102
108
|
@session.data.should == "other thing"
|
103
109
|
end
|
@@ -732,3 +738,136 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
|
|
732
738
|
end
|
733
739
|
|
734
740
|
end
|
741
|
+
|
742
|
+
describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
743
|
+
before(:all) do
|
744
|
+
ActiveRecord::Base.establish_connection(:adapter => "oracle_enhanced",
|
745
|
+
:database => "xe",
|
746
|
+
:username => "hr",
|
747
|
+
:password => "hr")
|
748
|
+
@conn = ActiveRecord::Base.connection
|
749
|
+
@conn.execute <<-SQL
|
750
|
+
CREATE TABLE test_employees (
|
751
|
+
employee_id NUMBER(6,0),
|
752
|
+
first_name VARCHAR2(20),
|
753
|
+
last_name VARCHAR2(25),
|
754
|
+
hire_date DATE,
|
755
|
+
last_login_at DATE,
|
756
|
+
last_login_at_ts TIMESTAMP
|
757
|
+
)
|
758
|
+
SQL
|
759
|
+
@conn.execute <<-SQL
|
760
|
+
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
761
|
+
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
762
|
+
SQL
|
763
|
+
class TestEmployee < ActiveRecord::Base
|
764
|
+
set_primary_key :employee_id
|
765
|
+
end
|
766
|
+
end
|
767
|
+
|
768
|
+
after(:all) do
|
769
|
+
Object.send(:remove_const, "TestEmployee")
|
770
|
+
@conn.execute "DROP TABLE test_employees"
|
771
|
+
@conn.execute "DROP SEQUENCE test_employees_seq"
|
772
|
+
end
|
773
|
+
|
774
|
+
before(:each) do
|
775
|
+
@today = Date.new(2008,6,28)
|
776
|
+
@today_iso = "2008-06-28"
|
777
|
+
@today_nls = "28.06.2008"
|
778
|
+
@nls_date_format = "%d.%m.%Y"
|
779
|
+
@now = Time.local(2008,6,28,13,34,33)
|
780
|
+
@now_iso = "2008-06-28 13:34:33"
|
781
|
+
@now_nls = "28.06.2008 13:34:33"
|
782
|
+
@nls_time_format = "%d.%m.%Y %H:%M:%S"
|
783
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
784
|
+
end
|
785
|
+
|
786
|
+
it "should assign ISO string to date column" do
|
787
|
+
@employee = TestEmployee.create(
|
788
|
+
:first_name => "First",
|
789
|
+
:last_name => "Last",
|
790
|
+
:hire_date => @today_iso
|
791
|
+
)
|
792
|
+
@employee.reload
|
793
|
+
@employee.hire_date.should == @today
|
794
|
+
end
|
795
|
+
|
796
|
+
it "should assign NLS string to date column" do
|
797
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
798
|
+
@employee = TestEmployee.create(
|
799
|
+
:first_name => "First",
|
800
|
+
:last_name => "Last",
|
801
|
+
:hire_date => @today_nls
|
802
|
+
)
|
803
|
+
@employee.reload
|
804
|
+
@employee.hire_date.should == @today
|
805
|
+
end
|
806
|
+
|
807
|
+
it "should assign ISO time string to date column" do
|
808
|
+
@employee = TestEmployee.create(
|
809
|
+
:first_name => "First",
|
810
|
+
:last_name => "Last",
|
811
|
+
:hire_date => @now_iso
|
812
|
+
)
|
813
|
+
@employee.reload
|
814
|
+
@employee.hire_date.should == @today
|
815
|
+
end
|
816
|
+
|
817
|
+
it "should assign NLS time string to date column" do
|
818
|
+
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
819
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
820
|
+
@employee = TestEmployee.create(
|
821
|
+
:first_name => "First",
|
822
|
+
:last_name => "Last",
|
823
|
+
:hire_date => @now_nls
|
824
|
+
)
|
825
|
+
@employee.reload
|
826
|
+
@employee.hire_date.should == @today
|
827
|
+
end
|
828
|
+
|
829
|
+
it "should assign ISO time string to datetime column" do
|
830
|
+
@employee = TestEmployee.create(
|
831
|
+
:first_name => "First",
|
832
|
+
:last_name => "Last",
|
833
|
+
:last_login_at => @now_iso
|
834
|
+
)
|
835
|
+
@employee.reload
|
836
|
+
@employee.last_login_at.should == @now
|
837
|
+
end
|
838
|
+
|
839
|
+
it "should assign NLS time string to datetime column" do
|
840
|
+
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
841
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
842
|
+
@employee = TestEmployee.create(
|
843
|
+
:first_name => "First",
|
844
|
+
:last_name => "Last",
|
845
|
+
:last_login_at => @now_nls
|
846
|
+
)
|
847
|
+
@employee.reload
|
848
|
+
@employee.last_login_at.should == @now
|
849
|
+
end
|
850
|
+
|
851
|
+
it "should assign ISO date string to datetime column" do
|
852
|
+
@employee = TestEmployee.create(
|
853
|
+
:first_name => "First",
|
854
|
+
:last_name => "Last",
|
855
|
+
:last_login_at => @today_iso
|
856
|
+
)
|
857
|
+
@employee.reload
|
858
|
+
@employee.last_login_at.should == @today.to_time
|
859
|
+
end
|
860
|
+
|
861
|
+
it "should assign NLS date string to datetime column" do
|
862
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_date_format = @nls_date_format
|
863
|
+
# ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.string_to_time_format = @nls_time_format
|
864
|
+
@employee = TestEmployee.create(
|
865
|
+
:first_name => "First",
|
866
|
+
:last_name => "Last",
|
867
|
+
:last_login_at => @today_nls
|
868
|
+
)
|
869
|
+
@employee.reload
|
870
|
+
@employee.last_login_at.should == @today.to_time
|
871
|
+
end
|
872
|
+
|
873
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-oracle_enhanced-adapter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raimonds Simanovskis
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-07-
|
12
|
+
date: 2008-07-27 00:00:00 +03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|