activerecord-oracle_enhanced-adapter 8.1.0-java

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 (78) hide show
  1. checksums.yaml +7 -0
  2. data/History.md +1971 -0
  3. data/License.txt +20 -0
  4. data/README.md +947 -0
  5. data/VERSION +1 -0
  6. data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +7 -0
  7. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +24 -0
  8. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +137 -0
  9. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +359 -0
  10. data/lib/active_record/connection_adapters/oracle_enhanced/database_limits.rb +47 -0
  11. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +325 -0
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +63 -0
  13. data/lib/active_record/connection_adapters/oracle_enhanced/dbms_output.rb +71 -0
  14. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +629 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +38 -0
  16. data/lib/active_record/connection_adapters/oracle_enhanced/lob.rb +57 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +465 -0
  18. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +44 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +195 -0
  20. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +186 -0
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +95 -0
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +99 -0
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +197 -0
  24. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +739 -0
  25. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +394 -0
  26. data/lib/active_record/connection_adapters/oracle_enhanced/type_metadata.rb +34 -0
  27. data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +3 -0
  28. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +886 -0
  29. data/lib/active_record/type/oracle_enhanced/boolean.rb +19 -0
  30. data/lib/active_record/type/oracle_enhanced/character_string.rb +36 -0
  31. data/lib/active_record/type/oracle_enhanced/integer.rb +14 -0
  32. data/lib/active_record/type/oracle_enhanced/json.rb +10 -0
  33. data/lib/active_record/type/oracle_enhanced/national_character_string.rb +26 -0
  34. data/lib/active_record/type/oracle_enhanced/national_character_text.rb +36 -0
  35. data/lib/active_record/type/oracle_enhanced/raw.rb +25 -0
  36. data/lib/active_record/type/oracle_enhanced/string.rb +29 -0
  37. data/lib/active_record/type/oracle_enhanced/text.rb +32 -0
  38. data/lib/active_record/type/oracle_enhanced/timestampltz.rb +25 -0
  39. data/lib/active_record/type/oracle_enhanced/timestamptz.rb +25 -0
  40. data/lib/activerecord-oracle_enhanced-adapter.rb +25 -0
  41. data/lib/arel/visitors/oracle.rb +216 -0
  42. data/lib/arel/visitors/oracle12.rb +121 -0
  43. data/lib/arel/visitors/oracle_common.rb +51 -0
  44. data/spec/active_record/connection_adapters/emulation/oracle_adapter_spec.rb +24 -0
  45. data/spec/active_record/connection_adapters/oracle_enhanced/compatibility_spec.rb +40 -0
  46. data/spec/active_record/connection_adapters/oracle_enhanced/composite_spec.rb +84 -0
  47. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +589 -0
  48. data/spec/active_record/connection_adapters/oracle_enhanced/context_index_spec.rb +431 -0
  49. data/spec/active_record/connection_adapters/oracle_enhanced/database_tasks_spec.rb +122 -0
  50. data/spec/active_record/connection_adapters/oracle_enhanced/dbconsole_spec.rb +63 -0
  51. data/spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb +69 -0
  52. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +362 -0
  53. data/spec/active_record/connection_adapters/oracle_enhanced/quoting_spec.rb +181 -0
  54. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +492 -0
  55. data/spec/active_record/connection_adapters/oracle_enhanced/schema_statements_spec.rb +1318 -0
  56. data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +485 -0
  57. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +815 -0
  58. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +230 -0
  59. data/spec/active_record/oracle_enhanced/type/binary_spec.rb +119 -0
  60. data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +206 -0
  61. data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +67 -0
  62. data/spec/active_record/oracle_enhanced/type/custom_spec.rb +90 -0
  63. data/spec/active_record/oracle_enhanced/type/decimal_spec.rb +56 -0
  64. data/spec/active_record/oracle_enhanced/type/dirty_spec.rb +141 -0
  65. data/spec/active_record/oracle_enhanced/type/float_spec.rb +48 -0
  66. data/spec/active_record/oracle_enhanced/type/integer_spec.rb +101 -0
  67. data/spec/active_record/oracle_enhanced/type/json_spec.rb +56 -0
  68. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +55 -0
  69. data/spec/active_record/oracle_enhanced/type/national_character_text_spec.rb +230 -0
  70. data/spec/active_record/oracle_enhanced/type/raw_spec.rb +137 -0
  71. data/spec/active_record/oracle_enhanced/type/text_spec.rb +295 -0
  72. data/spec/active_record/oracle_enhanced/type/timestamp_spec.rb +107 -0
  73. data/spec/spec_config.yaml.template +11 -0
  74. data/spec/spec_helper.rb +225 -0
  75. data/spec/support/alter_system_set_open_cursors.sql +1 -0
  76. data/spec/support/alter_system_user_password.sql +2 -0
  77. data/spec/support/create_oracle_enhanced_users.sql +31 -0
  78. metadata +181 -0
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Arel # :nodoc: all
4
+ module Visitors
5
+ module OracleCommon
6
+ BIND_BLOCK = proc { |i| ":a#{i}" }
7
+ private_constant :BIND_BLOCK
8
+
9
+ def bind_block; BIND_BLOCK; end
10
+
11
+ private
12
+ # Oracle can't compare CLOB columns with standard SQL operators for comparison.
13
+ # We need to replace standard equality for text/binary columns to use DBMS_LOB.COMPARE function.
14
+ # Fixes ORA-00932: inconsistent datatypes: expected - got CLOB
15
+ def visit_Arel_Nodes_Equality(o, collector)
16
+ left = o.left
17
+ return super unless %i(text binary).include?(cached_column_for(left)&.type)
18
+
19
+ # https://docs.oracle.com/cd/B19306_01/appdev.102/b14258/d_lob.htm#i1016668
20
+ # returns 0 when the comparison succeeds
21
+ comparator = Arel::Nodes::NamedFunction.new("DBMS_LOB.COMPARE", [left, o.right])
22
+ collector = visit comparator, collector
23
+ collector << " = 0"
24
+ collector
25
+ end
26
+
27
+ def visit_Arel_Nodes_Matches(o, collector)
28
+ if !o.case_sensitive && o.left && o.right
29
+ o.left = Arel::Nodes::NamedFunction.new("UPPER", [o.left])
30
+ o.right = Arel::Nodes::NamedFunction.new("UPPER", [o.right])
31
+ end
32
+
33
+ super o, collector
34
+ end
35
+
36
+ def cached_column_for(attr)
37
+ return unless Arel::Attributes::Attribute === attr
38
+
39
+ table = attr.relation.name
40
+ return unless schema_cache.columns_hash?(table)
41
+
42
+ column = attr.name.to_s
43
+ schema_cache.columns_hash(table)[column]
44
+ end
45
+
46
+ def schema_cache
47
+ @connection.schema_cache
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe "OracleEnhancedAdapter emulate OracleAdapter" do
4
+ before(:all) do
5
+ @old_oracle_adapter = nil
6
+ if defined?(ActiveRecord::ConnectionAdapters::OracleAdapter)
7
+ @old_oracle_adapter = ActiveRecord::ConnectionAdapters::OracleAdapter
8
+ ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
9
+ end
10
+ end
11
+
12
+ it "should be an OracleAdapter" do
13
+ @conn = ActiveRecord::Base.establish_connection(CONNECTION_PARAMS.merge(adapter: "oracle"))
14
+ expect(ActiveRecord::Base.connection).not_to be_nil
15
+ expect(ActiveRecord::Base.connection.is_a?(ActiveRecord::ConnectionAdapters::OracleAdapter)).to be_truthy
16
+ end
17
+
18
+ after(:all) do
19
+ if @old_oracle_adapter
20
+ ActiveRecord::ConnectionAdapters.send(:remove_const, :OracleAdapter)
21
+ ActiveRecord::ConnectionAdapters::OracleAdapter = @old_oracle_adapter
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe "compatibility migrations" do
4
+ include SchemaSpecHelper
5
+
6
+ before(:all) do
7
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
8
+ @conn = ActiveRecord::Base.connection
9
+ schema_define do
10
+ create_table :test_employees, force: true
11
+ end
12
+ end
13
+
14
+ after(:all) do
15
+ schema_define do
16
+ drop_table :test_employees, if_exists: true
17
+ drop_table :new_test_employees, if_exists: true
18
+ end
19
+ end
20
+
21
+ it "should rename table on 7_0 and below" do
22
+ migration = Class.new(ActiveRecord::Migration[7.0]) {
23
+ def change
24
+ rename_table :test_employees, :new_test_employees
25
+ end
26
+ }.new
27
+
28
+ ActiveRecord::Migration.suppress_messages do
29
+ migration.migrate(:up)
30
+ end
31
+ expect(@conn.table_exists?(:new_test_employees)).to be_truthy
32
+ expect(@conn.table_exists?(:test_employees)).not_to be_truthy
33
+
34
+ ActiveRecord::Migration.suppress_messages do
35
+ migration.migrate(:down)
36
+ end
37
+ expect(@conn.table_exists?(:new_test_employees)).not_to be_truthy
38
+ expect(@conn.table_exists?(:test_employees)).to be_truthy
39
+ end
40
+ end
@@ -0,0 +1,84 @@
1
+ # frozen_string_literal: true
2
+
3
+ describe "OracleEnhancedAdapter should support composite primary" do
4
+ include SchemaSpecHelper
5
+
6
+ before(:all) do
7
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
8
+ schema_define do
9
+ create_table :test_authors, force: true do |t|
10
+ t.string :first_name, limit: 20
11
+ t.string :last_name, limit: 25
12
+ end
13
+
14
+ create_table :test_books, force: true do |t|
15
+ t.string :title, limit: 20
16
+ end
17
+
18
+ create_table :test_authors_test_books, primary_key: ["test_author_id", "test_book_id"], force: true do |t|
19
+ t.integer "test_author_id", precision: 38, null: false
20
+ t.integer "test_book_id", precision: 38, null: false
21
+ end
22
+ end
23
+ end
24
+
25
+ after(:all) do
26
+ schema_define do
27
+ drop_table :test_authors
28
+ drop_table :test_books
29
+ drop_table :test_authors_test_books
30
+ end
31
+ end
32
+
33
+ before(:each) do
34
+ class ::TestAuthor < ActiveRecord::Base
35
+ has_many :test_authors_test_books
36
+ has_many :test_books, through: :test_authors_test_books, inverse_of: :test_authors
37
+ end
38
+ class ::TestBook < ActiveRecord::Base
39
+ has_many :test_authors_test_books
40
+ has_many :test_authors, through: :test_authors_test_books, inverse_of: :test_books
41
+ end
42
+ class ::TestAuthorsTestBook < ActiveRecord::Base
43
+ self.primary_key = [:test_author_id, :test_book_id]
44
+ belongs_to :test_author, foreign_key: :test_author_id
45
+ belongs_to :test_book, foreign_key: :test_book_id
46
+ end
47
+
48
+ @author = TestAuthor.create!(
49
+ first_name: "First",
50
+ last_name: "Last",
51
+ )
52
+ @book = TestBook.create!(title: "Nice book")
53
+ @testRel = TestAuthorsTestBook.create!(test_author: @author, test_book: @book)
54
+ expect([@book]).to eq(@author.test_books)
55
+ end
56
+
57
+ after(:each) do
58
+ TestAuthor.delete_all
59
+ TestBook.delete_all
60
+ TestAuthorsTestBook.delete_all
61
+ Object.send(:remove_const, "TestAuthor")
62
+ Object.send(:remove_const, "TestBook")
63
+ Object.send(:remove_const, "TestAuthorsTestBook")
64
+ ActiveRecord::Base.clear_cache!
65
+ end
66
+
67
+ it "should support distinct" do
68
+ expect(TestAuthor.distinct.count).to eq(1)
69
+ skip "this appears to be a rails bug https://github.com/rails/rails/issues/55401"
70
+ expect(TestAuthorsTestBook.distinct.count).to eq(1)
71
+ end
72
+
73
+ it "should support includes when requesting the first record by a referenced composite idx association" do
74
+ expect([@book]).to eq(@author.test_books)
75
+ expect(TestAuthor.includes(:test_authors_test_books).references(:test_authors_test_books).merge(TestAuthorsTestBook.where(test_author: @author)).take).to eq(@author)
76
+ expect(TestAuthor.includes(:test_authors_test_books).references(:test_authors_test_books).merge(TestAuthorsTestBook.where(test_author: @author)).first).to eq(@author)
77
+ end
78
+
79
+ it "should support includes when requesting the first record by a referenced association" do
80
+ expect([@book]).to eq(@author.test_books)
81
+ expect(TestAuthorsTestBook.includes(:test_author).references(:test_author).merge(TestAuthor.where(first_name: "First")).take).to eq(@testRel)
82
+ expect(TestAuthorsTestBook.includes(:test_author).references(:test_author).merge(TestAuthor.where(first_name: "First")).first).to eq(@testRel)
83
+ end
84
+ end