activerecord-oracle_enhanced-adapter 6.0.6 → 6.1.0.rc1

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 (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
@@ -8,9 +8,8 @@ module ActiveRecord #:nodoc:
8
8
  STATEMENT_TOKEN = "\n\n/\n\n"
9
9
 
10
10
  def structure_dump #:nodoc:
11
- sequences = select(<<~SQL.squish, "sequences to dump at structure dump")
12
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
13
- sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag
11
+ sequences = select(<<~SQL.squish, "SCHEMA")
12
+ SELECT sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag
14
13
  FROM all_sequences
15
14
  where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
16
15
  SQL
@@ -18,8 +17,8 @@ module ActiveRecord #:nodoc:
18
17
  structure = sequences.map do |result|
19
18
  "CREATE SEQUENCE #{quote_table_name(result["sequence_name"])} MINVALUE #{result["min_value"]} MAXVALUE #{result["max_value"]} INCREMENT BY #{result["increment_by"]} #{result["order_flag"] == 'Y' ? "ORDER" : "NOORDER"} #{result["cycle_flag"] == 'Y' ? "CYCLE" : "NOCYCLE"}"
20
19
  end
21
- tables = select_values(<<~SQL.squish, "tables at structure dump")
22
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables t
20
+ tables = select_values(<<~SQL.squish, "SCHEMA")
21
+ SELECT table_name FROM all_tables t
23
22
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
24
23
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
25
24
  WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
@@ -30,8 +29,8 @@ module ActiveRecord #:nodoc:
30
29
  tables.each do |table_name|
31
30
  virtual_columns = virtual_columns_for(table_name) if supports_virtual_columns?
32
31
  ddl = +"CREATE#{ ' GLOBAL TEMPORARY' if temporary_table?(table_name)} TABLE \"#{table_name}\" (\n"
33
- columns = select_all(<<~SQL.squish, "columns at structure dump")
34
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_type, data_length, char_used, char_length,
32
+ columns = select_all(<<~SQL.squish, "SCHEMA")
33
+ SELECT column_name, data_type, data_length, char_used, char_length,
35
34
  data_precision, data_scale, data_default, nullable
36
35
  FROM all_tab_columns
37
36
  WHERE table_name = '#{table_name}'
@@ -55,9 +54,8 @@ module ActiveRecord #:nodoc:
55
54
  structure << structure_dump_column_comments(table_name)
56
55
  end
57
56
 
58
- join_with_statement_token(structure) <<
59
- structure_dump_fk_constraints <<
60
- structure_dump_views
57
+ join_with_statement_token(structure) << structure_dump_fk_constraints
58
+ join_with_statement_token(structure) << structure_dump_views
61
59
  end
62
60
 
63
61
  def structure_dump_column(column) #:nodoc:
@@ -91,8 +89,8 @@ module ActiveRecord #:nodoc:
91
89
 
92
90
  def structure_dump_primary_key(table) #:nodoc:
93
91
  opts = { name: "", cols: [] }
94
- pks = select_all(<<~SQL.squish, "Primary Keys")
95
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
92
+ pks = select_all(<<~SQL.squish, "SCHEMA")
93
+ SELECT a.constraint_name, a.column_name, a.position
96
94
  FROM all_cons_columns a
97
95
  JOIN all_constraints c
98
96
  ON a.constraint_name = c.constraint_name
@@ -110,8 +108,8 @@ module ActiveRecord #:nodoc:
110
108
 
111
109
  def structure_dump_unique_keys(table) #:nodoc:
112
110
  keys = {}
113
- uks = select_all(<<~SQL.squish, "Primary Keys")
114
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
111
+ uks = select_all(<<~SQL.squish, "SCHEMA")
112
+ SELECT a.constraint_name, a.column_name, a.position
115
113
  FROM all_cons_columns a
116
114
  JOIN all_constraints c
117
115
  ON a.constraint_name = c.constraint_name
@@ -146,8 +144,8 @@ module ActiveRecord #:nodoc:
146
144
  end
147
145
 
148
146
  def structure_dump_fk_constraints #:nodoc:
149
- foreign_keys = select_all(<<~SQL.squish, "foreign keys at structure dump")
150
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
147
+ foreign_keys = select_all(<<~SQL.squish, "SCHEMA")
148
+ SELECT table_name FROM all_tables
151
149
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
152
150
  SQL
153
151
  fks = foreign_keys.map do |table|
@@ -174,8 +172,8 @@ module ActiveRecord #:nodoc:
174
172
 
175
173
  def structure_dump_column_comments(table_name)
176
174
  comments = []
177
- columns = select_values(<<~SQL.squish, "column comments at structure dump")
178
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name FROM user_tab_columns
175
+ columns = select_values(<<~SQL.squish, "SCHEMA")
176
+ SELECT column_name FROM user_tab_columns
179
177
  WHERE table_name = '#{table_name}' ORDER BY column_id
180
178
  SQL
181
179
 
@@ -208,8 +206,8 @@ module ActiveRecord #:nodoc:
208
206
  # Extract all stored procedures, packages, synonyms.
209
207
  def structure_dump_db_stored_code #:nodoc:
210
208
  structure = []
211
- all_source = select_all(<<~SQL.squish, "stored program at structure dump")
212
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ DISTINCT name, type
209
+ all_source = select_all(<<~SQL.squish, "SCHEMA")
210
+ SELECT DISTINCT name, type
213
211
  FROM all_source
214
212
  WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE')
215
213
  AND name NOT LIKE 'BIN$%'
@@ -218,7 +216,7 @@ module ActiveRecord #:nodoc:
218
216
  all_source.each do |source|
219
217
  ddl = +"CREATE OR REPLACE \n"
220
218
  texts = select_all(<<~SQL.squish, "all source at structure dump")
221
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text
219
+ SELECT text
222
220
  FROM all_source
223
221
  WHERE name = '#{source['name']}'
224
222
  AND type = '#{source['type']}'
@@ -240,8 +238,8 @@ module ActiveRecord #:nodoc:
240
238
 
241
239
  def structure_dump_views #:nodoc:
242
240
  structure = []
243
- views = select_all(<<~SQL.squish, "views at structure dump")
244
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ view_name, text FROM all_views
241
+ views = select_all(<<~SQL.squish, "SCHEMA")
242
+ SELECT view_name, text FROM all_views
245
243
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY view_name ASC
246
244
  SQL
247
245
  views.each do |view|
@@ -252,8 +250,8 @@ module ActiveRecord #:nodoc:
252
250
 
253
251
  def structure_dump_synonyms #:nodoc:
254
252
  structure = []
255
- synonyms = select_all(<<~SQL.squish, "synonyms at structure dump")
256
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, synonym_name, table_name, table_owner
253
+ synonyms = select_all(<<~SQL.squish, "SCHEMA")
254
+ SELECT owner, synonym_name, table_name, table_owner
257
255
  FROM all_synonyms
258
256
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
259
257
  SQL
@@ -265,15 +263,14 @@ module ActiveRecord #:nodoc:
265
263
  end
266
264
 
267
265
  def structure_drop #:nodoc:
268
- sequences = select_values(<<~SQL.squish, "sequences to drop at structure dump")
269
- SELECT/*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
270
- sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
266
+ sequences = select_values(<<~SQL.squish, "SCHEMA")
267
+ SELECT sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
271
268
  SQL
272
269
  statements = sequences.map do |seq|
273
270
  "DROP SEQUENCE \"#{seq}\""
274
271
  end
275
- tables = select_values(<<~SQL.squish, "tables to drop at structure dump")
276
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name from all_tables t
272
+ tables = select_values(<<~SQL.squish, "SCHEMA")
273
+ SELECT table_name from all_tables t
277
274
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
278
275
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
279
276
  WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
@@ -288,8 +285,8 @@ module ActiveRecord #:nodoc:
288
285
  end
289
286
 
290
287
  def temp_table_drop #:nodoc:
291
- temporary_tables = select_values(<<~SQL.squish, "temporary tables to drop at structure dump")
292
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
288
+ temporary_tables = select_values(<<~SQL.squish, "SCHEMA")
289
+ SELECT table_name FROM all_tables
293
290
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
294
291
  AND secondary = 'N' AND temporary = 'Y' ORDER BY 1
295
292
  SQL
@@ -319,12 +316,11 @@ module ActiveRecord #:nodoc:
319
316
  end
320
317
 
321
318
  private
322
-
323
319
  # Called only if `supports_virtual_columns?` returns true
324
320
  # return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...]
325
321
  def virtual_columns_for(table)
326
- select_all(<<~SQL.squish, "virtual columns for")
327
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_default
322
+ select_all(<<~SQL.squish, "SCHEMA")
323
+ SELECT column_name, data_default
328
324
  FROM all_tab_cols
329
325
  WHERE virtual_column = 'YES'
330
326
  AND owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -334,8 +330,8 @@ module ActiveRecord #:nodoc:
334
330
 
335
331
  def drop_sql_for_feature(type)
336
332
  short_type = type == "materialized view" ? "mview" : type
337
- features = select_values(<<~SQL.squish, "features to drop")
338
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ #{short_type}_name FROM all_#{short_type.tableize}
333
+ features = select_values(<<~SQL.squish, "SCHEMA")
334
+ SELECT #{short_type}_name FROM all_#{short_type.tableize}
339
335
  where owner = SYS_CONTEXT('userenv', 'current_schema')
340
336
  SQL
341
337
  statements = features.map do |name|
@@ -345,8 +341,8 @@ module ActiveRecord #:nodoc:
345
341
  end
346
342
 
347
343
  def drop_sql_for_object(type)
348
- objects = select_values(<<~SQL.squish, "objects to drop")
349
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ object_name FROM all_objects
344
+ objects = select_values(<<~SQL.squish, "SCHEMA")
345
+ SELECT object_name FROM all_objects
350
346
  WHERE object_type = '#{type.upcase}' and owner = SYS_CONTEXT('userenv', 'current_schema')
351
347
  SQL
352
348
  statements = objects.map do |name|
@@ -4,6 +4,8 @@ module ActiveRecord
4
4
  module ConnectionAdapters #:nodoc:
5
5
  module OracleEnhanced
6
6
  class TypeMetadata < DelegateClass(ActiveRecord::ConnectionAdapters::SqlTypeMetadata) # :nodoc:
7
+ include Deduplicable
8
+
7
9
  attr_reader :virtual
8
10
 
9
11
  def initialize(type_metadata, virtual: nil)
@@ -23,7 +25,6 @@ module ActiveRecord
23
25
  end
24
26
 
25
27
  protected
26
-
27
28
  def attributes_for_hash
28
29
  [self.class, @type_metadata, virtual]
29
30
  end
@@ -30,6 +30,9 @@
30
30
  # contribution.
31
31
  # portions Copyright 2005 Graham Jenkins
32
32
 
33
+ require "arel/visitors/oracle"
34
+ require "arel/visitors/oracle12"
35
+ require "active_record/connection_adapters"
33
36
  require "active_record/connection_adapters/abstract_adapter"
34
37
  require "active_record/connection_adapters/statement_pool"
35
38
  require "active_record/connection_adapters/oracle_enhanced/connection"
@@ -213,13 +216,24 @@ module ActiveRecord
213
216
  cattr_accessor :use_shorter_identifier
214
217
  self.use_shorter_identifier = false
215
218
 
219
+ ##
220
+ # :singleton-method:
221
+ # By default, OracleEnhanced adapter will grant unlimited tablespace, create session, create table, create view,
222
+ # and create sequence when running the rake task db:create.
223
+ #
224
+ # If you wish to change these permissions you can add the following line to your initializer file:
225
+ #
226
+ # ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.permissions =
227
+ # ["create session", "create table", "create view", "create sequence", "create trigger", "ctxapp"]
228
+ cattr_accessor :permissions
229
+ self.permissions = ["create session", "create table", "create view", "create sequence"]
230
+
216
231
  ##
217
232
  # :singleton-method:
218
233
  # Specify default sequence start with value (by default 1 if not explicitly set), e.g.:
219
234
 
220
235
  class StatementPool < ConnectionAdapters::StatementPool
221
236
  private
222
-
223
237
  def dealloc(stmt)
224
238
  stmt.close
225
239
  end
@@ -238,6 +252,14 @@ module ActiveRecord
238
252
  ADAPTER_NAME
239
253
  end
240
254
 
255
+ # Oracle enhanced adapter has no implementation because
256
+ # Oracle Database cannot detect `NoDatabaseError`.
257
+ # Please refer to the following discussion for details.
258
+ # https://github.com/rsim/oracle-enhanced/pull/1900
259
+ def self.database_exists?(config)
260
+ raise NotImplementedError
261
+ end
262
+
241
263
  def arel_visitor # :nodoc:
242
264
  if supports_fetch_first_n_rows_and_offset?
243
265
  Arel::Visitors::Oracle12.new(self)
@@ -266,6 +288,10 @@ module ActiveRecord
266
288
  true
267
289
  end
268
290
 
291
+ def supports_common_table_expressions?
292
+ true
293
+ end
294
+
269
295
  def supports_views?
270
296
  true
271
297
  end
@@ -438,6 +464,7 @@ module ActiveRecord
438
464
  end
439
465
 
440
466
  def discard!
467
+ super
441
468
  @connection = nil
442
469
  end
443
470
 
@@ -451,7 +478,7 @@ module ActiveRecord
451
478
  # if sequence_name is set to :autogenerated then it means that primary key will be populated by trigger
452
479
  raise ArgumentError.new "Trigger based primary key is not supported" if sequence_name == AUTOGENERATED_SEQUENCE_NAME
453
480
  # call directly connection method to avoid prepared statement which causes fetching of next sequence value twice
454
- select_value(<<~SQL.squish, "next sequence value")
481
+ select_value(<<~SQL.squish, "SCHEMA")
455
482
  SELECT #{quote_table_name(sequence_name)}.NEXTVAL FROM dual
456
483
  SQL
457
484
  end
@@ -489,7 +516,7 @@ module ActiveRecord
489
516
  end
490
517
 
491
518
  if primary_key && sequence_name
492
- new_start_value = select_value(<<~SQL.squish, "new start value")
519
+ new_start_value = select_value(<<~SQL.squish, "SCHEMA")
493
520
  select NVL(max(#{quote_column_name(primary_key)}),0) + 1 from #{quote_table_name(table_name)}
494
521
  SQL
495
522
 
@@ -500,33 +527,33 @@ module ActiveRecord
500
527
 
501
528
  # Current database name
502
529
  def current_database
503
- select_value(<<~SQL.squish, "current database on CDB ")
530
+ select_value(<<~SQL.squish, "SCHEMA")
504
531
  SELECT SYS_CONTEXT('userenv', 'con_name') FROM dual
505
532
  SQL
506
533
  rescue ActiveRecord::StatementInvalid
507
- select_value(<<~SQL.squish, "current database")
534
+ select_value(<<~SQL.squish, "SCHEMA")
508
535
  SELECT SYS_CONTEXT('userenv', 'db_name') FROM dual
509
536
  SQL
510
537
  end
511
538
 
512
539
  # Current database session user
513
540
  def current_user
514
- select_value(<<~SQL.squish, "current user")
541
+ select_value(<<~SQL.squish, "SCHEMA")
515
542
  SELECT SYS_CONTEXT('userenv', 'session_user') FROM dual
516
543
  SQL
517
544
  end
518
545
 
519
546
  # Current database session schema
520
547
  def current_schema
521
- select_value(<<~SQL.squish, "current schema")
548
+ select_value(<<~SQL.squish, "SCHEMA")
522
549
  SELECT SYS_CONTEXT('userenv', 'current_schema') FROM dual
523
550
  SQL
524
551
  end
525
552
 
526
553
  # Default tablespace name of current user
527
554
  def default_tablespace
528
- select_value(<<~SQL.squish, "default tablespace")
529
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ LOWER(default_tablespace) FROM user_users
555
+ select_value(<<~SQL.squish, "SCHEMA")
556
+ SELECT LOWER(default_tablespace) FROM user_users
530
557
  WHERE username = SYS_CONTEXT('userenv', 'current_schema')
531
558
  SQL
532
559
  end
@@ -534,8 +561,8 @@ module ActiveRecord
534
561
  def column_definitions(table_name)
535
562
  (owner, desc_table_name) = @connection.describe(table_name)
536
563
 
537
- select_all(<<~SQL.squish, "Column definitions")
538
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cols.column_name AS name, cols.data_type AS sql_type,
564
+ select_all(<<~SQL.squish, "SCHEMA")
565
+ SELECT cols.column_name AS name, cols.data_type AS sql_type,
539
566
  cols.data_default, cols.nullable, cols.virtual_column, cols.hidden_column,
540
567
  cols.data_type_owner AS sql_type_owner,
541
568
  DECODE(cols.data_type, 'NUMBER', data_precision,
@@ -566,16 +593,16 @@ module ActiveRecord
566
593
  def pk_and_sequence_for(table_name, owner = nil, desc_table_name = nil) #:nodoc:
567
594
  (owner, desc_table_name) = @connection.describe(table_name)
568
595
 
569
- seqs = select_values(<<~SQL.squish, "Sequence")
570
- select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ us.sequence_name
596
+ seqs = select_values(<<~SQL.squish, "SCHEMA")
597
+ select us.sequence_name
571
598
  from all_sequences us
572
599
  where us.sequence_owner = '#{owner}'
573
600
  and us.sequence_name = upper(#{quote(default_sequence_name(desc_table_name))})
574
601
  SQL
575
602
 
576
603
  # changed back from user_constraints to all_constraints for consistency
577
- pks = select_values(<<~SQL.squish, "Primary Key")
578
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cc.column_name
604
+ pks = select_values(<<~SQL.squish, "SCHEMA")
605
+ SELECT cc.column_name
579
606
  FROM all_constraints c, all_cons_columns cc
580
607
  WHERE c.owner = '#{owner}'
581
608
  AND c.table_name = #{quote(desc_table_name)}
@@ -608,8 +635,8 @@ module ActiveRecord
608
635
  def primary_keys(table_name) # :nodoc:
609
636
  (_owner, desc_table_name) = @connection.describe(table_name)
610
637
 
611
- pks = select_values(<<~SQL.squish, "Primary Keys", [bind_string("table_name", desc_table_name)])
612
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cc.column_name
638
+ pks = select_values(<<~SQL.squish, "SCHEMA", [bind_string("table_name", desc_table_name)])
639
+ SELECT cc.column_name
613
640
  FROM all_constraints c, all_cons_columns cc
614
641
  WHERE c.owner = SYS_CONTEXT('userenv', 'current_schema')
615
642
  AND c.table_name = :table_name
@@ -628,7 +655,7 @@ module ActiveRecord
628
655
  #
629
656
  # It does not construct DISTINCT clause. Just return column names for distinct.
630
657
  order_columns = orders.reject(&:blank?).map { |s|
631
- s = s.to_sql unless s.is_a?(String)
658
+ s = visitor.compile(s) unless s.is_a?(String)
632
659
  # remove any ASC/DESC modifiers
633
660
  s.gsub(/\s+(ASC|DESC)\s*?/i, "")
634
661
  }.reject(&:blank?).map.with_index { |column, i|
@@ -638,9 +665,8 @@ module ActiveRecord
638
665
  end
639
666
 
640
667
  def temporary_table?(table_name) #:nodoc:
641
- select_value(<<~SQL.squish, "temporary table", [bind_string("table_name", table_name.upcase)]) == "Y"
642
- SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
643
- temporary FROM all_tables WHERE table_name = :table_name and owner = SYS_CONTEXT('userenv', 'current_schema')
668
+ select_value(<<~SQL.squish, "SCHEMA", [bind_string("table_name", table_name.upcase)]) == "Y"
669
+ SELECT temporary FROM all_tables WHERE table_name = :table_name and owner = SYS_CONTEXT('userenv', 'current_schema')
644
670
  SQL
645
671
  end
646
672
 
@@ -748,25 +774,17 @@ module ActiveRecord
748
774
  autoload :OracleEnhancedProcedures, "active_record/connection_adapters/oracle_enhanced/procedures"
749
775
  end
750
776
 
751
- # Backport #2070 into relese60 branch by adding some dirty monkey patch
752
- # Because #2002 has been merged to release61 branch or newer, not available for release60 branch.
753
- module Arel # :nodoc: all
754
- module Visitors
755
- class Oracle < Arel::Visitors::ToSql
756
- private
757
- def build_subselect(key, o)
758
- stmt = super
759
- stmt.orders = [] # `orders` will never be set to prevent `ORA-00907`.
760
- stmt
761
- end
762
- end
763
- class Oracle12 < Arel::Visitors::ToSql
764
- private
765
- def build_subselect(key, o)
766
- stmt = super
767
- stmt.orders = [] # `orders` will never be set to prevent `ORA-00907`.
768
- stmt
769
- end
777
+ # Workaround for https://github.com/jruby/jruby/issues/6267
778
+ if RUBY_ENGINE == "jruby"
779
+ require "jruby"
780
+
781
+ class org.jruby::RubyObjectSpace::WeakMap
782
+ field_reader :map
783
+ end
784
+
785
+ class ObjectSpace::WeakMap
786
+ def values
787
+ JRuby.ref(self).map.values.reject(&:nil?)
770
788
  end
771
789
  end
772
790
  end
@@ -5,7 +5,6 @@ module ActiveRecord
5
5
  module OracleEnhanced
6
6
  class Boolean < ActiveModel::Type::Boolean # :nodoc:
7
7
  private
8
-
9
8
  def cast_value(value)
10
9
  # Kind of adding 'n' and 'N' to `FALSE_VALUES`
11
10
  if ["n", "N"].include?(value)
@@ -5,7 +5,6 @@ module ActiveRecord
5
5
  module OracleEnhanced
6
6
  class Integer < ActiveModel::Type::Integer # :nodoc:
7
7
  private
8
-
9
8
  def max_value
10
9
  ("9" * 38).to_i
11
10
  end