activerecord-oracle_enhanced-adapter 6.0.6 → 6.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +141 -4
  3. data/README.md +12 -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 +6 -6
  9. data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +8 -9
  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 +9 -7
  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 +7 -11
  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 +15 -3
  18. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +42 -39
  19. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +16 -17
  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 +53 -34
  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 +217 -0
  25. data/lib/arel/visitors/oracle12.rb +124 -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 +5 -0
  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_adapter_spec.rb +83 -0
  31. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +4 -2
  32. data/spec/spec_config.yaml.template +2 -2
  33. data/spec/spec_helper.rb +13 -2
  34. metadata +7 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1410c7eb8f55a7b4c96b8016f31c573512699978498ee6effae6d4875b1e3f31
4
- data.tar.gz: 36cbc570c5c5a1c6d074353f1de0d8d6ce07c90fd5b906727d7ee2e78a473a1e
3
+ metadata.gz: b17060d198e5da1dcccae49e4c50e114a2fc52c84d7a529271a8c7fc1948c8a4
4
+ data.tar.gz: fbc916077b37c9a31f2a3e315b7ddec8559aaaadd5eb4898d67703914586a1e9
5
5
  SHA512:
6
- metadata.gz: 1f1ba2aed7eef1fa08e31c4fe7f43762eb077b10e412f9db61228589d1387f440b64b17db05fd3fd796e0eb4ebc8ca00f91f767f0ea6402e079783265cb583a6
7
- data.tar.gz: 700df5182daf9a04a67dcc478aa378d9deb8d09fba726ccf2ce9878b8c1dc70f56a5a135048e00438e5078b9916467f8b356e6a3a4bc5bc8897fb874a8a686c3
6
+ metadata.gz: f1654bf5c9d946e7f795075ae030e8b46560c8f1f680cbe203e953f1d3a596d5f4d20395c56e4bfc0d137cd1adb712f7ceaa50bcedbacae83583f7796d98a6ad
7
+ data.tar.gz: cc75b8f1cd8e2abd4ffa8268ba62bba9bbc1fae23d20502226ec95d3c0f56a4a90837e77bf650160b6c5b940db6284608bb191fd7f5b12c0c96eaf07989b75c4
data/History.md CHANGED
@@ -1,9 +1,146 @@
1
- ## 6.0.5 / 2020-12-17
1
+ ## 6.1.6 / 2022-01-21
2
2
 
3
3
  * Changes and bug fixes
4
- * Address `next_sequence_value` ArgumentError syntax [#2048 #2050]
5
- * Add /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint to address slow SCHEMA queries [#2055, #2069]
6
- * `build_subselect` does not have ordering [#2023, #2070, #2073]
4
+ * Fix `columns_for_distinct` when using Rails 6.1 [#2249 #2252 rails/rails#31966]
5
+
6
+ ## 6.1.5 / 2021-12-07
7
+
8
+ * Changes and bug fixes
9
+ * get root cause if something went wrong with jdbc.OracleDriver [#2180 #2181]
10
+
11
+ * CI
12
+ * Bump CRuby versions at Travis CI for release61 branch [#2192]
13
+
14
+ ## 6.1.4 / 2021-04-01
15
+
16
+ * Changes and bug fixes
17
+ * Support use of ojdbc11.jar [#2155, #2168]
18
+ * Add missing default granted permission "ulimited tablespace" [#2156, #2167]
19
+ * Prevent from including ojdbc8.jar file to gem file [#2163, #2164, #2165]
20
+ * Oracle enhanced adapter 6.1.3 has been yanked since #2163
21
+
22
+ * CI
23
+ * Allow-failure CI against jruby-head for release61 branch [#2166]
24
+
25
+ ## 6.1.3 / 2021-03-31
26
+
27
+ * Changes and bug fixes
28
+ * Address FrozenError (can't modify frozen Hash): error [#2139 #2151 #2160]
29
+
30
+ * CI
31
+ * CI against JRuby 9.2.15.0 [#2150]
32
+
33
+ ## 6.1.2 / 2021-02-10
34
+ * Changes and bug fixes
35
+ * Fixed ORA-01935: missing user or role name with config read issue [#1943 #2135, #2142]
36
+
37
+ ## 6.1.1 / 2021-01-14
38
+
39
+ * Changes and bug fixes
40
+ * Remove /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint for all_synonyms [#2110, #2119]
41
+ * Fix write_lobs Invalid byte sequence in UTF-8 [#2097, #2111]
42
+ * Ensure FKs are properly included in structure dumps [#2109, #2113]
43
+
44
+ * CI
45
+ * CI against JRuby 9.2.14.0 [#2085]
46
+ * CI against Ruby 3.0.0 [#2091, #2092]
47
+ * Address Travis CI warnings and bump Ubuntu version to 20.04 [#2086]
48
+ * Exclude `ruby-head` and `ruby-debug` until minitest allows Ruby 3.1 #2094, #2095
49
+ * CI against Ruby 3.0.0 at Travis CI [#2093]
50
+
51
+ ## 6.1.0 / 2020-12-15
52
+
53
+ * Changes and bug fixes
54
+ * Support Rails 6.1.0
55
+ * Update bug report templates for Oracle enhanced adapter 6.1 [#2063]
56
+ * Use released version of rake [#2065 #2066]
57
+ * Add /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ hint to address slow SCHEMA queries [#2055, #2068]
58
+ * `build_subselect` does not have ordering [#2070]
59
+ * Remove `visit_Arel_Nodes_NotIn` and `visit_Arel_Nodes_In` visitors [#2075, #2077]
60
+ * `NOT IN` clause needs separated by `AND` [#2079, #2081]
61
+
62
+ ## 6.1.0.rc1 / 2020-11-03
63
+
64
+ * Changes and bug fixes
65
+ * Support Rails 6.1.0.rc1
66
+ * Add support to change the permissions granted when creating DB [#1885]
67
+ * Refactor `create_table`'s options separation [#1886]
68
+ * Move schema cache to pool [#1888]
69
+ * Clear schema cache when a table is created/dropped/renamed [#1891]
70
+ * Deduplicate various Active Record schema cache structures [#1897]
71
+ * Support SQLCounter change to ignore "SCHEMA" and "TRANSACTION" log [#1892]
72
+ * Share the column and table name quote cache between connections [#1901]
73
+ * Add database_exists? method to connection adapters [#1906]
74
+ * Accept columns passed with options in remove_index [#1930]
75
+ * Fix `NameError` for `SchemaCreation` [#1933]
76
+ * Add `supports_common_table_expressions?` for CTE testing [#1946]
77
+ * create_table_definition and add_column take keyword arguments [#1942]
78
+ * Address `uninitialized constant ActiveRecord::ConnectionAdapters::AbstractAdapter::Quoting (NameError) [#1950]
79
+ * Fix an error when writing lobs [#1962]
80
+ * Uninstall SimpleCov [#1968]
81
+ * fix: Auto retry only works for connection.exec() [#1976]
82
+ * Fix keyword arguments errors for Ruby 2.8.0-dev [#1977]
83
+ * Fix a build errors when using Ruby 2.8.0-dev [#1983]
84
+ * Include sync option when dumping a context index [#1988]
85
+ * Use `build_result` instead of `ActiveRecord::Result.new` [#1994]
86
+ * Use the new API for build_results [#1995]
87
+ * Merge Arel visitors [#2002]
88
+ * Enable `Rails/IndexBy` and `Rails/IndexWith` cops [#2006]
89
+ * Don't refer `allowed_index_name_length` directly [#2009]
90
+ * Should not rely on the global `Arel::Table.engine` in the framework [#2010]
91
+ * Suppress `warning: already initialized constant` [#2011]
92
+ * Deprecate passing a column to `type_cast` [#2012]
93
+ * Limit number of expressions in a list during a "homogenous in" operation [#2013]
94
+ * Allow column name with function (e.g. `length(title)`) as safe SQL string [#2017]
95
+ * Default engine `ENGINE=InnoDB` is no longer dumped to make schema more agnostic [#2019]
96
+ * Separate primary key column options from table options [#2019]
97
+ * Make index options to kwargs [#2022]
98
+ * Make remaining migration options to kwargs [#2024]
99
+ * Allow TruffleRuby RUBY_ENGINE [#2046]
100
+ * Restore Schema Dumper behavior changed by #2019 [#2047]
101
+ * Support JDBC service name syntax [#2035]
102
+ * Use Rake 13.0.0.pre.1 [#1924]
103
+ * Bump RuboCop version to 0.71 [#1887]
104
+ * Bump RuboCop to 0.74.0 [#1914]
105
+ * Bump RuboCop to 0.76.0 [#1947]
106
+ * Use RuboCop 0.77 [#1959]
107
+ * Bump RuboCop to 0.82.0 [#2005]
108
+ * Suppress RuboCop's offenses [#2020]
109
+ * Enable `Layout/EmptyLinesAroundAccessModifier` cop [#1890]
110
+ * Disable `Style/BracesAroundHashParameters` cop [#1923]
111
+ * Enable `Layout/ClosingHeredocIndentation` cop [#1958]
112
+ * Unlock RuboCop gem versions [#1926]
113
+ * Enable `Rails/IndexBy` and `Rails/IndexWith` cops [#2006]
114
+ * Enable `Performance/DeletePrefix` and `Performance/DeleteSuffix` cops [#2021]
115
+ * Enable `Layout/SpaceAroundOperators` cop [#2057]
116
+ * Fix links to rails-dev-box running on docker [#1883]
117
+ * Fix spec config template copy instructions [#1884]
118
+ * Update UPGRADE section for Rails 5.2 [#1993]
119
+
120
+ * CI
121
+ * Enable GitHub Actions and run RuboCop [#1925]
122
+ * Run CI with GitHub Actions [#2015]
123
+ * Enabled Dependabot by creating .dependabot/config.yml [#1931]
124
+ * Disable Code Climate #1938
125
+ * CI against JRuby 9.2.8.0 [#1911]
126
+ * CI against JRuby 9.2.9.0 #1948
127
+ * CI against Ruby 2.6.4 and Ruby 2.5.6 [#1921]
128
+ * CI against Ruby 2.5.7 and Ruby 2.6.5 [#1949]
129
+ * CI against Ruby 2.7.0 [#1975]
130
+ * CI against JRuby 9.2.10.0 [#1989]
131
+ * CI against JRuby 9.2.11.0 [#1992]
132
+ * CI against JRuby 9.2.11.1 [#1997]
133
+ * CI againt Ruby 2.7.1, 2.6.6 and 2.5.8 #1998
134
+ * CI against JRuby 9.2.12.0 [#2034]
135
+ * Use Oracle Instant Client 18.5 [#2036]
136
+ * Support `jruby-head` again [#2037]
137
+ * CI against JRuby 9.2.13.0 [#2041]
138
+ * CI against Ruby 2.7.2 [#2052]
139
+ * Remove unnecessary PATH and LD_LIBRARY_PATH environment variables [#1927]
140
+ * Use Ubuntu 18.04 (Bionic Beaver) at Travis CI [#1937]
141
+ * Run bug report template at CI [#1936]
142
+ * Skip known failures until #1943 is resolved [#1961]
143
+ * Migrate to `ruby/setup-ruby` to use Ruby 2.7 [#2026]
7
144
 
8
145
  ## 6.0.4 / 2020-08-18
9
146
 
data/README.md CHANGED
@@ -10,6 +10,17 @@ Oracle enhanced ActiveRecord adapter provides Oracle database access from Ruby o
10
10
 
11
11
  INSTALLATION
12
12
  ------------
13
+ ### Rails 6.1
14
+
15
+ Oracle enhanced adapter version 6.1 supports Rails 6.1.
16
+ When using Ruby on Rails version 6.1 then in Gemfile include
17
+
18
+ ```ruby
19
+ # Use oracle as the database for Active Record
20
+ gem 'activerecord-oracle_enhanced-adapter', '~> 6.1.0'
21
+ gem 'ruby-oci8' # only for CRuby users
22
+ ```
23
+
13
24
  ### Rails 6.0
14
25
 
15
26
  Oracle enhanced adapter version 6.0 supports Rails 6.0.
@@ -663,7 +674,7 @@ if any database structure changed by migrations, execute `rails db:schema:cache:
663
674
 
664
675
  UPGRADE
665
676
  ---------------
666
- ### Upgrade Rails 5.0 or older version to Rails 5.2
677
+ ### Upgrade Rails 5.1 or older version to Rails 5.2
667
678
 
668
679
  * `emulate_booleans_from_strings = true` change
669
680
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.0.6
1
+ 6.1.6
@@ -19,7 +19,6 @@ module ActiveRecord
19
19
  attr_reader :raw_connection
20
20
 
21
21
  private
22
-
23
22
  # Used always by JDBC connection as well by OCI connection when describing tables over database link
24
23
  def describe(name)
25
24
  name = name.to_s
@@ -116,8 +115,8 @@ module ActiveRecord
116
115
  end
117
116
  end
118
117
 
119
- # if MRI or YARV
120
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
118
+ # if MRI or YARV or TruffleRuby
119
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "truffleruby"
121
120
  ORACLE_ENHANCED_CONNECTION = :oci
122
121
  require "active_record/connection_adapters/oracle_enhanced/oci_connection"
123
122
  # if JRuby
@@ -142,7 +142,6 @@ module ActiveRecord
142
142
  end
143
143
 
144
144
  private
145
-
146
145
  def create_datastore_procedure(table_name, procedure_name, column_names, options)
147
146
  quoted_table_name = quote_table_name(table_name)
148
147
  select_queries, column_names = column_names.partition { |c| c.to_s =~ /^\s*SELECT\s+/i }
@@ -25,15 +25,6 @@ module ActiveRecord
25
25
  end
26
26
  deprecate :column_name_length
27
27
 
28
- # Returns the maximum allowed length for an index name. This
29
- # limit is enforced by rails and Is less than or equal to
30
- # <tt>index_name_length</tt>. The gap between
31
- # <tt>index_name_length</tt> is to allow internal rails
32
- # opreations to use prefixes in temporary opreations.
33
- def allowed_index_name_length
34
- index_name_length
35
- end
36
-
37
28
  # the maximum length of an index name
38
29
  # supported by this database
39
30
  def index_name_length
@@ -42,7 +42,7 @@ module ActiveRecord
42
42
  cursor.exec
43
43
  end
44
44
 
45
- if (name == "EXPLAIN") && sql =~ /^EXPLAIN/
45
+ if (name == "EXPLAIN") && sql.start_with?("EXPLAIN")
46
46
  res = true
47
47
  else
48
48
  columns = cursor.get_col_names.map do |col_name|
@@ -53,7 +53,7 @@ module ActiveRecord
53
53
  while row = cursor.fetch(fetch_options)
54
54
  rows << row
55
55
  end
56
- res = ActiveRecord::Result.new(columns, rows)
56
+ res = build_result(columns: columns, rows: rows)
57
57
  end
58
58
 
59
59
  cursor.close unless cached
@@ -67,7 +67,7 @@ module ActiveRecord
67
67
 
68
68
  def explain(arel, binds = [])
69
69
  sql = "EXPLAIN PLAN FOR #{to_sql(arel, binds)}"
70
- return if sql =~ /FROM all_/
70
+ return if /FROM all_/.match?(sql)
71
71
  if ORACLE_ENHANCED_CONNECTION == :jdbc
72
72
  exec_query(sql, "EXPLAIN", binds)
73
73
  else
@@ -130,7 +130,7 @@ module ActiveRecord
130
130
  rows << [returning_id]
131
131
  end
132
132
  cursor.close unless cached
133
- ActiveRecord::Result.new(returning_id_col || [], rows)
133
+ build_result(columns: returning_id_col || [], rows: rows)
134
134
  end
135
135
  end
136
136
 
@@ -196,11 +196,11 @@ module ActiveRecord
196
196
  end
197
197
 
198
198
  def create_savepoint(name = current_savepoint_name) #:nodoc:
199
- execute("SAVEPOINT #{name}")
199
+ execute("SAVEPOINT #{name}", "TRANSACTION")
200
200
  end
201
201
 
202
202
  def exec_rollback_to_savepoint(name = current_savepoint_name) #:nodoc:
203
- execute("ROLLBACK TO #{name}")
203
+ execute("ROLLBACK TO #{name}", "TRANSACTION")
204
204
  end
205
205
 
206
206
  def release_savepoint(name = current_savepoint_name) #:nodoc:
@@ -17,21 +17,20 @@ module ActiveRecord
17
17
  print "Please provide the SYSTEM password for your Oracle installation (set ORACLE_SYSTEM_PASSWORD to avoid this prompt)\n>"
18
18
  $stdin.gets.strip
19
19
  }
20
- establish_connection(@config.merge("username" => "SYSTEM", "password" => system_password))
20
+ establish_connection(@config.merge(username: "SYSTEM", password: system_password))
21
21
  begin
22
- connection.execute "CREATE USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
22
+ connection.execute "CREATE USER #{@config[:username]} IDENTIFIED BY #{@config[:password]}"
23
23
  rescue => e
24
24
  if /ORA-01920/.match?(e.message) # user name conflicts with another user or role name
25
- connection.execute "ALTER USER #{@config['username']} IDENTIFIED BY #{@config['password']}"
25
+ connection.execute "ALTER USER #{@config[:username]} IDENTIFIED BY #{@config[:password]}"
26
26
  else
27
27
  raise e
28
28
  end
29
29
  end
30
- connection.execute "GRANT unlimited tablespace TO #{@config['username']}"
31
- connection.execute "GRANT create session TO #{@config['username']}"
32
- connection.execute "GRANT create table TO #{@config['username']}"
33
- connection.execute "GRANT create view TO #{@config['username']}"
34
- connection.execute "GRANT create sequence TO #{@config['username']}"
30
+
31
+ OracleEnhancedAdapter.permissions.each do |permission|
32
+ connection.execute "GRANT #{permission} TO #{@config[:username]}"
33
+ end
35
34
  end
36
35
 
37
36
  def drop
@@ -47,7 +46,7 @@ module ActiveRecord
47
46
  def structure_dump(filename, extra_flags)
48
47
  establish_connection(@config)
49
48
  File.open(filename, "w:utf-8") { |f| f << connection.structure_dump }
50
- if @config["structure_dump"] == "db_stored_code"
49
+ if @config[:structure_dump] == "db_stored_code"
51
50
  File.open(filename, "a") { |f| f << connection.structure_dump_db_stored_code }
52
51
  end
53
52
  end
@@ -31,7 +31,6 @@ module ActiveRecord
31
31
  end
32
32
 
33
33
  private
34
-
35
34
  def log(sql, name = "SQL", binds = [], type_casted_binds = [], statement_name = nil)
36
35
  super
37
36
  ensure
@@ -16,7 +16,8 @@ begin
16
16
  # Oracle 11g client ojdbc6.jar is also compatible with Java 1.7
17
17
  # Oracle 12c Release 1 client provides ojdbc7.jar
18
18
  # Oracle 12c Release 2 client provides ojdbc8.jar
19
- ojdbc_jars = %w(ojdbc8.jar ojdbc7.jar ojdbc6.jar)
19
+ # Oracle 21c provides ojdbc11.jar for Java 11 and above
20
+ ojdbc_jars = %w(ojdbc11.jar ojdbc8.jar ojdbc7.jar ojdbc6.jar)
20
21
 
21
22
  if !ENV_JAVA["java.class.path"]&.match?(Regexp.new(ojdbc_jars.join("|")))
22
23
  # On Unix environment variable should be PATH, on Windows it is sometimes Path
@@ -42,9 +43,9 @@ begin
42
43
  java.lang.System.set_property("oracle.net.tns_admin", ENV["TNS_ADMIN"])
43
44
  end
44
45
 
45
- rescue LoadError, NameError
46
+ rescue LoadError, NameError => e
46
47
  # JDBC driver is unavailable.
47
- raise LoadError, "ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install #{ojdbc_jars.join(' or ') } library."
48
+ raise LoadError, "ERROR: ActiveRecord oracle_enhanced adapter could not load Oracle JDBC driver. Please install #{ojdbc_jars.join(' or ') } library.\n#{e.class}:#{e.message}"
48
49
  end
49
50
 
50
51
  module ActiveRecord
@@ -98,6 +99,8 @@ module ActiveRecord
98
99
  @raw_connection = @raw_connection.underlying_connection
99
100
  end
100
101
 
102
+ # Workaround FrozenError (can't modify frozen Hash):
103
+ config = config.dup
101
104
  config[:driver] ||= @raw_connection.meta_data.connection.java_class.name
102
105
  username = @raw_connection.meta_data.user_name
103
106
  else
@@ -115,9 +118,9 @@ module ActiveRecord
115
118
  else
116
119
  unless database.match?(/^(\:|\/)/)
117
120
  # assume database is a SID if no colon or slash are supplied (backward-compatibility)
118
- database = ":#{database}"
121
+ database = "/#{database}"
119
122
  end
120
- url = config[:url] || "jdbc:oracle:thin:@#{host || 'localhost'}:#{port || 1521}#{database}"
123
+ url = config[:url] || "jdbc:oracle:thin:@//#{host || 'localhost'}:#{port || 1521}#{database}"
121
124
  end
122
125
 
123
126
  prefetch_rows = config[:prefetch_rows] || 100
@@ -238,7 +241,7 @@ module ActiveRecord
238
241
  begin
239
242
  yield if block_given?
240
243
  rescue Java::JavaSql::SQLException => e
241
- raise unless e.message =~ /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/
244
+ raise unless /^(Closed Connection|Io exception:|No more data to read from socket|IO Error:)/.match?(e.message)
242
245
  @active = false
243
246
  raise unless should_retry
244
247
  should_retry = false
@@ -512,7 +515,6 @@ module ActiveRecord
512
515
  end
513
516
 
514
517
  private
515
-
516
518
  def lob_to_ruby_value(val)
517
519
  case val
518
520
  when ::Java::OracleSql::CLOB
@@ -18,13 +18,12 @@ module ActiveRecord #:nodoc:
18
18
  module ClassMethods
19
19
  def lob_columns
20
20
  columns.select do |column|
21
- column.sql_type_metadata.sql_type =~ /LOB$/
21
+ column.sql_type_metadata.sql_type.end_with?("LOB")
22
22
  end
23
23
  end
24
24
  end
25
25
 
26
26
  private
27
-
28
27
  def enhanced_write_lobs
29
28
  if self.class.connection.is_a?(ConnectionAdapters::OracleEnhancedAdapter) &&
30
29
  !(self.class.custom_create_method || self.class.custom_update_method)
@@ -269,7 +269,6 @@ module ActiveRecord
269
269
  end
270
270
 
271
271
  private
272
-
273
272
  def date_without_time?(value)
274
273
  case value
275
274
  when OraDate
@@ -323,9 +322,9 @@ module ActiveRecord
323
322
  # connection using host, port and database name
324
323
  elsif host || port
325
324
  host ||= "localhost"
326
- host = "[#{host}]" if host =~ /^[^\[].*:/ # IPv6
325
+ host = "[#{host}]" if /^[^\[].*:/.match?(host) # IPv6
327
326
  port ||= 1521
328
- database = "/#{database}" unless database.match(/^\//)
327
+ database = "/#{database}" unless database.start_with?("/")
329
328
  "//#{host}:#{port}#{database}"
330
329
  # if no host is specified then assume that
331
330
  # database parameter is TNS alias or TNS connection string
@@ -97,7 +97,6 @@ module ActiveRecord #:nodoc:
97
97
  end
98
98
 
99
99
  private
100
-
101
100
  # Creates a record with custom create method
102
101
  # and returns its id.
103
102
  def _create_record
@@ -10,14 +10,11 @@ module ActiveRecord
10
10
 
11
11
  def quote_column_name(name) #:nodoc:
12
12
  name = name.to_s
13
- self.class.quoted_column_names[name] ||= begin
14
- # if only valid lowercase column characters in name
15
- if /\A[a-z][a-z_0-9\$#]*\Z/.match?(name)
16
- "\"#{name.upcase}\""
17
- else
18
- # remove double quotes which cannot be used inside quoted identifier
19
- "\"#{name.gsub('"', '')}\""
20
- end
13
+ self.class.quoted_column_names[name] ||= if /\A[a-z][a-z_0-9\$#]*\Z/.match?(name)
14
+ "\"#{name.upcase}\""
15
+ else
16
+ # remove double quotes which cannot be used inside quoted identifier
17
+ "\"#{name.gsub('"', '')}\""
21
18
  end
22
19
  end
23
20
 
@@ -169,7 +166,6 @@ module ActiveRecord
169
166
  private_constant :COLUMN_NAME, :COLUMN_NAME_WITH_ORDER
170
167
 
171
168
  private
172
-
173
169
  def oracle_downcase(column_name)
174
170
  return nil if column_name.nil?
175
171
  /[a-z]/.match?(column_name) ? column_name : column_name.downcase
@@ -179,8 +175,8 @@ module ActiveRecord
179
175
  end
180
176
  end
181
177
 
182
- # if MRI or YARV
183
- if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby"
178
+ # if MRI or YARV or TruffleRuby
179
+ if !defined?(RUBY_ENGINE) || RUBY_ENGINE == "ruby" || RUBY_ENGINE == "truffleruby"
184
180
  require "active_record/connection_adapters/oracle_enhanced/oci_quoting"
185
181
  # if JRuby
186
182
  elsif RUBY_ENGINE == "jruby"
@@ -3,9 +3,8 @@
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  module OracleEnhanced
6
- class SchemaCreation < AbstractAdapter::SchemaCreation
6
+ class SchemaCreation < SchemaCreation
7
7
  private
8
-
9
8
  def visit_ColumnDefinition(o)
10
9
  if [:blob, :clob, :nclob].include?(sql_type = type_to_sql(o.type, **o.options).downcase.to_sym)
11
10
  if (tablespace = default_tablespace_for(sql_type))
@@ -36,7 +35,7 @@ module ActiveRecord
36
35
  create_sql << " TABLESPACE #{tablespace}"
37
36
  end
38
37
  end
39
- add_table_options!(create_sql, table_options(o))
38
+ add_table_options!(create_sql, o)
40
39
  create_sql << " AS #{to_sql(o.as)}" if o.as
41
40
  create_sql
42
41
  end
@@ -4,7 +4,15 @@ module ActiveRecord #:nodoc:
4
4
  module ConnectionAdapters #:nodoc:
5
5
  module OracleEnhanced #:nodoc:
6
6
  class SchemaDumper < ConnectionAdapters::SchemaDumper #:nodoc:
7
+ DEFAULT_PRIMARY_KEY_COLUMN_SPEC = { precision: "38", null: "false" }.freeze
8
+ private_constant :DEFAULT_PRIMARY_KEY_COLUMN_SPEC
9
+
7
10
  private
11
+ def column_spec_for_primary_key(column)
12
+ spec = super
13
+ spec.except!(:precision) if prepare_column_options(column) == DEFAULT_PRIMARY_KEY_COLUMN_SPEC
14
+ spec
15
+ end
8
16
 
9
17
  def tables(stream)
10
18
  # do not include materialized views in schema dump - they should be created separately after schema creation
@@ -51,6 +59,7 @@ module ActiveRecord #:nodoc:
51
59
  else
52
60
  statement_parts = [ ("add_context_index " + remove_prefix_and_suffix(table).inspect) ]
53
61
  statement_parts << index.columns.inspect
62
+ statement_parts << ("sync: " + $1.inspect) if index.parameters =~ /SYNC\((.*?)\)/
54
63
  statement_parts << ("name: " + index.name.inspect)
55
64
  end
56
65
  else
@@ -72,7 +81,7 @@ module ActiveRecord #:nodoc:
72
81
  index_statements = indexes.map do |index|
73
82
  " t.index #{index_parts(index).join(', ')}" unless index.type == "CTXSYS.CONTEXT"
74
83
  end
75
- stream.puts index_statements.sort.join("\n")
84
+ stream.puts index_statements.compact.sort.join("\n")
76
85
  end
77
86
  end
78
87
 
@@ -107,7 +116,10 @@ module ActiveRecord #:nodoc:
107
116
  tbl.print ", primary_key: #{pk.inspect}" unless pk == "id"
108
117
  pkcol = columns.detect { |c| c.name == pk }
109
118
  pkcolspec = column_spec_for_primary_key(pkcol)
110
- if pkcolspec.present?
119
+ unless pkcolspec.empty?
120
+ if pkcolspec != pkcolspec.slice(:id, :default)
121
+ pkcolspec = { id: { type: pkcolspec.delete(:id), **pkcolspec }.compact }
122
+ end
111
123
  tbl.print ", #{format_colspec(pkcolspec)}"
112
124
  end
113
125
  when Array
@@ -168,7 +180,7 @@ module ActiveRecord #:nodoc:
168
180
 
169
181
  def extract_expression_for_virtual_column(column)
170
182
  column_name = column.name
171
- @connection.select_value(<<~SQL.squish, "Table comment", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
183
+ @connection.select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
172
184
  select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ data_default from all_tab_columns
173
185
  where owner = SYS_CONTEXT('userenv', 'current_schema')
174
186
  and table_name = :table_name