activerecord-oracle_enhanced-adapter 1.4.3 → 5.2.0
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.
- checksums.yaml +5 -5
- data/History.md +1162 -2
- data/README.md +567 -155
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +3 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +19 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +132 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +345 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +52 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +280 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +64 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +59 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +538 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +38 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +46 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +435 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +44 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +196 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +164 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +95 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +79 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +194 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +709 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +28 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +353 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +33 -0
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +3 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +385 -1083
- data/lib/active_record/type/oracle_enhanced/boolean.rb +20 -0
- data/lib/active_record/type/oracle_enhanced/integer.rb +15 -0
- data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
- data/lib/active_record/type/oracle_enhanced/national_character_string.rb +26 -0
- data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
- data/lib/active_record/type/oracle_enhanced/raw.rb +25 -0
- data/lib/active_record/type/oracle_enhanced/string.rb +29 -0
- data/lib/active_record/type/oracle_enhanced/text.rb +32 -0
- data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
- data/lib/active_record/type/oracle_enhanced/timestamptz.rb +25 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +5 -13
- data/spec/active_record/connection_adapters/{oracle_enhanced_emulate_oracle_adapter_spec.rb → emulation/oracle_adapter_spec.rb} +5 -4
- data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +469 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_context_index_spec.rb → oracle_enhanced/context_index_spec.rb} +140 -128
- data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +112 -0
- data/spec/active_record/connection_adapters/{oracle_enhanced_dbms_output_spec.rb → oracle_enhanced/dbms_output_spec.rb} +13 -13
- data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +365 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +196 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +492 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +1433 -0
- data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +478 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +385 -550
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +92 -1249
- data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
- data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +208 -0
- data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +139 -0
- data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
- data/spec/active_record/oracle_enhanced/type/integer_spec.rb +91 -0
- data/spec/active_record/oracle_enhanced/type/json_spec.rb +57 -0
- data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
- data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
- data/spec/active_record/oracle_enhanced/type/raw_spec.rb +122 -0
- data/spec/active_record/oracle_enhanced/type/text_spec.rb +229 -0
- data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +75 -0
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +100 -93
- data/spec/support/alter_system_set_open_cursors.sql +1 -0
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +105 -152
- data/.rspec +0 -2
- data/Gemfile +0 -52
- data/RUNNING_TESTS.md +0 -45
- data/Rakefile +0 -59
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -130
- data/lib/active_record/connection_adapters/oracle_enhanced.rake +0 -105
- data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
- data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -121
- data/lib/active_record/connection_adapters/oracle_enhanced_column.rb +0 -151
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +0 -119
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +0 -359
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +0 -25
- data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +0 -21
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +0 -46
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +0 -572
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +0 -497
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +0 -260
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +0 -227
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +0 -260
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +0 -428
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +0 -258
- data/lib/active_record/connection_adapters/oracle_enhanced_structure_dump.rb +0 -294
- data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +0 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +0 -334
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +0 -19
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +0 -141
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +0 -378
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +0 -440
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +0 -1400
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +0 -339
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
# Used just for Rails 2.x
|
|
2
|
-
# In Rails 3.x rake tasks are loaded using railtie
|
|
3
|
-
if ActiveRecord::VERSION::MAJOR == 2
|
|
4
|
-
|
|
5
|
-
if defined?(Rake.application) && Rake.application &&
|
|
6
|
-
ActiveRecord::Base.configurations[defined?(Rails.env) ? Rails.env : RAILS_ENV]['adapter'] == 'oracle_enhanced'
|
|
7
|
-
oracle_enhanced_rakefile = File.dirname(__FILE__) + "/oracle_enhanced.rake"
|
|
8
|
-
if Rake.application.lookup("environment")
|
|
9
|
-
# rails tasks already defined; load the override tasks now
|
|
10
|
-
load oracle_enhanced_rakefile
|
|
11
|
-
else
|
|
12
|
-
# rails tasks not loaded yet; load as an import
|
|
13
|
-
Rake.application.add_import(oracle_enhanced_rakefile)
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::VERSION = File.read(File.expand_path('../../../../VERSION', __FILE__)).chomp
|
|
@@ -1,334 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe "OracleEnhancedConnection" do
|
|
4
|
-
|
|
5
|
-
describe "create connection" do
|
|
6
|
-
before(:all) do
|
|
7
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
before(:each) do
|
|
11
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS) unless @conn.active?
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "should create new connection" do
|
|
15
|
-
@conn.should be_active
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
it "should ping active connection" do
|
|
19
|
-
@conn.ping.should be_true
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it "should not ping inactive connection" do
|
|
23
|
-
@conn.logoff
|
|
24
|
-
lambda { @conn.ping }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
|
|
25
|
-
end
|
|
26
|
-
|
|
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
|
|
35
|
-
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
describe "create connection with NLS parameters" do
|
|
39
|
-
after do
|
|
40
|
-
ENV['NLS_DATE_FORMAT'] = nil
|
|
41
|
-
end
|
|
42
|
-
|
|
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
|
|
48
|
-
|
|
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'}]
|
|
53
|
-
end
|
|
54
|
-
|
|
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}]
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
describe "with non-string parameters" do
|
|
64
|
-
before(:all) do
|
|
65
|
-
params = CONNECTION_PARAMS.dup
|
|
66
|
-
params[:username] = params[:username].to_sym
|
|
67
|
-
params[:password] = params[:password].to_sym
|
|
68
|
-
params[:database] = params[:database].to_sym
|
|
69
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
it "should create new connection" do
|
|
73
|
-
@conn.should be_active
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
describe "with slash-prefixed database name (service name)" do
|
|
78
|
-
before(:all) do
|
|
79
|
-
params = CONNECTION_PARAMS.dup
|
|
80
|
-
params[:database] = "/#{params[:database]}" unless params[:database].match(/^\//)
|
|
81
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it "should create new connection" do
|
|
85
|
-
@conn.should be_active
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
|
|
90
|
-
|
|
91
|
-
describe "create JDBC connection" do
|
|
92
|
-
|
|
93
|
-
it "should create new connection using :url" do
|
|
94
|
-
params = CONNECTION_PARAMS.dup
|
|
95
|
-
params[:url] = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
|
|
96
|
-
params[:host] = nil
|
|
97
|
-
params[:database] = nil
|
|
98
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
|
99
|
-
@conn.should be_active
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it "should create new connection using :url and tnsnames alias" do
|
|
103
|
-
params = CONNECTION_PARAMS.dup
|
|
104
|
-
params[:url] = "jdbc:oracle:thin:@#{DATABASE_NAME}"
|
|
105
|
-
params[:host] = nil
|
|
106
|
-
params[:database] = nil
|
|
107
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
|
108
|
-
@conn.should be_active
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
it "should create new connection using just tnsnames alias" do
|
|
112
|
-
params = CONNECTION_PARAMS.dup
|
|
113
|
-
params[:host] = nil
|
|
114
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
|
115
|
-
@conn.should be_active
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
it "should create a new connection using JNDI" do
|
|
119
|
-
|
|
120
|
-
begin
|
|
121
|
-
import 'oracle.jdbc.driver.OracleDriver'
|
|
122
|
-
import 'org.apache.commons.pool.impl.GenericObjectPool'
|
|
123
|
-
import 'org.apache.commons.dbcp.PoolingDataSource'
|
|
124
|
-
import 'org.apache.commons.dbcp.PoolableConnectionFactory'
|
|
125
|
-
import 'org.apache.commons.dbcp.DriverManagerConnectionFactory'
|
|
126
|
-
rescue NameError => e
|
|
127
|
-
return pending e.message
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
class InitialContextMock
|
|
131
|
-
def initialize
|
|
132
|
-
connection_pool = GenericObjectPool.new(nil)
|
|
133
|
-
uri = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
|
|
134
|
-
connection_factory = DriverManagerConnectionFactory.new(uri, DATABASE_USER, DATABASE_PASSWORD)
|
|
135
|
-
poolable_connection_factory = PoolableConnectionFactory.new(connection_factory,connection_pool,nil,nil,false,true)
|
|
136
|
-
@data_source = PoolingDataSource.new(connection_pool)
|
|
137
|
-
@data_source.access_to_underlying_connection_allowed = true
|
|
138
|
-
end
|
|
139
|
-
def lookup(path)
|
|
140
|
-
if (path == 'java:/comp/env')
|
|
141
|
-
return self
|
|
142
|
-
else
|
|
143
|
-
return @data_source
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
javax.naming.InitialContext.stub!(:new).and_return(InitialContextMock.new)
|
|
149
|
-
|
|
150
|
-
params = {}
|
|
151
|
-
params[:jndi] = 'java:comp/env/jdbc/test'
|
|
152
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
|
153
|
-
@conn.should be_active
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
end
|
|
157
|
-
|
|
158
|
-
it "should fall back to directly instantiating OracleDriver" do
|
|
159
|
-
params = CONNECTION_PARAMS.dup
|
|
160
|
-
params[:url] = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
|
|
161
|
-
params[:host] = nil
|
|
162
|
-
params[:database] = nil
|
|
163
|
-
java.sql.DriverManager.stub!(:getConnection).and_raise('no suitable driver found')
|
|
164
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
|
165
|
-
@conn.should be_active
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
end
|
|
169
|
-
|
|
170
|
-
describe "SQL execution" do
|
|
171
|
-
before(:all) do
|
|
172
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it "should execute SQL statement" do
|
|
176
|
-
@conn.exec("SELECT * FROM dual").should_not be_nil
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
it "should execute SQL select" do
|
|
180
|
-
@conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
it "should execute SQL select and return also columns" do
|
|
184
|
-
@conn.select("SELECT * FROM dual", nil, true).should == [ [{'dummy' => 'X'}], ['dummy'] ]
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
end
|
|
188
|
-
|
|
189
|
-
describe "SQL with bind parameters" do
|
|
190
|
-
before(:all) do
|
|
191
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
it "should execute SQL statement with bind parameter" do
|
|
195
|
-
cursor = @conn.prepare("SELECT * FROM dual WHERE :1 = 1")
|
|
196
|
-
cursor.bind_param(1, 1)
|
|
197
|
-
cursor.exec
|
|
198
|
-
cursor.get_col_names.should == ['DUMMY']
|
|
199
|
-
cursor.fetch.should == ["X"]
|
|
200
|
-
cursor.close
|
|
201
|
-
end
|
|
202
|
-
|
|
203
|
-
it "should execute prepared statement with different bind parameters" do
|
|
204
|
-
cursor = @conn.prepare("SELECT * FROM dual WHERE :1 = 1")
|
|
205
|
-
cursor.bind_param(1, 1)
|
|
206
|
-
cursor.exec
|
|
207
|
-
cursor.fetch.should == ["X"]
|
|
208
|
-
cursor.bind_param(1, 0)
|
|
209
|
-
cursor.exec
|
|
210
|
-
cursor.fetch.should be_nil
|
|
211
|
-
cursor.close
|
|
212
|
-
end
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
describe "SQL with bind parameters when NLS_NUMERIC_CHARACTERS is set to ', '" do
|
|
216
|
-
before(:all) do
|
|
217
|
-
ENV['NLS_NUMERIC_CHARACTERS'] = ", "
|
|
218
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
|
219
|
-
@conn.exec "CREATE TABLE test_employees (age NUMBER(10,2))"
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
after(:all) do
|
|
223
|
-
ENV['NLS_NUMERIC_CHARACTERS'] = nil
|
|
224
|
-
@conn.exec "DROP TABLE test_employees" rescue nil
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
it "should execute prepared statement with decimal bind parameter " do
|
|
228
|
-
cursor = @conn.prepare("INSERT INTO test_employees VALUES(:1)")
|
|
229
|
-
column = ActiveRecord::ConnectionAdapters::OracleEnhancedColumn.new('age', nil, 'NUMBER(10,2)')
|
|
230
|
-
column.type.should == :decimal
|
|
231
|
-
cursor.bind_param(1, "1.5", column)
|
|
232
|
-
cursor.exec
|
|
233
|
-
cursor.close
|
|
234
|
-
cursor = @conn.prepare("SELECT age FROM test_employees")
|
|
235
|
-
cursor.exec
|
|
236
|
-
cursor.fetch.should == [1.5]
|
|
237
|
-
cursor.close
|
|
238
|
-
end
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
describe "auto reconnection" do
|
|
242
|
-
before(:all) do
|
|
243
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
244
|
-
@conn = ActiveRecord::Base.connection.instance_variable_get("@connection")
|
|
245
|
-
@sys_conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(SYS_CONNECTION_PARAMS)
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
before(:each) do
|
|
249
|
-
ActiveRecord::Base.connection.reconnect! unless @conn.active?
|
|
250
|
-
end
|
|
251
|
-
|
|
252
|
-
def kill_current_session
|
|
253
|
-
audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first['audsid']
|
|
254
|
-
sid_serial = @sys_conn.select("SELECT s.sid||','||s.serial# sid_serial
|
|
255
|
-
FROM v$session s
|
|
256
|
-
WHERE audsid = '#{audsid}'").first['sid_serial']
|
|
257
|
-
@sys_conn.exec "ALTER SYSTEM KILL SESSION '#{sid_serial}' IMMEDIATE"
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
it "should reconnect and execute SQL statement if connection is lost and auto retry is enabled" do
|
|
261
|
-
# @conn.auto_retry = true
|
|
262
|
-
ActiveRecord::Base.connection.auto_retry = true
|
|
263
|
-
kill_current_session
|
|
264
|
-
@conn.exec("SELECT * FROM dual").should_not be_nil
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
it "should not reconnect and execute SQL statement if connection is lost and auto retry is disabled" do
|
|
268
|
-
# @conn.auto_retry = false
|
|
269
|
-
ActiveRecord::Base.connection.auto_retry = false
|
|
270
|
-
kill_current_session
|
|
271
|
-
lambda { @conn.exec("SELECT * FROM dual") }.should raise_error
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
it "should reconnect and execute SQL select if connection is lost and auto retry is enabled" do
|
|
275
|
-
# @conn.auto_retry = true
|
|
276
|
-
ActiveRecord::Base.connection.auto_retry = true
|
|
277
|
-
kill_current_session
|
|
278
|
-
@conn.select("SELECT * FROM dual").should == [{'dummy' => 'X'}]
|
|
279
|
-
end
|
|
280
|
-
|
|
281
|
-
it "should not reconnect and execute SQL select if connection is lost and auto retry is disabled" do
|
|
282
|
-
# @conn.auto_retry = false
|
|
283
|
-
ActiveRecord::Base.connection.auto_retry = false
|
|
284
|
-
kill_current_session
|
|
285
|
-
lambda { @conn.select("SELECT * FROM dual") }.should raise_error
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
describe "describe table" do
|
|
291
|
-
before(:all) do
|
|
292
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
|
293
|
-
@owner = CONNECTION_PARAMS[:username].upcase
|
|
294
|
-
end
|
|
295
|
-
|
|
296
|
-
it "should describe existing table" do
|
|
297
|
-
@conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
|
|
298
|
-
@conn.describe("test_employees").should == [@owner, "TEST_EMPLOYEES"]
|
|
299
|
-
@conn.exec "DROP TABLE test_employees" rescue nil
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
it "should not describe non-existing table" do
|
|
303
|
-
lambda { @conn.describe("test_xxx") }.should raise_error(ActiveRecord::ConnectionAdapters::OracleEnhancedConnectionException)
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
it "should describe table in other schema" do
|
|
307
|
-
@conn.describe("sys.dual").should == ["SYS", "DUAL"]
|
|
308
|
-
end
|
|
309
|
-
|
|
310
|
-
it "should describe existing view" do
|
|
311
|
-
@conn.exec "CREATE TABLE test_employees (first_name VARCHAR2(20))" rescue nil
|
|
312
|
-
@conn.exec "CREATE VIEW test_employees_v AS SELECT * FROM test_employees" rescue nil
|
|
313
|
-
@conn.describe("test_employees_v").should == [@owner, "TEST_EMPLOYEES_V"]
|
|
314
|
-
@conn.exec "DROP VIEW test_employees_v" rescue nil
|
|
315
|
-
@conn.exec "DROP TABLE test_employees" rescue nil
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
it "should describe view in other schema" do
|
|
319
|
-
@conn.describe("sys.v_$version").should == ["SYS", "V_$VERSION"]
|
|
320
|
-
end
|
|
321
|
-
|
|
322
|
-
it "should describe existing private synonym" do
|
|
323
|
-
@conn.exec "CREATE SYNONYM test_dual FOR sys.dual" rescue nil
|
|
324
|
-
@conn.describe("test_dual").should == ["SYS", "DUAL"]
|
|
325
|
-
@conn.exec "DROP SYNONYM test_dual" rescue nil
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
it "should describe existing public synonym" do
|
|
329
|
-
@conn.describe("all_tables").should == ["SYS", "ALL_TABLES"]
|
|
330
|
-
end
|
|
331
|
-
|
|
332
|
-
end
|
|
333
|
-
|
|
334
|
-
end
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# encoding: utf-8
|
|
2
|
-
require 'spec_helper'
|
|
3
|
-
|
|
4
|
-
describe "OracleEnhancedAdapter to_d method" do
|
|
5
|
-
it "BigDecimal#to_d returns the same decimal number" do
|
|
6
|
-
d = BigDecimal.new("12345678901234567890.0123456789")
|
|
7
|
-
d.to_d.should == d
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
it "Bignum#to_d translates large integer to decimal" do
|
|
11
|
-
n = 12345678901234567890
|
|
12
|
-
n.to_d.should == BigDecimal.new(n.to_s)
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
it "Fixnum#to_d translates small integer to decimal" do
|
|
16
|
-
n = 123456
|
|
17
|
-
n.to_d.should == BigDecimal.new(n.to_s)
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
unless defined?(NO_COMPOSITE_PRIMARY_KEYS)
|
|
4
|
-
|
|
5
|
-
describe "OracleEnhancedAdapter composite_primary_keys support" do
|
|
6
|
-
include SchemaSpecHelper
|
|
7
|
-
|
|
8
|
-
before(:all) do
|
|
9
|
-
if defined?(::ActiveRecord::ConnectionAdapters::OracleAdapter)
|
|
10
|
-
@old_oracle_adapter = ::ActiveRecord::ConnectionAdapters::OracleAdapter
|
|
11
|
-
::ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
|
|
12
|
-
end
|
|
13
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
14
|
-
if $cpk_oracle_adapter
|
|
15
|
-
::ActiveRecord::ConnectionAdapters::OracleAdapter = $cpk_oracle_adapter
|
|
16
|
-
$cpk_oracle_adapter = nil
|
|
17
|
-
end
|
|
18
|
-
require 'composite_primary_keys'
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
after(:all) do
|
|
22
|
-
# Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
|
|
23
|
-
if defined?(::ActiveRecord::ConnectionAdapters::OracleAdapter)
|
|
24
|
-
$cpk_oracle_adapter = ::ActiveRecord::ConnectionAdapters::OracleAdapter
|
|
25
|
-
::ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
|
|
26
|
-
end
|
|
27
|
-
if @old_oracle_adapter
|
|
28
|
-
::ActiveRecord::ConnectionAdapters::OracleAdapter = @old_oracle_adapter
|
|
29
|
-
@old_oracle_adapter = nil
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
describe "do not use count distinct" do
|
|
34
|
-
before(:all) do
|
|
35
|
-
schema_define do
|
|
36
|
-
create_table :job_history, :primary_key => [:employee_id, :start_date], :force => true do |t|
|
|
37
|
-
t.integer :employee_id
|
|
38
|
-
t.date :start_date
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
class ::JobHistory < ActiveRecord::Base
|
|
42
|
-
set_table_name "job_history"
|
|
43
|
-
set_primary_keys :employee_id, :start_date
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
after(:all) do
|
|
48
|
-
Object.send(:remove_const, 'JobHistory') if defined?(JobHistory)
|
|
49
|
-
schema_define do
|
|
50
|
-
drop_table :job_history
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "should tell ActiveRecord that count distinct is not supported" do
|
|
55
|
-
ActiveRecord::Base.connection.supports_count_distinct?.should be_false
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it "should execute correct SQL COUNT DISTINCT statement on table with composite primary keys" do
|
|
59
|
-
lambda { JobHistory.count(:distinct => true) }.should_not raise_error
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
describe "table with LOB" do
|
|
64
|
-
before(:all) do
|
|
65
|
-
schema_define do
|
|
66
|
-
create_table :cpk_write_lobs_test, :primary_key => [:type_category, :date_value], :force => true do |t|
|
|
67
|
-
t.string :type_category, :limit => 15, :null => false
|
|
68
|
-
t.date :date_value, :null => false
|
|
69
|
-
t.text :results, :null => false
|
|
70
|
-
t.timestamps
|
|
71
|
-
end
|
|
72
|
-
create_table :non_cpk_write_lobs_test, :force => true do |t|
|
|
73
|
-
t.date :date_value, :null => false
|
|
74
|
-
t.text :results, :null => false
|
|
75
|
-
t.timestamps
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
class ::CpkWriteLobsTest < ActiveRecord::Base
|
|
79
|
-
set_table_name 'cpk_write_lobs_test'
|
|
80
|
-
set_primary_keys :type_category, :date_value
|
|
81
|
-
end
|
|
82
|
-
class ::NonCpkWriteLobsTest < ActiveRecord::Base
|
|
83
|
-
set_table_name 'non_cpk_write_lobs_test'
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
after(:all) do
|
|
88
|
-
schema_define do
|
|
89
|
-
drop_table :cpk_write_lobs_test
|
|
90
|
-
drop_table :non_cpk_write_lobs_test
|
|
91
|
-
end
|
|
92
|
-
Object.send(:remove_const, "CpkWriteLobsTest")
|
|
93
|
-
Object.send(:remove_const, "NonCpkWriteLobsTest")
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it "should create new record in table with CPK and LOB" do
|
|
97
|
-
lambda {
|
|
98
|
-
CpkWriteLobsTest.create(:type_category => 'AAA', :date_value => Date.today, :results => 'DATA '*10)
|
|
99
|
-
}.should_not raise_error
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it "should create new record in table without CPK and with LOB" do
|
|
103
|
-
lambda {
|
|
104
|
-
NonCpkWriteLobsTest.create(:date_value => Date.today, :results => 'DATA '*10)
|
|
105
|
-
}.should_not raise_error
|
|
106
|
-
end
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
# Other testing was done based on composite_primary_keys tests
|
|
110
|
-
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
end
|