activerecord-oracle_enhanced-adapter 6.0.4 → 6.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecb6a81d928e0b751feb92c6eddbf1f11ae67ff269430216611f0d8871a3de7f
4
- data.tar.gz: 345cfa5a563fdb93d59404b13177bdf39f837f3d3338956b5b242ba85d95cca0
3
+ metadata.gz: 5c17fca6feaefdeefe04446c769a721e5f26b6f2ed254bef6f3bdee85a66b222
4
+ data.tar.gz: 5d975d115515ccbacb1b540dc8ece885f218213128d462536df3023b0112bbe2
5
5
  SHA512:
6
- metadata.gz: 44789c82df86d977714f00ef4a90b08c2d554c9e9b0cd3e2f39854ed89e69c02ade149990d1c16fe0630e91f0b13960e5263340d430e182f05791cabbb82d515
7
- data.tar.gz: c1dad68beacf2a519ab0819b41c3249902f64b6ba61c440aa0cc8f566d0e9820e12a4f45d2dd52e733a076c267016cf9fa895f7774f8b36c19c756b375f55a6b
6
+ metadata.gz: a736592361bc80d4930bbd0a2b21680dd1458400c66832c401f164c1effe9179e5a0771c5877b70df6286ef05ec81f71d8f1a96b1479c43f1b3f9d2b7d46c55e
7
+ data.tar.gz: 158dd74c1af746d0295b593ad62bedaa656374740151b4fb99342d9f33eedef8ed85f42b3e9622ab9289938f1b62c8e37a4eeca87f39a2779a42081e65d09bb4
data/History.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## 6.0.5 / 2020-12-17
2
+
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]
7
+
1
8
  ## 6.0.4 / 2020-08-18
2
9
 
3
10
  * Changes and bug fixes
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.0.4
1
+ 6.0.5
@@ -35,7 +35,7 @@ module ActiveRecord
35
35
  table_owner, table_name = default_owner, real_name
36
36
  end
37
37
  sql = <<~SQL.squish
38
- SELECT owner, table_name, 'TABLE' name_type
38
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, table_name, 'TABLE' name_type
39
39
  FROM all_tables
40
40
  WHERE owner = '#{table_owner}'
41
41
  AND table_name = '#{table_name}'
@@ -169,7 +169,7 @@ module ActiveRecord #:nodoc:
169
169
  def extract_expression_for_virtual_column(column)
170
170
  column_name = column.name
171
171
  @connection.select_value(<<~SQL.squish, "Table comment", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
172
- select data_default from all_tab_columns
172
+ select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ data_default from all_tab_columns
173
173
  where owner = SYS_CONTEXT('userenv', 'current_schema')
174
174
  and table_name = :table_name
175
175
  and column_name = :column_name
@@ -12,7 +12,8 @@ module ActiveRecord
12
12
 
13
13
  def tables #:nodoc:
14
14
  select_values(<<~SQL.squish, "tables")
15
- SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name)
15
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
16
+ DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name)
16
17
  FROM all_tables
17
18
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
18
19
  AND secondary = 'N'
@@ -44,7 +45,7 @@ module ActiveRecord
44
45
  end
45
46
 
46
47
  select_values(<<~SQL.squish, "table exists", [bind_string("owner", table_owner), bind_string("table_name", table_name)]).any?
47
- SELECT owner, table_name
48
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, table_name
48
49
  FROM all_tables
49
50
  WHERE owner = :owner
50
51
  AND table_name = :table_name
@@ -60,20 +61,22 @@ module ActiveRecord
60
61
 
61
62
  def views # :nodoc:
62
63
  select_values(<<~SQL.squish, "views")
63
- SELECT LOWER(view_name) FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
64
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
65
+ LOWER(view_name) FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
64
66
  SQL
65
67
  end
66
68
 
67
69
  def materialized_views #:nodoc:
68
70
  select_values(<<~SQL.squish, "materialized views")
69
- SELECT LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
71
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
72
+ LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
70
73
  SQL
71
74
  end
72
75
 
73
76
  # get synonyms for schema dump
74
77
  def synonyms
75
78
  result = select_all(<<~SQL.squish, "synonyms")
76
- SELECT synonym_name, table_owner, table_name
79
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ synonym_name, table_owner, table_name
77
80
  FROM all_synonyms where owner = SYS_CONTEXT('userenv', 'current_schema')
78
81
  SQL
79
82
 
@@ -88,7 +91,7 @@ module ActiveRecord
88
91
  default_tablespace_name = default_tablespace
89
92
 
90
93
  result = select_all(<<~SQL.squish, "indexes", [bind_string("table_name", table_name)])
91
- SELECT LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness,
94
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness,
92
95
  i.index_type, i.ityp_owner, i.ityp_name, i.parameters,
93
96
  LOWER(i.tablespace_name) AS tablespace_name,
94
97
  LOWER(c.column_name) AS column_name, e.column_expression,
@@ -118,7 +121,7 @@ module ActiveRecord
118
121
  if row["index_type"] == "DOMAIN" && row["ityp_owner"] == "CTXSYS" && row["ityp_name"] == "CONTEXT"
119
122
  procedure_name = default_datastore_procedure(row["index_name"])
120
123
  source = select_values(<<~SQL.squish, "procedure", [bind_string("procedure_name", procedure_name.upcase)]).join
121
- SELECT text
124
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text
122
125
  FROM all_source
123
126
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
124
127
  AND name = :procedure_name
@@ -362,7 +365,7 @@ module ActiveRecord
362
365
  def index_name_exists?(table_name, index_name)
363
366
  (_owner, table_name) = @connection.describe(table_name)
364
367
  result = select_value(<<~SQL.squish, "index name exists")
365
- SELECT 1 FROM all_indexes i
368
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ 1 FROM all_indexes i
366
369
  WHERE i.owner = SYS_CONTEXT('userenv', 'current_schema')
367
370
  AND i.table_owner = SYS_CONTEXT('userenv', 'current_schema')
368
371
  AND i.table_name = '#{table_name}'
@@ -496,7 +499,7 @@ module ActiveRecord
496
499
  def table_comment(table_name) #:nodoc:
497
500
  (_owner, table_name) = @connection.describe(table_name)
498
501
  select_value(<<~SQL.squish, "Table comment", [bind_string("table_name", table_name)])
499
- SELECT comments FROM all_tab_comments
502
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_tab_comments
500
503
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
501
504
  AND table_name = :table_name
502
505
  SQL
@@ -512,7 +515,7 @@ module ActiveRecord
512
515
  # TODO: it does not exist in Abstract adapter
513
516
  (_owner, table_name) = @connection.describe(table_name)
514
517
  select_value(<<~SQL.squish, "Column comment", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
515
- SELECT comments FROM all_col_comments
518
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ comments FROM all_col_comments
516
519
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
517
520
  AND table_name = :table_name
518
521
  AND column_name = :column_name
@@ -529,7 +532,7 @@ module ActiveRecord
529
532
 
530
533
  def tablespace(table_name)
531
534
  select_value(<<~SQL.squish, "tablespace")
532
- SELECT tablespace_name
535
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ tablespace_name
533
536
  FROM all_tables
534
537
  WHERE table_name='#{table_name.to_s.upcase}'
535
538
  AND owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -541,7 +544,7 @@ module ActiveRecord
541
544
  (_owner, desc_table_name) = @connection.describe(table_name)
542
545
 
543
546
  fk_info = select_all(<<~SQL.squish, "Foreign Keys", [bind_string("desc_table_name", desc_table_name)])
544
- SELECT r.table_name to_table
547
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ r.table_name to_table
545
548
  ,rc.column_name references_column
546
549
  ,cc.column_name
547
550
  ,c.constraint_name name
@@ -583,7 +586,7 @@ module ActiveRecord
583
586
 
584
587
  def disable_referential_integrity(&block) #:nodoc:
585
588
  old_constraints = select_all(<<~SQL.squish, "Foreign Keys to disable and enable")
586
- SELECT constraint_name, owner, table_name
589
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ constraint_name, owner, table_name
587
590
  FROM all_constraints
588
591
  WHERE constraint_type = 'R'
589
592
  AND status = 'ENABLED'
@@ -699,7 +702,7 @@ module ActiveRecord
699
702
  return unless tablespace
700
703
 
701
704
  index_name = select_value(<<~SQL.squish, "Index name for primary key", [bind_string("table_name", table_name.upcase)])
702
- SELECT index_name FROM all_constraints
705
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ index_name FROM all_constraints
703
706
  WHERE table_name = :table_name
704
707
  AND constraint_type = 'P'
705
708
  AND owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -9,7 +9,8 @@ module ActiveRecord #:nodoc:
9
9
 
10
10
  def structure_dump #:nodoc:
11
11
  sequences = select(<<~SQL.squish, "sequences to dump at structure dump")
12
- SELECT sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag
12
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
13
+ sequence_name, min_value, max_value, increment_by, order_flag, cycle_flag
13
14
  FROM all_sequences
14
15
  where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
15
16
  SQL
@@ -18,7 +19,7 @@ module ActiveRecord #:nodoc:
18
19
  "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"}"
19
20
  end
20
21
  tables = select_values(<<~SQL.squish, "tables at structure dump")
21
- SELECT table_name FROM all_tables t
22
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables t
22
23
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
23
24
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
24
25
  WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
@@ -30,7 +31,7 @@ module ActiveRecord #:nodoc:
30
31
  virtual_columns = virtual_columns_for(table_name) if supports_virtual_columns?
31
32
  ddl = +"CREATE#{ ' GLOBAL TEMPORARY' if temporary_table?(table_name)} TABLE \"#{table_name}\" (\n"
32
33
  columns = select_all(<<~SQL.squish, "columns at structure dump")
33
- SELECT column_name, data_type, data_length, char_used, char_length,
34
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_type, data_length, char_used, char_length,
34
35
  data_precision, data_scale, data_default, nullable
35
36
  FROM all_tab_columns
36
37
  WHERE table_name = '#{table_name}'
@@ -90,7 +91,7 @@ module ActiveRecord #:nodoc:
90
91
  def structure_dump_primary_key(table) #:nodoc:
91
92
  opts = { name: "", cols: [] }
92
93
  pks = select_all(<<~SQL.squish, "Primary Keys")
93
- SELECT a.constraint_name, a.column_name, a.position
94
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
94
95
  FROM all_cons_columns a
95
96
  JOIN all_constraints c
96
97
  ON a.constraint_name = c.constraint_name
@@ -109,7 +110,7 @@ module ActiveRecord #:nodoc:
109
110
  def structure_dump_unique_keys(table) #:nodoc:
110
111
  keys = {}
111
112
  uks = select_all(<<~SQL.squish, "Primary Keys")
112
- SELECT a.constraint_name, a.column_name, a.position
113
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ a.constraint_name, a.column_name, a.position
113
114
  FROM all_cons_columns a
114
115
  JOIN all_constraints c
115
116
  ON a.constraint_name = c.constraint_name
@@ -145,7 +146,7 @@ module ActiveRecord #:nodoc:
145
146
 
146
147
  def structure_dump_fk_constraints #:nodoc:
147
148
  foreign_keys = select_all(<<~SQL.squish, "foreign keys at structure dump")
148
- SELECT table_name FROM all_tables
149
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
149
150
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
150
151
  SQL
151
152
  fks = foreign_keys.map do |table|
@@ -173,7 +174,7 @@ module ActiveRecord #:nodoc:
173
174
  def structure_dump_column_comments(table_name)
174
175
  comments = []
175
176
  columns = select_values(<<~SQL.squish, "column comments at structure dump")
176
- SELECT column_name FROM user_tab_columns
177
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name FROM user_tab_columns
177
178
  WHERE table_name = '#{table_name}' ORDER BY column_id
178
179
  SQL
179
180
 
@@ -207,7 +208,7 @@ module ActiveRecord #:nodoc:
207
208
  def structure_dump_db_stored_code #:nodoc:
208
209
  structure = []
209
210
  all_source = select_all(<<~SQL.squish, "stored program at structure dump")
210
- SELECT DISTINCT name, type
211
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ DISTINCT name, type
211
212
  FROM all_source
212
213
  WHERE type IN ('PROCEDURE', 'PACKAGE', 'PACKAGE BODY', 'FUNCTION', 'TRIGGER', 'TYPE')
213
214
  AND name NOT LIKE 'BIN$%'
@@ -216,7 +217,7 @@ module ActiveRecord #:nodoc:
216
217
  all_source.each do |source|
217
218
  ddl = +"CREATE OR REPLACE \n"
218
219
  texts = select_all(<<~SQL.squish, "all source at structure dump")
219
- SELECT text
220
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ text
220
221
  FROM all_source
221
222
  WHERE name = '#{source['name']}'
222
223
  AND type = '#{source['type']}'
@@ -239,7 +240,7 @@ module ActiveRecord #:nodoc:
239
240
  def structure_dump_views #:nodoc:
240
241
  structure = []
241
242
  views = select_all(<<~SQL.squish, "views at structure dump")
242
- SELECT view_name, text FROM all_views
243
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ view_name, text FROM all_views
243
244
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY view_name ASC
244
245
  SQL
245
246
  views.each do |view|
@@ -251,7 +252,7 @@ module ActiveRecord #:nodoc:
251
252
  def structure_dump_synonyms #:nodoc:
252
253
  structure = []
253
254
  synonyms = select_all(<<~SQL.squish, "synonyms at structure dump")
254
- SELECT owner, synonym_name, table_name, table_owner
255
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ owner, synonym_name, table_name, table_owner
255
256
  FROM all_synonyms
256
257
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
257
258
  SQL
@@ -264,13 +265,14 @@ module ActiveRecord #:nodoc:
264
265
 
265
266
  def structure_drop #:nodoc:
266
267
  sequences = select_values(<<~SQL.squish, "sequences to drop at structure dump")
267
- SELECT sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
268
+ SELECT/*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */
269
+ sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'current_schema') ORDER BY 1
268
270
  SQL
269
271
  statements = sequences.map do |seq|
270
272
  "DROP SEQUENCE \"#{seq}\""
271
273
  end
272
274
  tables = select_values(<<~SQL.squish, "tables to drop at structure dump")
273
- SELECT table_name from all_tables t
275
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name from all_tables t
274
276
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema') AND secondary = 'N'
275
277
  AND NOT EXISTS (SELECT mv.mview_name FROM all_mviews mv
276
278
  WHERE mv.owner = t.owner AND mv.mview_name = t.table_name)
@@ -286,7 +288,7 @@ module ActiveRecord #:nodoc:
286
288
 
287
289
  def temp_table_drop #:nodoc:
288
290
  temporary_tables = select_values(<<~SQL.squish, "temporary tables to drop at structure dump")
289
- SELECT table_name FROM all_tables
291
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ table_name FROM all_tables
290
292
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
291
293
  AND secondary = 'N' AND temporary = 'Y' ORDER BY 1
292
294
  SQL
@@ -321,7 +323,7 @@ module ActiveRecord #:nodoc:
321
323
  # return [{'column_name' => 'FOOS', 'data_default' => '...'}, ...]
322
324
  def virtual_columns_for(table)
323
325
  select_all(<<~SQL.squish, "virtual columns for")
324
- SELECT column_name, data_default
326
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ column_name, data_default
325
327
  FROM all_tab_cols
326
328
  WHERE virtual_column = 'YES'
327
329
  AND owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -332,7 +334,7 @@ module ActiveRecord #:nodoc:
332
334
  def drop_sql_for_feature(type)
333
335
  short_type = type == "materialized view" ? "mview" : type
334
336
  features = select_values(<<~SQL.squish, "features to drop")
335
- SELECT #{short_type}_name FROM all_#{short_type.tableize}
337
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ #{short_type}_name FROM all_#{short_type.tableize}
336
338
  where owner = SYS_CONTEXT('userenv', 'current_schema')
337
339
  SQL
338
340
  statements = features.map do |name|
@@ -343,7 +345,7 @@ module ActiveRecord #:nodoc:
343
345
 
344
346
  def drop_sql_for_object(type)
345
347
  objects = select_values(<<~SQL.squish, "objects to drop")
346
- SELECT object_name FROM all_objects
348
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ object_name FROM all_objects
347
349
  WHERE object_type = '#{type.upcase}' and owner = SYS_CONTEXT('userenv', 'current_schema')
348
350
  SQL
349
351
  statements = objects.map do |name|
@@ -449,7 +449,7 @@ module ActiveRecord
449
449
  # when inserting a new database record (see #prefetch_primary_key?).
450
450
  def next_sequence_value(sequence_name)
451
451
  # if sequence_name is set to :autogenerated then it means that primary key will be populated by trigger
452
- raise ArgumentError "Trigger based primary key is not supported" if sequence_name == AUTOGENERATED_SEQUENCE_NAME
452
+ raise ArgumentError.new "Trigger based primary key is not supported" if sequence_name == AUTOGENERATED_SEQUENCE_NAME
453
453
  # call directly connection method to avoid prepared statement which causes fetching of next sequence value twice
454
454
  select_value(<<~SQL.squish, "next sequence value")
455
455
  SELECT #{quote_table_name(sequence_name)}.NEXTVAL FROM dual
@@ -526,7 +526,7 @@ module ActiveRecord
526
526
  # Default tablespace name of current user
527
527
  def default_tablespace
528
528
  select_value(<<~SQL.squish, "default tablespace")
529
- SELECT LOWER(default_tablespace) FROM user_users
529
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ LOWER(default_tablespace) FROM user_users
530
530
  WHERE username = SYS_CONTEXT('userenv', 'current_schema')
531
531
  SQL
532
532
  end
@@ -535,7 +535,7 @@ module ActiveRecord
535
535
  (owner, desc_table_name) = @connection.describe(table_name)
536
536
 
537
537
  select_all(<<~SQL.squish, "Column definitions")
538
- SELECT cols.column_name AS name, cols.data_type AS sql_type,
538
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cols.column_name AS name, cols.data_type AS sql_type,
539
539
  cols.data_default, cols.nullable, cols.virtual_column, cols.hidden_column,
540
540
  cols.data_type_owner AS sql_type_owner,
541
541
  DECODE(cols.data_type, 'NUMBER', data_precision,
@@ -567,7 +567,7 @@ module ActiveRecord
567
567
  (owner, desc_table_name) = @connection.describe(table_name)
568
568
 
569
569
  seqs = select_values(<<~SQL.squish, "Sequence")
570
- select us.sequence_name
570
+ select /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ us.sequence_name
571
571
  from all_sequences us
572
572
  where us.sequence_owner = '#{owner}'
573
573
  and us.sequence_name = upper(#{quote(default_sequence_name(desc_table_name))})
@@ -575,7 +575,7 @@ module ActiveRecord
575
575
 
576
576
  # changed back from user_constraints to all_constraints for consistency
577
577
  pks = select_values(<<~SQL.squish, "Primary Key")
578
- SELECT cc.column_name
578
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cc.column_name
579
579
  FROM all_constraints c, all_cons_columns cc
580
580
  WHERE c.owner = '#{owner}'
581
581
  AND c.table_name = #{quote(desc_table_name)}
@@ -609,7 +609,7 @@ module ActiveRecord
609
609
  (_owner, desc_table_name) = @connection.describe(table_name)
610
610
 
611
611
  pks = select_values(<<~SQL.squish, "Primary Keys", [bind_string("table_name", desc_table_name)])
612
- SELECT cc.column_name
612
+ SELECT /*+ OPTIMIZER_FEATURES_ENABLE('11.2.0.2') */ cc.column_name
613
613
  FROM all_constraints c, all_cons_columns cc
614
614
  WHERE c.owner = SYS_CONTEXT('userenv', 'current_schema')
615
615
  AND c.table_name = :table_name
@@ -639,7 +639,8 @@ module ActiveRecord
639
639
 
640
640
  def temporary_table?(table_name) #:nodoc:
641
641
  select_value(<<~SQL.squish, "temporary table", [bind_string("table_name", table_name.upcase)]) == "Y"
642
- SELECT temporary FROM all_tables WHERE table_name = :table_name and owner = SYS_CONTEXT('userenv', 'current_schema')
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')
643
644
  SQL
644
645
  end
645
646
 
@@ -746,3 +747,26 @@ require "active_record/connection_adapters/oracle_enhanced/version"
746
747
  module ActiveRecord
747
748
  autoload :OracleEnhancedProcedures, "active_record/connection_adapters/oracle_enhanced/procedures"
748
749
  end
750
+
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
770
+ end
771
+ end
772
+ end
@@ -150,6 +150,45 @@ describe "OracleEnhancedAdapter" do
150
150
  end
151
151
  end
152
152
 
153
+ describe "`has_many` assoc has `dependent: :delete_all` with `order`" do
154
+ before(:all) do
155
+ schema_define do
156
+ create_table :test_posts do |t|
157
+ t.string :title
158
+ end
159
+ create_table :test_comments do |t|
160
+ t.integer :test_post_id
161
+ t.string :description
162
+ end
163
+ add_index :test_comments, :test_post_id
164
+ end
165
+ class ::TestPost < ActiveRecord::Base
166
+ has_many :test_comments, -> { order(:id) }, dependent: :delete_all
167
+ end
168
+ class ::TestComment < ActiveRecord::Base
169
+ belongs_to :test_post
170
+ end
171
+ TestPost.transaction do
172
+ post = TestPost.create!(title: "Title")
173
+ TestComment.create!(test_post_id: post.id, description: "Description")
174
+ end
175
+ end
176
+
177
+ after(:all) do
178
+ schema_define do
179
+ drop_table :test_comments
180
+ drop_table :test_posts
181
+ end
182
+ Object.send(:remove_const, "TestPost")
183
+ Object.send(:remove_const, "TestComment")
184
+ ActiveRecord::Base.clear_cache!
185
+ end
186
+
187
+ it "should not occur `ActiveRecord::StatementInvalid: OCIError: ORA-00907: missing right parenthesis`" do
188
+ expect { TestPost.first.destroy }.not_to raise_error
189
+ end
190
+ end
191
+
153
192
  describe "eager loading" do
154
193
  before(:all) do
155
194
  schema_define do
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.4
4
+ version: 6.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-18 00:00:00.000000000 Z
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  - !ruby/object:Gem::Version
136
136
  version: 1.8.11
137
137
  requirements: []
138
- rubygems_version: 3.1.2
138
+ rubygems_version: 3.1.4
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: Oracle enhanced adapter for ActiveRecord