activerecord-oracle_enhanced-adapter 1.3.1 → 1.3.2
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.
- data/.rspec +2 -0
- data/Gemfile +35 -30
- data/History.txt +14 -0
- data/License.txt +1 -1
- data/README.rdoc +4 -1
- data/RUNNING_TESTS.rdoc +1 -1
- data/Rakefile +24 -26
- data/VERSION +1 -1
- data/activerecord-oracle_enhanced-adapter.gemspec +95 -68
- data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +7 -3
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +147 -18
- data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +31 -15
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +0 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +146 -51
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +57 -18
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +7 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +6 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +6 -9
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +63 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +232 -151
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +5 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +1 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +61 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +10 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +49 -4
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +1 -1
- data/spec/spec_helper.rb +7 -17
- metadata +160 -16
- data/.gitignore +0 -11
- data/spec/spec.opts +0 -6
@@ -1,7 +1,11 @@
|
|
1
1
|
# define accessors before requiring ruby-plsql as these accessors are used in clob writing callback and should be
|
2
2
|
# available also if ruby-plsql could not be loaded
|
3
3
|
ActiveRecord::Base.class_eval do
|
4
|
-
|
4
|
+
if respond_to? :class_inheritable_accessor
|
5
|
+
class_inheritable_accessor :custom_create_method, :custom_update_method, :custom_delete_method
|
6
|
+
elsif respond_to? :class_attribute
|
7
|
+
class_attribute :custom_create_method, :custom_update_method, :custom_delete_method
|
8
|
+
end
|
5
9
|
end
|
6
10
|
|
7
11
|
require 'active_support'
|
@@ -153,6 +157,8 @@ module ActiveRecord #:nodoc:
|
|
153
157
|
self.id = instance_eval(&self.class.custom_create_method)
|
154
158
|
end
|
155
159
|
@new_record = false
|
160
|
+
# Starting from ActiveRecord 3.0.3 @persisted is used instead of @new_record
|
161
|
+
@persisted = true
|
156
162
|
id
|
157
163
|
end
|
158
164
|
|
@@ -35,9 +35,14 @@ module ActiveRecord #:nodoc:
|
|
35
35
|
oracle_enhanced_table(tbl, stream)
|
36
36
|
# add primary key trigger if table has it
|
37
37
|
primary_key_trigger(tbl, stream)
|
38
|
-
|
38
|
+
end
|
39
|
+
# following table definitions
|
40
|
+
# add foreign keys if table has them
|
41
|
+
sorted_tables.each do |tbl|
|
42
|
+
next if ignore_table? tbl
|
39
43
|
foreign_keys(tbl, stream)
|
40
44
|
end
|
45
|
+
|
41
46
|
# add synonyms in local schema
|
42
47
|
synonyms(stream)
|
43
48
|
end
|
@@ -112,19 +112,17 @@ module ActiveRecord
|
|
112
112
|
|
113
113
|
if Hash === options # legacy support, since this param was a string
|
114
114
|
index_type = options[:unique] ? "UNIQUE" : ""
|
115
|
-
index_name = options[:name]
|
115
|
+
index_name = options[:name].to_s if options.key?(:name)
|
116
116
|
tablespace = options[:tablespace] ? " TABLESPACE #{options[:tablespace]}" : ""
|
117
117
|
else
|
118
118
|
index_type = options
|
119
119
|
end
|
120
120
|
|
121
121
|
if index_name.to_s.length > index_name_length
|
122
|
-
|
123
|
-
return
|
122
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters"
|
124
123
|
end
|
125
124
|
if index_name_exists?(table_name, index_name, false)
|
126
|
-
|
127
|
-
return
|
125
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
|
128
126
|
end
|
129
127
|
quoted_column_names = column_names.map { |e| quote_column_name(e) }.join(", ")
|
130
128
|
|
@@ -138,8 +136,7 @@ module ActiveRecord
|
|
138
136
|
def remove_index(table_name, options = {}) #:nodoc:
|
139
137
|
index_name = index_name(table_name, options)
|
140
138
|
unless index_name_exists?(table_name, index_name, true)
|
141
|
-
|
142
|
-
return
|
139
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
|
143
140
|
end
|
144
141
|
remove_index!(table_name, index_name)
|
145
142
|
end
|
@@ -153,7 +150,7 @@ module ActiveRecord
|
|
153
150
|
|
154
151
|
# returned shortened index name if default is too large
|
155
152
|
def index_name(table_name, options) #:nodoc:
|
156
|
-
default_name = super(table_name, options)
|
153
|
+
default_name = super(table_name, options).to_s
|
157
154
|
# sometimes options can be String or Array with column names
|
158
155
|
options = {} unless options.is_a?(Hash)
|
159
156
|
identifier_max_length = options[:identifier_max_length] || index_name_length
|
@@ -189,7 +186,7 @@ module ActiveRecord
|
|
189
186
|
AND i.table_name = '#{table_name}'
|
190
187
|
AND i.index_name = '#{index_name.to_s.upcase}'
|
191
188
|
SQL
|
192
|
-
result == 1
|
189
|
+
result == 1
|
193
190
|
end
|
194
191
|
|
195
192
|
def add_column(table_name, column_name, type, options = {}) #:nodoc:
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "OracleEnhancedAdapter establish connection" do
|
4
4
|
|
@@ -39,11 +39,11 @@ describe "OracleEnhancedAdapter" do
|
|
39
39
|
|
40
40
|
before(:all) do
|
41
41
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
42
|
-
@conn = ActiveRecord::Base.connection
|
43
42
|
end
|
44
43
|
|
45
44
|
describe "database session store" do
|
46
45
|
before(:all) do
|
46
|
+
@conn = ActiveRecord::Base.connection
|
47
47
|
@conn.execute <<-SQL
|
48
48
|
CREATE TABLE sessions (
|
49
49
|
id NUMBER(38,0) NOT NULL,
|
@@ -111,6 +111,7 @@ describe "OracleEnhancedAdapter" do
|
|
111
111
|
|
112
112
|
describe "ignore specified table columns" do
|
113
113
|
before(:all) do
|
114
|
+
@conn = ActiveRecord::Base.connection
|
114
115
|
@conn.execute <<-SQL
|
115
116
|
CREATE TABLE test_employees (
|
116
117
|
id NUMBER PRIMARY KEY,
|
@@ -178,6 +179,7 @@ describe "OracleEnhancedAdapter" do
|
|
178
179
|
|
179
180
|
describe "cache table columns" do
|
180
181
|
before(:all) do
|
182
|
+
@conn = ActiveRecord::Base.connection
|
181
183
|
@conn.execute "DROP TABLE test_employees" rescue nil
|
182
184
|
@conn.execute <<-SQL
|
183
185
|
CREATE TABLE test_employees (
|
@@ -198,6 +200,7 @@ describe "OracleEnhancedAdapter" do
|
|
198
200
|
end
|
199
201
|
|
200
202
|
after(:all) do
|
203
|
+
@conn = ActiveRecord::Base.connection
|
201
204
|
Object.send(:remove_const, "TestEmployee")
|
202
205
|
Object.send(:remove_const, "TestEmployee2")
|
203
206
|
@conn.execute "DROP TABLE test_employees"
|
@@ -290,6 +293,7 @@ describe "OracleEnhancedAdapter" do
|
|
290
293
|
describe "without composite_primary_keys" do
|
291
294
|
|
292
295
|
before(:all) do
|
296
|
+
@conn = ActiveRecord::Base.connection
|
293
297
|
@conn.execute "DROP TABLE test_employees" rescue nil
|
294
298
|
@conn.execute <<-SQL
|
295
299
|
CREATE TABLE test_employees (
|
@@ -452,6 +456,10 @@ describe "OracleEnhancedAdapter" do
|
|
452
456
|
end
|
453
457
|
end
|
454
458
|
|
459
|
+
before(:all) do
|
460
|
+
@conn = ActiveRecord::Base.connection
|
461
|
+
end
|
462
|
+
|
455
463
|
after(:each) do
|
456
464
|
ActiveRecord::Schema.define do
|
457
465
|
suppress_messages do
|
@@ -491,6 +499,7 @@ describe "OracleEnhancedAdapter" do
|
|
491
499
|
|
492
500
|
describe "access table over database link" do
|
493
501
|
before(:all) do
|
502
|
+
@conn = ActiveRecord::Base.connection
|
494
503
|
@db_link = "db_link"
|
495
504
|
@sys_conn = ActiveRecord::Base.oracle_enhanced_connection(SYSTEM_CONNECTION_PARAMS)
|
496
505
|
@sys_conn.drop_table :test_posts rescue nil
|
@@ -537,6 +546,10 @@ describe "OracleEnhancedAdapter" do
|
|
537
546
|
end
|
538
547
|
|
539
548
|
describe "session information" do
|
549
|
+
before(:all) do
|
550
|
+
@conn = ActiveRecord::Base.connection
|
551
|
+
end
|
552
|
+
|
540
553
|
it "should get current database name" do
|
541
554
|
# get database name if using //host:port/database connection string
|
542
555
|
database_name = CONNECTION_PARAMS[:database].split('/').last
|
@@ -549,7 +562,10 @@ describe "OracleEnhancedAdapter" do
|
|
549
562
|
end
|
550
563
|
|
551
564
|
describe "temporary tables" do
|
552
|
-
|
565
|
+
before(:all) do
|
566
|
+
@conn = ActiveRecord::Base.connection
|
567
|
+
end
|
568
|
+
|
553
569
|
after(:each) do
|
554
570
|
@conn.drop_table :foos rescue nil
|
555
571
|
end
|
@@ -565,4 +581,48 @@ describe "OracleEnhancedAdapter" do
|
|
565
581
|
@conn.temporary_table?("foos").should be_true
|
566
582
|
end
|
567
583
|
end
|
584
|
+
|
585
|
+
describe "eager loading" do
|
586
|
+
before(:all) do
|
587
|
+
schema_define do
|
588
|
+
create_table :test_posts do |t|
|
589
|
+
t.string :title
|
590
|
+
end
|
591
|
+
create_table :test_comments do |t|
|
592
|
+
t.integer :test_post_id
|
593
|
+
t.string :description
|
594
|
+
end
|
595
|
+
add_index :test_comments, :test_post_id
|
596
|
+
end
|
597
|
+
class ::TestPost < ActiveRecord::Base
|
598
|
+
has_many :test_comments
|
599
|
+
end
|
600
|
+
class ::TestComment < ActiveRecord::Base
|
601
|
+
belongs_to :test_post
|
602
|
+
end
|
603
|
+
@ids = (1..1010).to_a
|
604
|
+
TestPost.transaction do
|
605
|
+
@ids.each do |id|
|
606
|
+
TestPost.create!(:id => id, :title => "Title #{id}")
|
607
|
+
TestComment.create!(:test_post_id => id, :description => "Description #{id}")
|
608
|
+
end
|
609
|
+
end
|
610
|
+
end
|
611
|
+
|
612
|
+
after(:all) do
|
613
|
+
schema_define do
|
614
|
+
drop_table :test_comments
|
615
|
+
drop_table :test_posts
|
616
|
+
end
|
617
|
+
Object.send(:remove_const, "TestPost")
|
618
|
+
Object.send(:remove_const, "TestComment")
|
619
|
+
end
|
620
|
+
|
621
|
+
it "should load included association with more than 1000 records" do
|
622
|
+
posts = TestPost.includes(:test_comments).all
|
623
|
+
posts.size.should == @ids.size
|
624
|
+
end
|
625
|
+
|
626
|
+
end if ENV['RAILS_GEM_VERSION'] >= '3.1'
|
627
|
+
|
568
628
|
end
|
@@ -1,206 +1,287 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "OracleEnhancedConnection
|
3
|
+
describe "OracleEnhancedConnection" do
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS) unless @conn.active?
|
11
|
-
end
|
5
|
+
describe "create connection" do
|
6
|
+
before(:all) do
|
7
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
8
|
+
end
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
before(:each) do
|
11
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS) unless @conn.active?
|
12
|
+
end
|
16
13
|
|
17
|
-
|
18
|
-
|
19
|
-
|
14
|
+
it "should create new connection" do
|
15
|
+
@conn.should be_active
|
16
|
+
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
it "should ping active connection" do
|
19
|
+
@conn.ping.should be_true
|
20
|
+
end
|
24
21
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
it "should not ping inactive connection" do
|
23
|
+
@conn.logoff
|
24
|
+
lambda { @conn.ping }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
27
|
+
it "should reset active connection" do
|
28
|
+
@conn.reset!
|
29
|
+
@conn.should be_active
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should be in autocommit mode after connection" do
|
33
|
+
@conn.should be_autocommit
|
34
|
+
end
|
34
35
|
|
35
|
-
it "should be in autocommit mode after connection" do
|
36
|
-
@conn.should be_autocommit
|
37
36
|
end
|
38
37
|
|
39
|
-
|
38
|
+
describe "create connection with NLS parameters" do
|
39
|
+
after do
|
40
|
+
ENV['NLS_DATE_FORMAT'] = nil
|
41
|
+
end
|
40
42
|
|
41
|
-
|
43
|
+
it "should use NLS_DATE_FORMAT environment variable" do
|
44
|
+
ENV['NLS_DATE_FORMAT'] = 'YYYY-MM-DD'
|
45
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
46
|
+
@conn.select("SELECT value FROM v$nls_parameters WHERE parameter = 'NLS_DATE_FORMAT'").should == [{'value' => 'YYYY-MM-DD'}]
|
47
|
+
end
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
@conn.
|
49
|
+
it "should use configuration value and ignore NLS_DATE_FORMAT environment variable" do
|
50
|
+
ENV['NLS_DATE_FORMAT'] = 'YYYY-MM-DD'
|
51
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS.merge(:nls_date_format => 'YYYY-MM-DD HH24:MI'))
|
52
|
+
@conn.select("SELECT value FROM v$nls_parameters WHERE parameter = 'NLS_DATE_FORMAT'").should == [{'value' => 'YYYY-MM-DD HH24:MI'}]
|
46
53
|
end
|
47
54
|
|
48
|
-
it "should
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
54
|
-
@conn.should be_active
|
55
|
+
it "should use default value when NLS_DATE_FORMAT environment variable is not set" do
|
56
|
+
ENV['NLS_DATE_FORMAT'] = nil
|
57
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
58
|
+
default = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::DEFAULT_NLS_PARAMETERS[:nls_date_format]
|
59
|
+
@conn.select("SELECT value FROM v$nls_parameters WHERE parameter = 'NLS_DATE_FORMAT'").should == [{'value' => default}]
|
55
60
|
end
|
61
|
+
end
|
56
62
|
|
57
|
-
|
63
|
+
describe "with non-string parameters" do
|
64
|
+
before(:all) do
|
58
65
|
params = CONNECTION_PARAMS.dup
|
59
|
-
params[:
|
60
|
-
params[:
|
61
|
-
params[:database] =
|
66
|
+
params[:username] = params[:username].to_sym
|
67
|
+
params[:password] = params[:password].to_sym
|
68
|
+
params[:database] = params[:database].to_sym
|
62
69
|
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
63
|
-
@conn.should be_active
|
64
70
|
end
|
65
71
|
|
66
|
-
it "should create new connection
|
67
|
-
params = CONNECTION_PARAMS.dup
|
68
|
-
params[:host] = nil
|
69
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
72
|
+
it "should create new connection" do
|
70
73
|
@conn.should be_active
|
71
74
|
end
|
72
|
-
|
73
75
|
end
|
74
76
|
|
75
|
-
|
77
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
78
|
+
|
79
|
+
describe "create JDBC connection" do
|
80
|
+
|
81
|
+
it "should create new connection using :url" do
|
82
|
+
params = CONNECTION_PARAMS.dup
|
83
|
+
params[:url] = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
|
84
|
+
params[:host] = nil
|
85
|
+
params[:database] = nil
|
86
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
87
|
+
@conn.should be_active
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should create new connection using :url and tnsnames alias" do
|
91
|
+
params = CONNECTION_PARAMS.dup
|
92
|
+
params[:url] = "jdbc:oracle:thin:@#{DATABASE_NAME}"
|
93
|
+
params[:host] = nil
|
94
|
+
params[:database] = nil
|
95
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
96
|
+
@conn.should be_active
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should create new connection using just tnsnames alias" do
|
100
|
+
params = CONNECTION_PARAMS.dup
|
101
|
+
params[:host] = nil
|
102
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
103
|
+
@conn.should be_active
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should create a new connection using JNDI" do
|
107
|
+
|
108
|
+
begin
|
109
|
+
import 'oracle.jdbc.driver.OracleDriver'
|
110
|
+
import 'org.apache.commons.pool.impl.GenericObjectPool'
|
111
|
+
import 'org.apache.commons.dbcp.PoolingDataSource'
|
112
|
+
import 'org.apache.commons.dbcp.PoolableConnectionFactory'
|
113
|
+
import 'org.apache.commons.dbcp.DriverManagerConnectionFactory'
|
114
|
+
rescue NameError => e
|
115
|
+
return pending e.message
|
116
|
+
end
|
117
|
+
|
118
|
+
class InitialContextMock
|
119
|
+
def initialize
|
120
|
+
connection_pool = GenericObjectPool.new(nil)
|
121
|
+
uri = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
|
122
|
+
connection_factory = DriverManagerConnectionFactory.new(uri, DATABASE_USER, DATABASE_PASSWORD)
|
123
|
+
poolable_connection_factory = PoolableConnectionFactory.new(connection_factory,connection_pool,nil,nil,false,true)
|
124
|
+
@data_source = PoolingDataSource.new(connection_pool)
|
125
|
+
@data_source.access_to_underlying_connection_allowed = true
|
126
|
+
end
|
127
|
+
def lookup(path)
|
128
|
+
if (path == 'java:/comp/env')
|
129
|
+
return self
|
130
|
+
else
|
131
|
+
return @data_source
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
javax.naming.InitialContext.stub!(:new).and_return(InitialContextMock.new)
|
137
|
+
|
138
|
+
params = {}
|
139
|
+
params[:jndi] = 'java:comp/env/jdbc/test'
|
140
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
141
|
+
@conn.should be_active
|
142
|
+
end
|
76
143
|
|
77
|
-
|
144
|
+
end
|
78
145
|
|
79
|
-
before(:all) do
|
80
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
81
|
-
end
|
82
|
-
|
83
|
-
before(:each) do
|
84
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS) unless @conn.active?
|
85
146
|
end
|
86
147
|
|
87
|
-
|
88
|
-
|
89
|
-
|
148
|
+
describe "SQL execution" do
|
149
|
+
before(:all) do
|
150
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
151
|
+
end
|
90
152
|
|
91
|
-
|
92
|
-
|
93
|
-
|
153
|
+
it "should execute SQL statement" do
|
154
|
+
@conn.exec("SELECT * FROM dual").should_not be_nil
|
155
|
+
end
|
94
156
|
|
95
|
-
|
96
|
-
|
97
|
-
|
157
|
+
it "should execute SQL select" do
|
158
|
+
@conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
|
159
|
+
end
|
160
|
+
|
161
|
+
it "should execute SQL select and return also columns" do
|
162
|
+
@conn.select("SELECT * FROM dual", nil, true).should == [ [{'dummy' => 'X'}], ['dummy'] ]
|
163
|
+
end
|
98
164
|
|
99
|
-
it "should execute SQL select and return also columns" do
|
100
|
-
@conn.select("SELECT * FROM dual", nil, true).should == [ [{'dummy' => 'X'}], ['dummy'] ]
|
101
165
|
end
|
102
166
|
|
103
|
-
|
167
|
+
describe "SQL with bind parameters" do
|
168
|
+
before(:all) do
|
169
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
170
|
+
end
|
104
171
|
|
105
|
-
|
172
|
+
it "should execute SQL statement with bind parameter" do
|
173
|
+
cursor = @conn.prepare("SELECT * FROM dual WHERE :1 = 1")
|
174
|
+
cursor.bind_param(1, 1)
|
175
|
+
cursor.exec
|
176
|
+
cursor.get_col_names.should == ['DUMMY']
|
177
|
+
cursor.fetch.should == ["X"]
|
178
|
+
cursor.close
|
179
|
+
end
|
106
180
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
181
|
+
it "should execute prepared statement with different bind parameters" do
|
182
|
+
cursor = @conn.prepare("SELECT * FROM dual WHERE :1 = 1")
|
183
|
+
cursor.bind_param(1, 1)
|
184
|
+
cursor.exec
|
185
|
+
cursor.fetch.should == ["X"]
|
186
|
+
cursor.bind_param(1, 0)
|
187
|
+
cursor.exec
|
188
|
+
cursor.fetch.should be_nil
|
189
|
+
cursor.close
|
190
|
+
end
|
116
191
|
|
117
|
-
after(:all) do
|
118
|
-
ActiveRecord::Base.connection.disconnect! if @conn.active?
|
119
192
|
end
|
120
193
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
end
|
194
|
+
describe "auto reconnection" do
|
195
|
+
before(:all) do
|
196
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
197
|
+
@conn = ActiveRecord::Base.connection.instance_variable_get("@connection")
|
198
|
+
@sys_conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(SYS_CONNECTION_PARAMS)
|
199
|
+
end
|
128
200
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
kill_current_session
|
133
|
-
@conn.exec("SELECT * FROM dual").should_not be_nil
|
134
|
-
end
|
201
|
+
before(:each) do
|
202
|
+
ActiveRecord::Base.connection.reconnect! unless @conn.active?
|
203
|
+
end
|
135
204
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
205
|
+
def kill_current_session
|
206
|
+
audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first['audsid']
|
207
|
+
sid_serial = @sys_conn.select("SELECT s.sid||','||s.serial# sid_serial
|
208
|
+
FROM v$session s
|
209
|
+
WHERE audsid = '#{audsid}'").first['sid_serial']
|
210
|
+
@sys_conn.exec "ALTER SYSTEM KILL SESSION '#{sid_serial}' IMMEDIATE"
|
211
|
+
end
|
142
212
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
213
|
+
it "should reconnect and execute SQL statement if connection is lost and auto retry is enabled" do
|
214
|
+
# @conn.auto_retry = true
|
215
|
+
ActiveRecord::Base.connection.auto_retry = true
|
216
|
+
kill_current_session
|
217
|
+
@conn.exec("SELECT * FROM dual").should_not be_nil
|
218
|
+
end
|
149
219
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
220
|
+
it "should not reconnect and execute SQL statement if connection is lost and auto retry is disabled" do
|
221
|
+
# @conn.auto_retry = false
|
222
|
+
ActiveRecord::Base.connection.auto_retry = false
|
223
|
+
kill_current_session
|
224
|
+
lambda { @conn.exec("SELECT * FROM dual") }.should raise_error
|
225
|
+
end
|
156
226
|
|
157
|
-
|
227
|
+
it "should reconnect and execute SQL select if connection is lost and auto retry is enabled" do
|
228
|
+
# @conn.auto_retry = true
|
229
|
+
ActiveRecord::Base.connection.auto_retry = true
|
230
|
+
kill_current_session
|
231
|
+
@conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
|
232
|
+
end
|
158
233
|
|
159
|
-
|
234
|
+
it "should not reconnect and execute SQL select if connection is lost and auto retry is disabled" do
|
235
|
+
# @conn.auto_retry = false
|
236
|
+
ActiveRecord::Base.connection.auto_retry = false
|
237
|
+
kill_current_session
|
238
|
+
lambda { @conn.select("SELECT * FROM dual") }.should raise_error
|
239
|
+
end
|
160
240
|
|
161
|
-
before(:all) do
|
162
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
163
|
-
@owner = CONNECTION_PARAMS[:username].upcase
|
164
|
-
end
|
165
|
-
|
166
|
-
after(:all) do
|
167
|
-
@conn.logoff if @conn.active?
|
168
241
|
end
|
169
242
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
243
|
+
describe "describe table" do
|
244
|
+
before(:all) do
|
245
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
246
|
+
@owner = CONNECTION_PARAMS[:username].upcase
|
247
|
+
end
|
175
248
|
|
176
|
-
|
177
|
-
|
178
|
-
|
249
|
+
it "should describe existing table" do
|
250
|
+
@conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
|
251
|
+
@conn.describe("test_employees").should == [@owner, "TEST_EMPLOYEES"]
|
252
|
+
@conn.exec "DROP TABLE test_employees" rescue nil
|
253
|
+
end
|
179
254
|
|
180
|
-
|
181
|
-
|
182
|
-
|
255
|
+
it "should not describe non-existing table" do
|
256
|
+
lambda { @conn.describe("test_xxx") }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
|
257
|
+
end
|
183
258
|
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
@conn.describe("test_employees_v").should == [@owner, "TEST_EMPLOYEES_V"]
|
188
|
-
@conn.exec "DROP VIEW test_employees_v" rescue nil
|
189
|
-
@conn.exec "DROP TABLE test_employees" rescue nil
|
190
|
-
end
|
259
|
+
it "should describe table in other schema" do
|
260
|
+
@conn.describe("sys.dual").should == ["SYS", "DUAL"]
|
261
|
+
end
|
191
262
|
|
192
|
-
|
193
|
-
|
194
|
-
|
263
|
+
it "should describe existing view" do
|
264
|
+
@conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
|
265
|
+
@conn.exec "CREATE VIEW test_employees_v AS SELECT * FROM test_employees" rescue nil
|
266
|
+
@conn.describe("test_employees_v").should == [@owner, "TEST_EMPLOYEES_V"]
|
267
|
+
@conn.exec "DROP VIEW test_employees_v" rescue nil
|
268
|
+
@conn.exec "DROP TABLE test_employees" rescue nil
|
269
|
+
end
|
195
270
|
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
271
|
+
it "should describe view in other schema" do
|
272
|
+
@conn.describe("sys.v_$version").should == ["SYS", "V_$VERSION"]
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should describe existing private synonym" do
|
276
|
+
@conn.exec "CREATE SYNONYM test_dual FOR sys.dual" rescue nil
|
277
|
+
@conn.describe("test_dual").should == ["SYS", "DUAL"]
|
278
|
+
@conn.exec "DROP SYNONYM test_dual" rescue nil
|
279
|
+
end
|
280
|
+
|
281
|
+
it "should describe existing public synonym" do
|
282
|
+
@conn.describe("all_tables").should == ["SYS", "ALL_TABLES"]
|
283
|
+
end
|
201
284
|
|
202
|
-
it "should describe existing public synonym" do
|
203
|
-
@conn.describe("all_tables").should == ["SYS", "ALL_TABLES"]
|
204
285
|
end
|
205
286
|
|
206
|
-
end
|
287
|
+
end
|