activerecord-oracle_enhanced-adapter 6.0.6 → 6.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +80 -4
  3. data/README.md +1 -1
  4. data/VERSION +1 -1
  5. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +2 -3
  6. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +0 -1
  7. data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +0 -9
  8. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +7 -9
  9. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +4 -5
  10. data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +0 -1
  11. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +3 -4
  12. data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +1 -2
  13. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +2 -3
  14. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +0 -1
  15. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +2 -3
  16. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +2 -3
  17. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +16 -4
  18. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +55 -55
  19. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +35 -39
  20. data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +2 -1
  21. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +58 -40
  22. data/lib/active_record/type/oracle_enhanced/boolean.rb +0 -1
  23. data/lib/active_record/type/oracle_enhanced/integer.rb +0 -1
  24. data/lib/arel/visitors/oracle.rb +253 -0
  25. data/lib/arel/visitors/oracle12.rb +160 -0
  26. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +9 -3
  27. data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +6 -1
  28. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +0 -1
  29. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +27 -0
  30. data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +2 -2
  31. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +30 -60
  32. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +4 -2
  33. data/spec/spec_config.yaml.template +2 -2
  34. data/spec/spec_helper.rb +13 -2
  35. data/spec/support/stats.sql +3 -0
  36. metadata +31 -27
@@ -16,10 +16,15 @@ describe "Oracle Enhanced adapter database tasks" do
16
16
  ActiveRecord::Tasks::DatabaseTasks.create(new_user_config)
17
17
  end
18
18
  end
19
- it "creates user" do
19
+ xit "creates user" do
20
20
  query = "SELECT COUNT(*) FROM dba_users WHERE UPPER(username) = '#{new_user_config[:username].upcase}'"
21
21
  expect(ActiveRecord::Base.connection.select_value(query)).to eq(1)
22
22
  end
23
+ xit "grants permissions defined by OracleEnhancedAdapter.persmissions" do
24
+ query = "SELECT COUNT(*) FROM DBA_SYS_PRIVS WHERE GRANTEE = '#{new_user_config[:username].upcase}'"
25
+ permissions_count = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.permissions.size
26
+ expect(ActiveRecord::Base.connection.select_value(query)).to eq(permissions_count)
27
+ end
23
28
  after do
24
29
  ActiveRecord::Base.connection.execute("DROP USER #{new_user_config[:username]}")
25
30
  end
@@ -133,7 +133,6 @@ describe "OracleEnhancedAdapter custom methods for create, update and destroy" d
133
133
  end
134
134
 
135
135
  private
136
-
137
136
  def raise_make_transaction_rollback
138
137
  raise "Make the transaction rollback"
139
138
  end
@@ -305,6 +305,33 @@ describe "OracleEnhancedAdapter schema dump" do
305
305
  end
306
306
  end
307
307
 
308
+ describe "context indexes" do
309
+ before(:each) do
310
+ schema_define do
311
+ create_table :test_context_indexed_posts, force: true do |t|
312
+ t.string :title
313
+ t.string :body
314
+ t.index :title
315
+ end
316
+ add_context_index :test_context_indexed_posts, :body, sync: "ON COMMIT"
317
+ end
318
+ end
319
+
320
+ after(:each) do
321
+ schema_define do
322
+ drop_table :test_context_indexed_posts
323
+ end
324
+ end
325
+
326
+ it "should dump the context index" do
327
+ expect(standard_dump).to include(%(add_context_index "test_context_indexed_posts", ["body"]))
328
+ end
329
+
330
+ it "dumps the sync option" do
331
+ expect(standard_dump).to include(%(sync: "ON COMMIT"))
332
+ end
333
+ end
334
+
308
335
  describe "virtual columns" do
309
336
  before(:all) do
310
337
  skip "Not supported in this database version" unless @oracle11g_or_higher
@@ -66,7 +66,7 @@ describe "OracleEnhancedAdapter structure dump" do
66
66
  ALTER TABLE TEST_POSTS
67
67
  ADD CONSTRAINT fk_test_post_foo FOREIGN KEY (foo_id) REFERENCES foos(id)
68
68
  SQL
69
- dump = ActiveRecord::Base.connection.structure_dump
69
+ dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
70
70
  expect(dump.split('\n').length).to eq(1)
71
71
  expect(dump).to match(/ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_FOO\"? FOREIGN KEY \(\"?FOO_ID\"?\) REFERENCES \"?FOOS\"?\(\"?ID\"?\)/i)
72
72
  end
@@ -86,7 +86,7 @@ describe "OracleEnhancedAdapter structure dump" do
86
86
  ADD CONSTRAINT fk_test_post_baz FOREIGN KEY (baz_id) REFERENCES foos(baz_id)
87
87
  SQL
88
88
 
89
- dump = ActiveRecord::Base.connection.structure_dump
89
+ dump = ActiveRecord::Base.connection.structure_dump_fk_constraints
90
90
  expect(dump.split('\n').length).to eq(1)
91
91
  expect(dump).to match(/ALTER TABLE \"?TEST_POSTS\"? ADD CONSTRAINT \"?FK_TEST_POST_BAZ\"? FOREIGN KEY \(\"?BAZ_ID\"?\) REFERENCES \"?FOOS\"?\(\"?BAZ_ID\"?\)/i)
92
92
  end
@@ -150,7 +150,7 @@ describe "OracleEnhancedAdapter" do
150
150
  end
151
151
  end
152
152
 
153
- describe "`has_many` assoc has `dependent: :delete_all` with `order`" do
153
+ describe "eager loading" do
154
154
  before(:all) do
155
155
  schema_define do
156
156
  create_table :test_posts do |t|
@@ -163,14 +163,17 @@ describe "OracleEnhancedAdapter" do
163
163
  add_index :test_comments, :test_post_id
164
164
  end
165
165
  class ::TestPost < ActiveRecord::Base
166
- has_many :test_comments, -> { order(:id) }, dependent: :delete_all
166
+ has_many :test_comments
167
167
  end
168
168
  class ::TestComment < ActiveRecord::Base
169
169
  belongs_to :test_post
170
170
  end
171
+ @ids = (1..1010).to_a
171
172
  TestPost.transaction do
172
- post = TestPost.create!(title: "Title")
173
- TestComment.create!(test_post_id: post.id, description: "Description")
173
+ @ids.each do |id|
174
+ TestPost.create!(id: id, title: "Title #{id}")
175
+ TestComment.create!(test_post_id: id, description: "Description #{id}")
176
+ end
174
177
  end
175
178
  end
176
179
 
@@ -184,50 +187,48 @@ describe "OracleEnhancedAdapter" do
184
187
  ActiveRecord::Base.clear_cache!
185
188
  end
186
189
 
187
- it "should not occur `ActiveRecord::StatementInvalid: OCIError: ORA-00907: missing right parenthesis`" do
188
- expect { TestPost.first.destroy }.not_to raise_error
190
+ it "should load included association with more than 1000 records" do
191
+ posts = TestPost.includes(:test_comments).to_a
192
+ expect(posts.size).to eq(@ids.size)
189
193
  end
190
194
  end
191
195
 
192
- describe "eager loading" do
196
+ describe "lists" do
193
197
  before(:all) do
194
198
  schema_define do
195
199
  create_table :test_posts do |t|
196
- t.string :title
197
- end
198
- create_table :test_comments do |t|
199
- t.integer :test_post_id
200
- t.string :description
200
+ t.string :title
201
201
  end
202
- add_index :test_comments, :test_post_id
203
202
  end
204
203
  class ::TestPost < ActiveRecord::Base
205
204
  has_many :test_comments
206
205
  end
207
- class ::TestComment < ActiveRecord::Base
208
- belongs_to :test_post
209
- end
210
206
  @ids = (1..1010).to_a
211
207
  TestPost.transaction do
212
208
  @ids.each do |id|
213
209
  TestPost.create!(id: id, title: "Title #{id}")
214
- TestComment.create!(test_post_id: id, description: "Description #{id}")
215
210
  end
216
211
  end
217
212
  end
218
213
 
219
214
  after(:all) do
220
215
  schema_define do
221
- drop_table :test_comments
222
216
  drop_table :test_posts
223
217
  end
224
218
  Object.send(:remove_const, "TestPost")
225
- Object.send(:remove_const, "TestComment")
226
219
  ActiveRecord::Base.clear_cache!
227
220
  end
228
221
 
229
- it "should load included association with more than 1000 records" do
230
- posts = TestPost.includes(:test_comments).to_a
222
+ ##
223
+ # See this GitHub issue for an explanation of homogenous lists.
224
+ # https://github.com/rails/rails/commit/72fd0bae5948c1169411941aeea6fef4c58f34a9
225
+ it "should allow more than 1000 items in a list where the list is homogenous" do
226
+ posts = TestPost.where(id: @ids).to_a
227
+ expect(posts.size).to eq(@ids.size)
228
+ end
229
+
230
+ it "should allow more than 1000 items in a list where the list is non-homogenous" do
231
+ posts = TestPost.where(id: [*@ids, nil]).to_a
231
232
  expect(posts.size).to eq(@ids.size)
232
233
  end
233
234
  end
@@ -283,6 +284,14 @@ describe "OracleEnhancedAdapter" do
283
284
  end
284
285
  end
285
286
 
287
+ describe "database_exists?" do
288
+ it "should raise `NotImplementedError`" do
289
+ expect {
290
+ ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.database_exists?(CONNECTION_PARAMS)
291
+ }.to raise_error(NotImplementedError)
292
+ end
293
+ end
294
+
286
295
  describe "explain" do
287
296
  before(:all) do
288
297
  @conn = ActiveRecord::Base.connection
@@ -431,45 +440,6 @@ describe "OracleEnhancedAdapter" do
431
440
  end
432
441
  end
433
442
 
434
- describe "Binary lob column" do
435
- before(:all) do
436
- schema_define do
437
- create_table :test_binary_columns do |t|
438
- t.binary :attachment
439
- end
440
- end
441
- class ::TestBinaryColumn < ActiveRecord::Base
442
- end
443
- end
444
-
445
- after(:all) do
446
- schema_define do
447
- drop_table :test_binary_columns
448
- end
449
- Object.send(:remove_const, "TestBinaryColumn")
450
- ActiveRecord::Base.table_name_prefix = nil
451
- ActiveRecord::Base.clear_cache!
452
- end
453
-
454
- before(:each) do
455
- set_logger
456
- end
457
-
458
- after(:each) do
459
- clear_logger
460
- end
461
-
462
- it "should serialize with non UTF-8 data" do
463
- binary_value = +"Hello \x93\xfa\x96\x7b"
464
- binary_value.force_encoding "UTF-8"
465
-
466
- binary_column_object = TestBinaryColumn.new
467
- binary_column_object.attachment = binary_value
468
-
469
- expect(binary_column_object.save!).to eq(true)
470
- end
471
- end
472
-
473
443
  describe "quoting" do
474
444
  before(:all) do
475
445
  schema_define do
@@ -35,9 +35,11 @@ describe "OracleEnhancedAdapter quoting of NCHAR and NVARCHAR2 columns" do
35
35
  columns = @conn.columns("test_items")
36
36
  %w(nchar_column nvarchar2_column char_column varchar2_column).each do |col|
37
37
  column = columns.detect { |c| c.name == col }
38
- value = @conn.type_cast_from_column(column, "abc")
38
+ type = @conn.lookup_cast_type_from_column(column)
39
+ value = type.serialize("abc")
39
40
  expect(@conn.quote(value)).to eq(column.sql_type[0, 1] == "N" ? "N'abc'" : "'abc'")
40
- nilvalue = @conn.type_cast_from_column(column, nil)
41
+ type = @conn.lookup_cast_type_from_column(column)
42
+ nilvalue = type.serialize(nil)
41
43
  expect(@conn.quote(nilvalue)).to eq("NULL")
42
44
  end
43
45
  end
@@ -1,4 +1,4 @@
1
- # copy this file to spec/config.yaml and set appropriate values
1
+ # copy this file to spec/spec_config.yaml and set appropriate values
2
2
  # you can also use environment variables, see spec_helper.rb
3
3
  database:
4
4
  name: 'orcl'
@@ -8,4 +8,4 @@ database:
8
8
  password: 'oracle_enhanced'
9
9
  sys_password: 'admin'
10
10
  non_default_tablespace: 'SYSTEM'
11
- timezone: 'Europe/Riga'
11
+ timezone: 'Europe/Riga'
data/spec/spec_helper.rb CHANGED
@@ -17,8 +17,8 @@ end
17
17
 
18
18
  require "rspec"
19
19
 
20
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
21
- puts "==> Running specs with MRI version #{RUBY_VERSION}"
20
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "truffleruby"
21
+ puts "==> Running specs with ruby version #{RUBY_VERSION}"
22
22
  require "oci8"
23
23
  elsif RUBY_ENGINE == "jruby"
24
24
  puts "==> Running specs with JRuby version #{JRUBY_VERSION}"
@@ -105,6 +105,8 @@ module LoggerSpecHelper
105
105
  end
106
106
  end
107
107
 
108
+ ActiveRecord::LogSubscriber::IGNORE_PAYLOAD_NAMES.replace(["EXPLAIN"])
109
+
108
110
  module SchemaSpecHelper
109
111
  def schema_define(&block)
110
112
  ActiveRecord::Schema.define do
@@ -183,6 +185,15 @@ SYSTEM_CONNECTION_PARAMS = {
183
185
  password: DATABASE_SYS_PASSWORD
184
186
  }
185
187
 
188
+ SERVICE_NAME_CONNECTION_PARAMS = {
189
+ adapter: "oracle_enhanced",
190
+ database: "/#{DATABASE_NAME}",
191
+ host: DATABASE_HOST,
192
+ port: DATABASE_PORT,
193
+ username: DATABASE_USER,
194
+ password: DATABASE_PASSWORD
195
+ }
196
+
186
197
  DATABASE_NON_DEFAULT_TABLESPACE = config["database"]["non_default_tablespace"] || ENV["DATABASE_NON_DEFAULT_TABLESPACE"] || "SYSTEM"
187
198
 
188
199
  # set default time zone in TZ environment variable
@@ -0,0 +1,3 @@
1
+ exec DBMS_STATS.GATHER_DICTIONARY_STATS();
2
+ exec DBMS_STATS.GATHER_FIXED_OBJECTS_STATS;
3
+ quit
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-oracle_enhanced-adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.6
4
+ version: 6.1.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-14 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.0
19
+ version: 6.1.0.rc1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 6.0.0
26
+ version: 6.1.0.rc1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: ruby-plsql
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,8 @@ files:
86
86
  - lib/active_record/type/oracle_enhanced/timestampltz.rb
87
87
  - lib/active_record/type/oracle_enhanced/timestamptz.rb
88
88
  - lib/activerecord-oracle_enhanced-adapter.rb
89
+ - lib/arel/visitors/oracle.rb
90
+ - lib/arel/visitors/oracle12.rb
89
91
  - spec/active_record/connection_adapters/emulation/oracle_adapter_spec.rb
90
92
  - spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb
91
93
  - spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb
@@ -116,6 +118,7 @@ files:
116
118
  - spec/support/alter_system_set_open_cursors.sql
117
119
  - spec/support/alter_system_user_password.sql
118
120
  - spec/support/create_oracle_enhanced_users.sql
121
+ - spec/support/stats.sql
119
122
  homepage: http://github.com/rsim/oracle-enhanced
120
123
  licenses:
121
124
  - MIT
@@ -135,38 +138,39 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
138
  - !ruby/object:Gem::Version
136
139
  version: 1.8.11
137
140
  requirements: []
138
- rubygems_version: 3.2.3
141
+ rubygems_version: 3.1.4
139
142
  signing_key:
140
143
  specification_version: 4
141
144
  summary: Oracle enhanced adapter for ActiveRecord
142
145
  test_files:
146
+ - spec/active_record/oracle_enhanced/type/dirty_spec.rb
147
+ - spec/active_record/oracle_enhanced/type/national_character_text_spec.rb
148
+ - spec/active_record/oracle_enhanced/type/raw_spec.rb
149
+ - spec/active_record/oracle_enhanced/type/float_spec.rb
150
+ - spec/active_record/oracle_enhanced/type/decimal_spec.rb
151
+ - spec/active_record/oracle_enhanced/type/character_string_spec.rb
152
+ - spec/active_record/oracle_enhanced/type/boolean_spec.rb
153
+ - spec/active_record/oracle_enhanced/type/json_spec.rb
154
+ - spec/active_record/oracle_enhanced/type/binary_spec.rb
155
+ - spec/active_record/oracle_enhanced/type/national_character_string_spec.rb
156
+ - spec/active_record/oracle_enhanced/type/timestamp_spec.rb
157
+ - spec/active_record/oracle_enhanced/type/integer_spec.rb
158
+ - spec/active_record/oracle_enhanced/type/text_spec.rb
159
+ - spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb
143
160
  - spec/active_record/connection_adapters/emulation/oracle_adapter_spec.rb
144
- - spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb
145
- - spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb
161
+ - spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb
146
162
  - spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb
147
- - spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb
148
- - spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb
149
163
  - spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb
150
- - spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb
151
164
  - spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb
165
+ - spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb
152
166
  - spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb
153
- - spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb
167
+ - spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb
168
+ - spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb
169
+ - spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb
154
170
  - spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb
155
- - spec/active_record/oracle_enhanced/type/binary_spec.rb
156
- - spec/active_record/oracle_enhanced/type/boolean_spec.rb
157
- - spec/active_record/oracle_enhanced/type/character_string_spec.rb
158
- - spec/active_record/oracle_enhanced/type/decimal_spec.rb
159
- - spec/active_record/oracle_enhanced/type/dirty_spec.rb
160
- - spec/active_record/oracle_enhanced/type/float_spec.rb
161
- - spec/active_record/oracle_enhanced/type/integer_spec.rb
162
- - spec/active_record/oracle_enhanced/type/json_spec.rb
163
- - spec/active_record/oracle_enhanced/type/national_character_string_spec.rb
164
- - spec/active_record/oracle_enhanced/type/national_character_text_spec.rb
165
- - spec/active_record/oracle_enhanced/type/raw_spec.rb
166
- - spec/active_record/oracle_enhanced/type/text_spec.rb
167
- - spec/active_record/oracle_enhanced/type/timestamp_spec.rb
171
+ - spec/support/stats.sql
172
+ - spec/support/create_oracle_enhanced_users.sql
173
+ - spec/support/alter_system_user_password.sql
174
+ - spec/support/alter_system_set_open_cursors.sql
168
175
  - spec/spec_config.yaml.template
169
176
  - spec/spec_helper.rb
170
- - spec/support/alter_system_set_open_cursors.sql
171
- - spec/support/alter_system_user_password.sql
172
- - spec/support/create_oracle_enhanced_users.sql