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.
Files changed (35) hide show
  1. data/.rspec +2 -0
  2. data/Gemfile +35 -30
  3. data/History.txt +14 -0
  4. data/License.txt +1 -1
  5. data/README.rdoc +4 -1
  6. data/RUNNING_TESTS.rdoc +1 -1
  7. data/Rakefile +24 -26
  8. data/VERSION +1 -1
  9. data/activerecord-oracle_enhanced-adapter.gemspec +95 -68
  10. data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +7 -3
  11. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +147 -18
  12. data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +31 -15
  13. data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +0 -2
  14. data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +146 -51
  15. data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +57 -18
  16. data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +7 -1
  17. data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +6 -1
  18. data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +6 -9
  19. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +63 -3
  20. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +232 -151
  21. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +5 -3
  22. data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +1 -2
  23. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +1 -1
  24. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +61 -1
  25. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +1 -1
  26. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +1 -1
  27. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -1
  28. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +1 -1
  29. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +10 -1
  30. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +49 -4
  31. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +1 -1
  32. data/spec/spec_helper.rb +7 -17
  33. metadata +160 -16
  34. data/.gitignore +0 -11
  35. 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
- class_inheritable_accessor :custom_create_method, :custom_update_method, :custom_delete_method
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
- # add foreign keys if table has them
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] || index_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
- @logger.warn("Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{index_name_length} characters. Skipping.") if @logger
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
- @logger.warn("Index name '#{index_name}' on table '#{table_name}' already exists. Skipping.") if @logger
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
- @logger.warn("Index name '#{index_name}' on table '#{table_name}' does not exist. Skipping.") if @logger
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 ? true : false
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 File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
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 File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
1
+ require 'spec_helper'
2
2
 
3
- describe "OracleEnhancedConnection create connection" do
3
+ describe "OracleEnhancedConnection" do
4
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
5
+ describe "create connection" do
6
+ before(:all) do
7
+ @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
8
+ end
12
9
 
13
- after(:all) do
14
- @conn.logoff if @conn.active?
15
- end
10
+ before(:each) do
11
+ @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS) unless @conn.active?
12
+ end
16
13
 
17
- it "should create new connection" do
18
- @conn.should be_active
19
- end
14
+ it "should create new connection" do
15
+ @conn.should be_active
16
+ end
20
17
 
21
- it "should ping active connection" do
22
- @conn.ping.should be_true
23
- end
18
+ it "should ping active connection" do
19
+ @conn.ping.should be_true
20
+ end
24
21
 
25
- it "should not ping inactive connection" do
26
- @conn.logoff
27
- lambda { @conn.ping }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
28
- end
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
- it "should reset active connection" do
31
- @conn.reset!
32
- @conn.should be_active
33
- end
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
- end
38
+ describe "create connection with NLS parameters" do
39
+ after do
40
+ ENV['NLS_DATE_FORMAT'] = nil
41
+ end
40
42
 
41
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
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
- describe "OracleEnhancedConnection create JDBC connection" do
44
- after(:each) do
45
- @conn.logoff if @conn.active?
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 create new connection using :url" do
49
- params = CONNECTION_PARAMS.dup
50
- params[:url] = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
51
- params[:host] = nil
52
- params[:database] = nil
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
- it "should create new connection using :url and tnsnames alias" do
63
+ describe "with non-string parameters" do
64
+ before(:all) do
58
65
  params = CONNECTION_PARAMS.dup
59
- params[:url] = "jdbc:oracle:thin:@#{DATABASE_NAME}"
60
- params[:host] = nil
61
- params[:database] = nil
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 using just tnsnames alias" do
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
- end
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
- describe "OracleEnhancedConnection SQL execution" do
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
- after(:all) do
88
- @conn.logoff if @conn.active?
89
- end
148
+ describe "SQL execution" do
149
+ before(:all) do
150
+ @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
151
+ end
90
152
 
91
- it "should execute SQL statement" do
92
- @conn.exec("SELECT * FROM dual").should_not be_nil
93
- end
153
+ it "should execute SQL statement" do
154
+ @conn.exec("SELECT * FROM dual").should_not be_nil
155
+ end
94
156
 
95
- it "should execute SQL select" do
96
- @conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
97
- end
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
- end
167
+ describe "SQL with bind parameters" do
168
+ before(:all) do
169
+ @conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
170
+ end
104
171
 
105
- describe "OracleEnhancedConnection auto reconnection" do
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
- before(:all) do
108
- ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
109
- @conn = ActiveRecord::Base.connection.instance_variable_get("@connection")
110
- @sys_conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(SYS_CONNECTION_PARAMS)
111
- end
112
-
113
- before(:each) do
114
- ActiveRecord::Base.connection.reconnect! unless @conn.active?
115
- end
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
- def kill_current_session
122
- audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first['audsid']
123
- sid_serial = @sys_conn.select("SELECT s.sid||','||s.serial# sid_serial
124
- FROM v$session s
125
- WHERE audsid = '#{audsid}'").first['sid_serial']
126
- @sys_conn.exec "ALTER SYSTEM KILL SESSION '#{sid_serial}' IMMEDIATE"
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
- it "should reconnect and execute SQL statement if connection is lost and auto retry is enabled" do
130
- # @conn.auto_retry = true
131
- ActiveRecord::Base.connection.auto_retry = true
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
- it "should not reconnect and execute SQL statement if connection is lost and auto retry is disabled" do
137
- # @conn.auto_retry = false
138
- ActiveRecord::Base.connection.auto_retry = false
139
- kill_current_session
140
- lambda { @conn.exec("SELECT * FROM dual") }.should raise_error
141
- end
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
- it "should reconnect and execute SQL select if connection is lost and auto retry is enabled" do
144
- # @conn.auto_retry = true
145
- ActiveRecord::Base.connection.auto_retry = true
146
- kill_current_session
147
- @conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
148
- end
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
- it "should not reconnect and execute SQL select if connection is lost and auto retry is disabled" do
151
- # @conn.auto_retry = false
152
- ActiveRecord::Base.connection.auto_retry = false
153
- kill_current_session
154
- lambda { @conn.select("SELECT * FROM dual") }.should raise_error
155
- end
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
- end
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
- describe "OracleEnhancedConnection describe table" do
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
- it "should describe existing table" do
171
- @conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
172
- @conn.describe("test_employees").should == [@owner, "TEST_EMPLOYEES"]
173
- @conn.exec "DROP TABLE test_employees" rescue nil
174
- end
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
- it "should not describe non-existing table" do
177
- lambda { @conn.describe("test_xxx") }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
178
- end
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
- it "should describe table in other schema" do
181
- @conn.describe("sys.dual").should == ["SYS", "DUAL"]
182
- end
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
- it "should describe existing view" do
185
- @conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
186
- @conn.exec "CREATE VIEW test_employees_v AS SELECT * FROM test_employees" rescue nil
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
- it "should describe view in other schema" do
193
- @conn.describe("sys.v_$version").should == ["SYS", "V_$VERSION"]
194
- end
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
- it "should describe existing private synonym" do
197
- @conn.exec "CREATE SYNONYM test_dual FOR sys.dual" rescue nil
198
- @conn.describe("test_dual").should == ["SYS", "DUAL"]
199
- @conn.exec "DROP SYNONYM test_dual" rescue nil
200
- end
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