activerecord-oracle_enhanced-adapter 1.1.9 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +11 -0
- data/README.txt +6 -2
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +5 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +771 -907
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +71 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +64 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +2 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +352 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +346 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +2 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_reserved_words.rb +126 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +200 -97
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +170 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +40 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +11 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +148 -53
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +13 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +27 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +10 -6
- data/spec/spec_helper.rb +51 -6
- metadata +11 -2
@@ -0,0 +1,170 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
2
|
+
|
3
|
+
describe "OracleEnhancedConnection create connection" do
|
4
|
+
|
5
|
+
before(:all) do
|
6
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS) unless @conn.active?
|
11
|
+
end
|
12
|
+
|
13
|
+
after(:all) do
|
14
|
+
@conn.logoff if @conn.active?
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should create new connection" do
|
18
|
+
@conn.should be_active
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should ping active connection" do
|
22
|
+
@conn.ping.should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should not ping inactive connection" do
|
26
|
+
@conn.logoff
|
27
|
+
lambda { @conn.ping }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should reset active connection" do
|
31
|
+
@conn.reset!
|
32
|
+
@conn.should be_active
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be in autocommit mode after connection" do
|
36
|
+
@conn.should be_autocommit
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "OracleEnhancedConnection SQL execution" do
|
42
|
+
|
43
|
+
before(:all) do
|
44
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
45
|
+
end
|
46
|
+
|
47
|
+
before(:each) do
|
48
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS) unless @conn.active?
|
49
|
+
end
|
50
|
+
|
51
|
+
after(:all) do
|
52
|
+
@conn.logoff if @conn.active?
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should execute SQL statement" do
|
56
|
+
@conn.exec("SELECT * FROM dual").should_not be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should execute SQL select" do
|
60
|
+
@conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should execute SQL select and return also columns" do
|
64
|
+
@conn.select("SELECT * FROM dual", nil, true).should == [ [{'dummy' => 'X'}], ['dummy'] ]
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "OracleEnhancedConnection auto reconnection" do
|
70
|
+
|
71
|
+
before(:all) do
|
72
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
73
|
+
@conn = ActiveRecord::Base.connection.instance_variable_get("@connection")
|
74
|
+
@sys_conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(SYS_CONNECTION_PARAMS)
|
75
|
+
end
|
76
|
+
|
77
|
+
before(:each) do
|
78
|
+
ActiveRecord::Base.connection.reconnect! unless @conn.active?
|
79
|
+
end
|
80
|
+
|
81
|
+
after(:all) do
|
82
|
+
ActiveRecord::Base.connection.disconnect! if @conn.active?
|
83
|
+
end
|
84
|
+
|
85
|
+
def kill_current_session
|
86
|
+
audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first['audsid']
|
87
|
+
sid_serial = @sys_conn.select("SELECT s.sid||','||s.serial# sid_serial
|
88
|
+
FROM v$session s
|
89
|
+
WHERE audsid = '#{audsid}'").first['sid_serial']
|
90
|
+
@sys_conn.exec "ALTER SYSTEM KILL SESSION '#{sid_serial}' IMMEDIATE"
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should reconnect and execute SQL statement if connection is lost and auto retry is enabled" do
|
94
|
+
# @conn.auto_retry = true
|
95
|
+
ActiveRecord::Base.connection.auto_retry = true
|
96
|
+
kill_current_session
|
97
|
+
@conn.exec("SELECT * FROM dual").should_not be_nil
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not reconnect and execute SQL statement if connection is lost and auto retry is disabled" do
|
101
|
+
# @conn.auto_retry = false
|
102
|
+
ActiveRecord::Base.connection.auto_retry = false
|
103
|
+
kill_current_session
|
104
|
+
lambda { @conn.exec("SELECT * FROM dual") }.should raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should reconnect and execute SQL select if connection is lost and auto retry is enabled" do
|
108
|
+
# @conn.auto_retry = true
|
109
|
+
ActiveRecord::Base.connection.auto_retry = true
|
110
|
+
kill_current_session
|
111
|
+
@conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should not reconnect and execute SQL select if connection is lost and auto retry is disabled" do
|
115
|
+
# @conn.auto_retry = false
|
116
|
+
ActiveRecord::Base.connection.auto_retry = false
|
117
|
+
kill_current_session
|
118
|
+
lambda { @conn.select("SELECT * FROM dual") }.should raise_error
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "OracleEnhancedConnection describe table" do
|
124
|
+
|
125
|
+
before(:all) do
|
126
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
127
|
+
@owner = CONNECTION_PARAMS[:username].upcase
|
128
|
+
end
|
129
|
+
|
130
|
+
after(:all) do
|
131
|
+
@conn.logoff if @conn.active?
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should describe existing table" do
|
135
|
+
@conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
|
136
|
+
@conn.describe("test_employees").should == [@owner, "TEST_EMPLOYEES"]
|
137
|
+
@conn.exec "DROP TABLE test_employees" rescue nil
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should not describe non-existing table" do
|
141
|
+
lambda { @conn.describe("test_xxx") }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should describe table in other schema" do
|
145
|
+
@conn.describe("sys.dual").should == ["SYS", "DUAL"]
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should describe existing view" do
|
149
|
+
@conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
|
150
|
+
@conn.exec "CREATE VIEW test_employees_v AS SELECT * FROM test_employees" rescue nil
|
151
|
+
@conn.describe("test_employees_v").should == [@owner, "TEST_EMPLOYEES_V"]
|
152
|
+
@conn.exec "DROP VIEW test_employees_v" rescue nil
|
153
|
+
@conn.exec "DROP TABLE test_employees" rescue nil
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should describe view in other schema" do
|
157
|
+
@conn.describe("sys.v_$version").should == ["SYS", "V_$VERSION"]
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should describe existing private synonym" do
|
161
|
+
@conn.exec "CREATE SYNONYM test_dual FOR sys.dual" rescue nil
|
162
|
+
@conn.describe("test_dual").should == ["SYS", "DUAL"]
|
163
|
+
@conn.exec "DROP SYNONYM test_dual" rescue nil
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should describe existing public synonym" do
|
167
|
+
@conn.describe("all_tables").should == ["SYS", "ALL_TABLES"]
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
4
|
+
|
5
|
+
describe "OracleEnhancedAdapter to_d method" do
|
6
|
+
it "BigDecimal#to_d returns the same decimal number" do
|
7
|
+
d = BigDecimal.new("12345678901234567890.0123456789")
|
8
|
+
d.to_d.should == d
|
9
|
+
end
|
10
|
+
|
11
|
+
it "Bignum#to_d translates large integer to decimal" do
|
12
|
+
n = 12345678901234567890
|
13
|
+
n.to_d.should == BigDecimal.new(n.to_s)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "Fixnum#to_d translates small integer to decimal" do
|
17
|
+
n = 123456
|
18
|
+
n.to_d.should == BigDecimal.new(n.to_s)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if ENV['RAILS_GEM_VERSION'] >= '2.3'
|
23
|
+
|
24
|
+
describe "OracleEnhancedAdapter Unicode aware upcase and downcase" do
|
25
|
+
before(:all) do
|
26
|
+
@down = "āčēģīķļņšūž"
|
27
|
+
@up = "ĀČĒĢĪĶĻŅŠŪŽ"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should translate Unicode string to upcase" do
|
31
|
+
@down.mb_chars.upcase.to_s.should == @up
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should translate Unicode string to downcase" do
|
35
|
+
@up.mb_chars.downcase.to_s.should == @down
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -3,12 +3,13 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
3
3
|
describe "OracleEnhancedAdapter composite_primary_keys support" do
|
4
4
|
|
5
5
|
before(:all) do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
if defined?(ActiveRecord::ConnectionAdapters::OracleAdapter)
|
7
|
+
@old_oracle_adapter = ActiveRecord::ConnectionAdapters::OracleAdapter
|
8
|
+
ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
|
9
|
+
end
|
10
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
11
|
+
require 'composite_primary_keys'
|
12
|
+
class ::JobHistory < ActiveRecord::Base
|
12
13
|
set_table_name "job_history"
|
13
14
|
set_primary_keys :employee_id, :start_date
|
14
15
|
end
|
@@ -17,6 +18,10 @@ describe "OracleEnhancedAdapter composite_primary_keys support" do
|
|
17
18
|
after(:all) do
|
18
19
|
Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
|
19
20
|
Object.send(:remove_const, 'JobHistory') if defined?(JobHistory)
|
21
|
+
if @old_oracle_adapter
|
22
|
+
ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
|
23
|
+
ActiveRecord::ConnectionAdapters::OracleAdapter = @old_oracle_adapter
|
24
|
+
end
|
20
25
|
end
|
21
26
|
|
22
27
|
it "should tell ActiveRecord that count distinct is not supported" do
|
@@ -2,10 +2,7 @@ require File.dirname(__FILE__) + '/../../spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe "OracleEnhancedAdapter date type detection based on column names" do
|
4
4
|
before(:all) do
|
5
|
-
ActiveRecord::Base.establish_connection(
|
6
|
-
:database => "xe",
|
7
|
-
:username => "hr",
|
8
|
-
:password => "hr")
|
5
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
9
6
|
@conn = ActiveRecord::Base.connection
|
10
7
|
@conn.execute <<-SQL
|
11
8
|
CREATE TABLE test_employees (
|
@@ -82,7 +79,7 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
82
79
|
ActiveRecord::Base.connection.clear_types_for_columns
|
83
80
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
84
81
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
|
85
|
-
class TestEmployee < ActiveRecord::Base
|
82
|
+
class ::TestEmployee < ActiveRecord::Base
|
86
83
|
set_table_name "hr.test_employees"
|
87
84
|
set_primary_key :employee_id
|
88
85
|
end
|
@@ -124,7 +121,7 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
124
121
|
end
|
125
122
|
|
126
123
|
it "should return Date value from DATE column if emulate_dates_by_column_name is false but column is defined as date" do
|
127
|
-
class TestEmployee < ActiveRecord::Base
|
124
|
+
class ::TestEmployee < ActiveRecord::Base
|
128
125
|
set_date_columns :hire_date
|
129
126
|
end
|
130
127
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
@@ -133,7 +130,7 @@ describe "OracleEnhancedAdapter date type detection based on column names" do
|
|
133
130
|
end
|
134
131
|
|
135
132
|
it "should return Time value from DATE column if emulate_dates_by_column_name is true but column is defined as datetime" do
|
136
|
-
class TestEmployee < ActiveRecord::Base
|
133
|
+
class ::TestEmployee < ActiveRecord::Base
|
137
134
|
set_datetime_columns :hire_date
|
138
135
|
end
|
139
136
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = true
|
@@ -160,10 +157,7 @@ end
|
|
160
157
|
|
161
158
|
describe "OracleEnhancedAdapter integer type detection based on column names" do
|
162
159
|
before(:all) do
|
163
|
-
ActiveRecord::Base.establish_connection(
|
164
|
-
:database => "xe",
|
165
|
-
:username => "hr",
|
166
|
-
:password => "hr")
|
160
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
167
161
|
@conn = ActiveRecord::Base.connection
|
168
162
|
@conn.execute <<-SQL
|
169
163
|
CREATE TABLE test2_employees (
|
@@ -231,7 +225,7 @@ describe "OracleEnhancedAdapter integer type detection based on column names" do
|
|
231
225
|
|
232
226
|
describe "/ NUMBER values from ActiveRecord model" do
|
233
227
|
before(:each) do
|
234
|
-
class Test2Employee < ActiveRecord::Base
|
228
|
+
class ::Test2Employee < ActiveRecord::Base
|
235
229
|
end
|
236
230
|
end
|
237
231
|
|
@@ -273,10 +267,7 @@ end
|
|
273
267
|
|
274
268
|
describe "OracleEnhancedAdapter boolean type detection based on string column types and names" do
|
275
269
|
before(:all) do
|
276
|
-
ActiveRecord::Base.establish_connection(
|
277
|
-
:database => "xe",
|
278
|
-
:username => "hr",
|
279
|
-
:password => "hr")
|
270
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
280
271
|
@conn = ActiveRecord::Base.connection
|
281
272
|
@conn.execute <<-SQL
|
282
273
|
CREATE TABLE test3_employees (
|
@@ -293,9 +284,9 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
293
284
|
department_id NUMBER(4,0),
|
294
285
|
created_at DATE,
|
295
286
|
has_email CHAR(1),
|
296
|
-
has_phone VARCHAR2(1),
|
287
|
+
has_phone VARCHAR2(1) DEFAULT 'Y',
|
297
288
|
active_flag VARCHAR2(2),
|
298
|
-
manager_yn VARCHAR2(3),
|
289
|
+
manager_yn VARCHAR2(3) DEFAULT 'N',
|
299
290
|
test_boolean VARCHAR2(3)
|
300
291
|
)
|
301
292
|
SQL
|
@@ -367,11 +358,18 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
367
358
|
ActiveRecord::Base.connection.type_to_sql(
|
368
359
|
:boolean, nil, nil, nil).should == "NUMBER(1)"
|
369
360
|
end
|
361
|
+
|
362
|
+
it "should get default value from VARCHAR2 boolean column if emulate_booleans_from_strings is true" do
|
363
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
364
|
+
columns = @conn.columns('test3_employees')
|
365
|
+
columns.detect{|c| c.name == 'has_phone'}.default.should be_true
|
366
|
+
columns.detect{|c| c.name == 'manager_yn'}.default.should be_false
|
367
|
+
end
|
370
368
|
|
371
369
|
describe "/ VARCHAR2 boolean values from ActiveRecord model" do
|
372
370
|
before(:each) do
|
373
371
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = false
|
374
|
-
class Test3Employee < ActiveRecord::Base
|
372
|
+
class ::Test3Employee < ActiveRecord::Base
|
375
373
|
end
|
376
374
|
end
|
377
375
|
|
@@ -422,7 +420,7 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
422
420
|
|
423
421
|
it "should return boolean value from VARCHAR2 boolean column if column specified in set_boolean_columns" do
|
424
422
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_booleans_from_strings = true
|
425
|
-
class Test3Employee < ActiveRecord::Base
|
423
|
+
class ::Test3Employee < ActiveRecord::Base
|
426
424
|
set_boolean_columns :test_boolean
|
427
425
|
end
|
428
426
|
create_employee3(:test_boolean => true)
|
@@ -431,6 +429,12 @@ describe "OracleEnhancedAdapter boolean type detection based on string column ty
|
|
431
429
|
create_employee3(:test_boolean => false)
|
432
430
|
@employee3.test_boolean.class.should == FalseClass
|
433
431
|
@employee3.test_boolean_before_type_cast.should == "N"
|
432
|
+
create_employee3(:test_boolean => nil)
|
433
|
+
@employee3.test_boolean.class.should == NilClass
|
434
|
+
@employee3.test_boolean_before_type_cast.should == nil
|
435
|
+
create_employee3(:test_boolean => "")
|
436
|
+
@employee3.test_boolean.class.should == NilClass
|
437
|
+
@employee3.test_boolean_before_type_cast.should == nil
|
434
438
|
end
|
435
439
|
|
436
440
|
end
|
@@ -439,10 +443,7 @@ end
|
|
439
443
|
|
440
444
|
describe "OracleEnhancedAdapter timestamp with timezone support" do
|
441
445
|
before(:all) do
|
442
|
-
ActiveRecord::Base.establish_connection(
|
443
|
-
:database => "xe",
|
444
|
-
:username => "hr",
|
445
|
-
:password => "hr")
|
446
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
446
447
|
@conn = ActiveRecord::Base.connection
|
447
448
|
@conn.execute <<-SQL
|
448
449
|
CREATE TABLE test_employees (
|
@@ -481,7 +482,7 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
481
482
|
|
482
483
|
describe "/ TIMESTAMP WITH TIME ZONE values from ActiveRecord model" do
|
483
484
|
before(:all) do
|
484
|
-
class TestEmployee < ActiveRecord::Base
|
485
|
+
class ::TestEmployee < ActiveRecord::Base
|
485
486
|
set_primary_key :employee_id
|
486
487
|
end
|
487
488
|
end
|
@@ -505,18 +506,35 @@ describe "OracleEnhancedAdapter timestamp with timezone support" do
|
|
505
506
|
end
|
506
507
|
end
|
507
508
|
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
509
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
510
|
+
it "should return Time value with fractional seconds from TIMESTAMP columns" do
|
511
|
+
# currently fractional seconds are not retrieved from database
|
512
|
+
@now = Time.local(2008,5,26,23,11,11,10)
|
513
|
+
@employee = TestEmployee.create(
|
514
|
+
:created_at => @now,
|
515
|
+
:created_at_tz => @now,
|
516
|
+
:created_at_ltz => @now
|
517
|
+
)
|
518
|
+
@employee.reload
|
519
|
+
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
520
|
+
@employee.send(c).class.should == Time
|
521
|
+
@employee.send(c).to_f.should == @now.to_f
|
522
|
+
end
|
523
|
+
end
|
524
|
+
else
|
525
|
+
it "should return Time value without fractional seconds from TIMESTAMP columns" do
|
526
|
+
# currently fractional seconds are not retrieved from database
|
527
|
+
@now = Time.local(2008,5,26,23,11,11,10)
|
528
|
+
@employee = TestEmployee.create(
|
529
|
+
:created_at => @now,
|
530
|
+
:created_at_tz => @now,
|
531
|
+
:created_at_ltz => @now
|
532
|
+
)
|
533
|
+
@employee.reload
|
534
|
+
[:created_at, :created_at_tz, :created_at_ltz].each do |c|
|
535
|
+
@employee.send(c).class.should == Time
|
536
|
+
@employee.send(c).to_f.should == @now.to_f.to_i.to_f # remove fractional seconds
|
537
|
+
end
|
520
538
|
end
|
521
539
|
end
|
522
540
|
|
@@ -527,10 +545,7 @@ end
|
|
527
545
|
|
528
546
|
describe "OracleEnhancedAdapter date and timestamp with different NLS date formats" do
|
529
547
|
before(:all) do
|
530
|
-
ActiveRecord::Base.establish_connection(
|
531
|
-
:database => "xe",
|
532
|
-
:username => "hr",
|
533
|
-
:password => "hr")
|
548
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
534
549
|
@conn = ActiveRecord::Base.connection
|
535
550
|
@conn.execute <<-SQL
|
536
551
|
CREATE TABLE test_employees (
|
@@ -567,7 +582,7 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
|
|
567
582
|
before(:each) do
|
568
583
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates = false
|
569
584
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_dates_by_column_name = false
|
570
|
-
class TestEmployee < ActiveRecord::Base
|
585
|
+
class ::TestEmployee < ActiveRecord::Base
|
571
586
|
set_primary_key :employee_id
|
572
587
|
end
|
573
588
|
@today = Date.new(2008,6,28)
|
@@ -626,7 +641,7 @@ describe "OracleEnhancedAdapter date and timestamp with different NLS date forma
|
|
626
641
|
end
|
627
642
|
|
628
643
|
it "should quote Time values with TO_TIMESTAMP" do
|
629
|
-
@ts =
|
644
|
+
@ts = @now + 0.1
|
630
645
|
@conn.quote(@ts).should == "TO_TIMESTAMP('#{@ts.year}-#{"%02d" % @ts.month}-#{"%02d" % @ts.day} "+
|
631
646
|
"#{"%02d" % @ts.hour}:#{"%02d" % @ts.min}:#{"%02d" % @ts.sec}.100000','YYYY-MM-DD HH24:MI:SS.FF6')"
|
632
647
|
end
|
@@ -635,10 +650,7 @@ end
|
|
635
650
|
|
636
651
|
describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
637
652
|
before(:all) do
|
638
|
-
ActiveRecord::Base.establish_connection(
|
639
|
-
:database => "xe",
|
640
|
-
:username => "hr",
|
641
|
-
:password => "hr")
|
653
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
642
654
|
@conn = ActiveRecord::Base.connection
|
643
655
|
@conn.execute <<-SQL
|
644
656
|
CREATE TABLE test_employees (
|
@@ -654,7 +666,7 @@ describe "OracleEnhancedAdapter assign string to :date and :datetime columns" do
|
|
654
666
|
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
655
667
|
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
656
668
|
SQL
|
657
|
-
class TestEmployee < ActiveRecord::Base
|
669
|
+
class ::TestEmployee < ActiveRecord::Base
|
658
670
|
set_primary_key :employee_id
|
659
671
|
end
|
660
672
|
end
|
@@ -768,10 +780,7 @@ end
|
|
768
780
|
|
769
781
|
describe "OracleEnhancedAdapter handling of CLOB columns" do
|
770
782
|
before(:all) do
|
771
|
-
ActiveRecord::Base.establish_connection(
|
772
|
-
:database => "xe",
|
773
|
-
:username => "hr",
|
774
|
-
:password => "hr")
|
783
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
775
784
|
@conn = ActiveRecord::Base.connection
|
776
785
|
@conn.execute <<-SQL
|
777
786
|
CREATE TABLE test_employees (
|
@@ -785,7 +794,7 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
785
794
|
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
786
795
|
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
787
796
|
SQL
|
788
|
-
class TestEmployee < ActiveRecord::Base
|
797
|
+
class ::TestEmployee < ActiveRecord::Base
|
789
798
|
set_primary_key :employee_id
|
790
799
|
end
|
791
800
|
end
|
@@ -824,3 +833,89 @@ describe "OracleEnhancedAdapter handling of CLOB columns" do
|
|
824
833
|
|
825
834
|
end
|
826
835
|
|
836
|
+
describe "OracleEnhancedAdapter handling of BLOB columns" do
|
837
|
+
before(:all) do
|
838
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
839
|
+
@conn = ActiveRecord::Base.connection
|
840
|
+
@conn.execute <<-SQL
|
841
|
+
CREATE TABLE test_employees (
|
842
|
+
employee_id NUMBER(6,0),
|
843
|
+
first_name VARCHAR2(20),
|
844
|
+
last_name VARCHAR2(25),
|
845
|
+
binary_data BLOB
|
846
|
+
)
|
847
|
+
SQL
|
848
|
+
@conn.execute <<-SQL
|
849
|
+
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
850
|
+
INCREMENT BY 1 CACHE 20 NOORDER NOCYCLE
|
851
|
+
SQL
|
852
|
+
@binary_data = "\0\1\2\3\4\5\6\7\8\9"*10000
|
853
|
+
@binary_data2 = "\1\2\3\4\5\6\7\8\9\0"*10000
|
854
|
+
end
|
855
|
+
|
856
|
+
after(:all) do
|
857
|
+
@conn.execute "DROP TABLE test_employees"
|
858
|
+
@conn.execute "DROP SEQUENCE test_employees_seq"
|
859
|
+
end
|
860
|
+
|
861
|
+
before(:each) do
|
862
|
+
class ::TestEmployee < ActiveRecord::Base
|
863
|
+
set_primary_key :employee_id
|
864
|
+
end
|
865
|
+
end
|
866
|
+
|
867
|
+
after(:each) do
|
868
|
+
Object.send(:remove_const, "TestEmployee")
|
869
|
+
end
|
870
|
+
|
871
|
+
it "should create record with BLOB data" do
|
872
|
+
@employee = TestEmployee.create!(
|
873
|
+
:first_name => "First",
|
874
|
+
:last_name => "Last",
|
875
|
+
:binary_data => @binary_data
|
876
|
+
)
|
877
|
+
@employee.reload
|
878
|
+
@employee.binary_data.should == @binary_data
|
879
|
+
end
|
880
|
+
|
881
|
+
it "should update record with BLOB data" do
|
882
|
+
@employee = TestEmployee.create!(
|
883
|
+
:first_name => "First",
|
884
|
+
:last_name => "Last"
|
885
|
+
)
|
886
|
+
@employee.reload
|
887
|
+
@employee.binary_data.should be_nil
|
888
|
+
@employee.binary_data = @binary_data
|
889
|
+
@employee.save!
|
890
|
+
@employee.reload
|
891
|
+
@employee.binary_data.should == @binary_data
|
892
|
+
end
|
893
|
+
|
894
|
+
it "should update record that has existing BLOB data with different BLOB data" do
|
895
|
+
@employee = TestEmployee.create!(
|
896
|
+
:first_name => "First",
|
897
|
+
:last_name => "Last",
|
898
|
+
:binary_data => @binary_data
|
899
|
+
)
|
900
|
+
@employee.reload
|
901
|
+
@employee.binary_data = @binary_data2
|
902
|
+
@employee.save!
|
903
|
+
@employee.reload
|
904
|
+
@employee.binary_data.should == @binary_data2
|
905
|
+
end
|
906
|
+
|
907
|
+
it "should update record that has existing BLOB data with nil" do
|
908
|
+
@employee = TestEmployee.create!(
|
909
|
+
:first_name => "First",
|
910
|
+
:last_name => "Last",
|
911
|
+
:binary_data => @binary_data
|
912
|
+
)
|
913
|
+
@employee.reload
|
914
|
+
@employee.binary_data = nil
|
915
|
+
@employee.save!
|
916
|
+
@employee.reload
|
917
|
+
@employee.binary_data.should be_nil
|
918
|
+
end
|
919
|
+
|
920
|
+
end
|
921
|
+
|