activerecord-oracle_enhanced-adapter 6.0.0.beta1 → 6.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (23) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +25 -1
  3. data/VERSION +1 -1
  4. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +2 -2
  5. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +21 -21
  6. data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +57 -57
  7. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +3 -3
  8. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +5 -5
  9. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +5 -2
  10. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +41 -40
  11. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +35 -35
  12. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +26 -22
  13. data/spec/active_record/connection_adapters/oracle_enhanced/connection_spec.rb +1 -1
  14. data/spec/active_record/connection_adapters/oracle_enhanced/dbms_output_spec.rb +17 -17
  15. data/spec/active_record/connection_adapters/oracle_enhanced/procedures_spec.rb +2 -2
  16. data/spec/active_record/connection_adapters/oracle_enhanced/schema_dumper_spec.rb +1 -1
  17. data/spec/active_record/connection_adapters/oracle_enhanced/structure_dump_spec.rb +24 -24
  18. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +2 -2
  19. data/spec/active_record/oracle_enhanced/type/boolean_spec.rb +2 -2
  20. data/spec/active_record/oracle_enhanced/type/character_string_spec.rb +1 -1
  21. data/spec/active_record/oracle_enhanced/type/integer_spec.rb +2 -2
  22. data/spec/active_record/oracle_enhanced/type/national_character_string_spec.rb +1 -1
  23. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88d4ded25c413bd3ad25d89e39551c5709e070365d687c515bca47e8c8f327fa
4
- data.tar.gz: 7e3c7a298c9e4fed4a66c08a8085883ecaf52698841fdf91bbd5fc98213dac41
3
+ metadata.gz: 20b3aea35f3c42e8485b1b11ec0c5a549e0571b81522e5608abea0a6916d38f8
4
+ data.tar.gz: 53379822a99628e864639ed410712386bbf025de3c75ac5f9aa99e33fa0cf170
5
5
  SHA512:
6
- metadata.gz: 7c90e048c399283b8125ae3aa6929140ead8db07cab427894993445ceb09d0c0665080444a28be6e8609fb26387b5d6bca50f1de2623c090626e2b4275c01d74
7
- data.tar.gz: db3ff9ab3f530b13074bd7dc9cf2146c0da1756e9a8c57429567f1122716dc0bc03e5724e35cb7e0349830e686146379f404b554f265a3292850608043797b66
6
+ metadata.gz: 9c928e3b86ca4f34e45ad25ca37737f605fddfae4ae5b9205812f05079655a46fa748aa6f70d926b41269574bcc811bb297396ae60325a10211ffb3854b6b08e
7
+ data.tar.gz: 1e8e54cab8bb27dc6754f559a19ee5ed60dfcad8835b6352ffd60304cd122294f326bf02bf93bd458410f8d319d2e707457d09292a9bfde56dcddc041e53e0fd
data/History.md CHANGED
@@ -1,4 +1,28 @@
1
- ## 6.0.0.beta1 / 2018-03-18
1
+ ## 6.0.0.rc1 / 2019-04-25
2
+
3
+ * Major changes
4
+ * Support Rails 6.0.0 rc1
5
+ * Address `ORA-01795: maximum number of expressions in a list is 1000`
6
+ - These changes has been made to Rails itself [rails/rails#35838, rails/rails#36074]
7
+
8
+ * Changes and bug fixes
9
+ * Cache database version in schema cache [#1859]
10
+ * Except `table_name` from column objects [#1860]
11
+ * Remove unused `sequence_name` in `sql_for_insert` [#1861]
12
+ * Use squiggly heredoc to strip odd indentation in the executed SQL [#1869]
13
+ * Use Active Support `String#squish` instead of `String#strip.gsub` [#1871]
14
+
15
+ * CI
16
+ * Revert "Add `allow_railures` for jruby-head until #1833 resolved" [#1862]
17
+ * CI against JRuby 9.2.7.0 [#1864]
18
+ * Use newer Code Climate analysis model, version 2 [#1868]
19
+ * CI against Ruby 2.6.3 [#1870]
20
+
21
+ * RuboCop
22
+ * Bump RuboCop version to 0.67 [#1867]
23
+ * Enable `Layout/SpaceBeforeComment` cop [#1863]
24
+
25
+ ## 6.0.0.beta1 / 2019-03-18
2
26
 
3
27
  * Major changes
4
28
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 6.0.0.beta1
1
+ 6.0.0.rc1
@@ -6,8 +6,8 @@ module ActiveRecord
6
6
  class Column < ActiveRecord::ConnectionAdapters::Column
7
7
  delegate :virtual, to: :sql_type_metadata, allow_nil: true
8
8
 
9
- def initialize(name, default, sql_type_metadata = nil, null = true, table_name = nil, comment = nil) #:nodoc:
10
- super(name, default, sql_type_metadata, null, table_name, comment: comment)
9
+ def initialize(name, default, sql_type_metadata = nil, null = true, comment: nil) #:nodoc:
10
+ super(name, default, sql_type_metadata, null, comment: comment)
11
11
  end
12
12
 
13
13
  def virtual?
@@ -34,27 +34,27 @@ module ActiveRecord
34
34
  else
35
35
  table_owner, table_name = default_owner, real_name
36
36
  end
37
- sql = <<-SQL.strip.gsub(/\s+/, " ")
38
- SELECT owner, table_name, 'TABLE' name_type
39
- FROM all_tables
40
- WHERE owner = '#{table_owner}'
41
- AND table_name = '#{table_name}'
42
- UNION ALL
43
- SELECT owner, view_name table_name, 'VIEW' name_type
44
- FROM all_views
45
- WHERE owner = '#{table_owner}'
46
- AND view_name = '#{table_name}'
47
- UNION ALL
48
- SELECT table_owner, table_name, 'SYNONYM' name_type
49
- FROM all_synonyms
50
- WHERE owner = '#{table_owner}'
51
- AND synonym_name = '#{table_name}'
52
- UNION ALL
53
- SELECT table_owner, table_name, 'SYNONYM' name_type
54
- FROM all_synonyms
55
- WHERE owner = 'PUBLIC'
56
- AND synonym_name = '#{real_name}'
57
- SQL
37
+ sql = <<~SQL.squish
38
+ SELECT owner, table_name, 'TABLE' name_type
39
+ FROM all_tables
40
+ WHERE owner = '#{table_owner}'
41
+ AND table_name = '#{table_name}'
42
+ UNION ALL
43
+ SELECT owner, view_name table_name, 'VIEW' name_type
44
+ FROM all_views
45
+ WHERE owner = '#{table_owner}'
46
+ AND view_name = '#{table_name}'
47
+ UNION ALL
48
+ SELECT table_owner, table_name, 'SYNONYM' name_type
49
+ FROM all_synonyms
50
+ WHERE owner = '#{table_owner}'
51
+ AND synonym_name = '#{table_name}'
52
+ UNION ALL
53
+ SELECT table_owner, table_name, 'SYNONYM' name_type
54
+ FROM all_synonyms
55
+ WHERE owner = 'PUBLIC'
56
+ AND synonym_name = '#{real_name}'
57
+ SQL
58
58
  if result = _select_one(sql)
59
59
  case result["name_type"]
60
60
  when "SYNONYM"
@@ -149,56 +149,56 @@ module ActiveRecord
149
149
  select_queries = select_queries.map { |s| s.strip.gsub(/\s+/, " ") }
150
150
  keys, selected_columns = parse_select_queries(select_queries)
151
151
  quoted_column_names = (column_names + keys).map { |col| quote_column_name(col) }
152
- execute <<-SQL
153
- CREATE OR REPLACE PROCEDURE #{quote_table_name(procedure_name)}
154
- (p_rowid IN ROWID,
155
- p_clob IN OUT NOCOPY CLOB) IS
156
- -- add_context_index_parameters #{(column_names + select_queries).inspect}#{!options.empty? ? +', ' << options.inspect[1..-2] : ''}
157
- #{
158
- selected_columns.map do |cols|
159
- cols.map do |col|
160
- raise ArgumentError, "Alias #{col} too large, should be 28 or less characters long" unless col.length <= 28
161
- "l_#{col} VARCHAR2(32767);\n"
162
- end.join
163
- end.join
164
- } BEGIN
165
- FOR r1 IN (
166
- SELECT #{quoted_column_names.join(', ')}
167
- FROM #{quoted_table_name}
168
- WHERE #{quoted_table_name}.ROWID = p_rowid
169
- ) LOOP
152
+ execute <<~SQL
153
+ CREATE OR REPLACE PROCEDURE #{quote_table_name(procedure_name)}
154
+ (p_rowid IN ROWID,
155
+ p_clob IN OUT NOCOPY CLOB) IS
156
+ -- add_context_index_parameters #{(column_names + select_queries).inspect}#{!options.empty? ? +', ' << options.inspect[1..-2] : ''}
170
157
  #{
171
- (column_names.map do |col|
172
- col = col.to_s
173
- +"DBMS_LOB.WRITEAPPEND(p_clob, #{col.length + 2}, '<#{col}>');\n" <<
174
- "IF LENGTH(r1.#{col}) > 0 THEN\n" <<
175
- "DBMS_LOB.WRITEAPPEND(p_clob, LENGTH(r1.#{col}), r1.#{col});\n" <<
176
- "END IF;\n" <<
177
- "DBMS_LOB.WRITEAPPEND(p_clob, #{col.length + 3}, '</#{col}>');\n"
178
- end.join) <<
179
- (selected_columns.zip(select_queries).map do |cols, query|
180
- (cols.map do |col|
181
- "l_#{col} := '';\n"
182
- end.join) <<
183
- "FOR r2 IN (\n" <<
184
- query.gsub(/:(\w+)/, "r1.\\1") << "\n) LOOP\n" <<
185
- (cols.map do |col|
186
- "l_#{col} := l_#{col} || r2.#{col} || CHR(10);\n"
187
- end.join) <<
188
- "END LOOP;\n" <<
189
- (cols.map do |col|
158
+ selected_columns.map do |cols|
159
+ cols.map do |col|
160
+ raise ArgumentError, "Alias #{col} too large, should be 28 or less characters long" unless col.length <= 28
161
+ "l_#{col} VARCHAR2(32767);\n"
162
+ end.join
163
+ end.join
164
+ } BEGIN
165
+ FOR r1 IN (
166
+ SELECT #{quoted_column_names.join(', ')}
167
+ FROM #{quoted_table_name}
168
+ WHERE #{quoted_table_name}.ROWID = p_rowid
169
+ ) LOOP
170
+ #{
171
+ (column_names.map do |col|
190
172
  col = col.to_s
191
173
  +"DBMS_LOB.WRITEAPPEND(p_clob, #{col.length + 2}, '<#{col}>');\n" <<
192
- "IF LENGTH(l_#{col}) > 0 THEN\n" <<
193
- "DBMS_LOB.WRITEAPPEND(p_clob, LENGTH(l_#{col}), l_#{col});\n" <<
174
+ "IF LENGTH(r1.#{col}) > 0 THEN\n" <<
175
+ "DBMS_LOB.WRITEAPPEND(p_clob, LENGTH(r1.#{col}), r1.#{col});\n" <<
194
176
  "END IF;\n" <<
195
177
  "DBMS_LOB.WRITEAPPEND(p_clob, #{col.length + 3}, '</#{col}>');\n"
178
+ end.join) <<
179
+ (selected_columns.zip(select_queries).map do |cols, query|
180
+ (cols.map do |col|
181
+ "l_#{col} := '';\n"
182
+ end.join) <<
183
+ "FOR r2 IN (\n" <<
184
+ query.gsub(/:(\w+)/, "r1.\\1") << "\n) LOOP\n" <<
185
+ (cols.map do |col|
186
+ "l_#{col} := l_#{col} || r2.#{col} || CHR(10);\n"
187
+ end.join) <<
188
+ "END LOOP;\n" <<
189
+ (cols.map do |col|
190
+ col = col.to_s
191
+ +"DBMS_LOB.WRITEAPPEND(p_clob, #{col.length + 2}, '<#{col}>');\n" <<
192
+ "IF LENGTH(l_#{col}) > 0 THEN\n" <<
193
+ "DBMS_LOB.WRITEAPPEND(p_clob, LENGTH(l_#{col}), l_#{col});\n" <<
194
+ "END IF;\n" <<
195
+ "DBMS_LOB.WRITEAPPEND(p_clob, #{col.length + 3}, '</#{col}>');\n"
196
+ end.join)
196
197
  end.join)
197
- end.join)
198
- }
199
- END LOOP;
200
- END;
201
- SQL
198
+ }
199
+ END LOOP;
200
+ END;
201
+ SQL
202
202
  end
203
203
 
204
204
  def parse_select_queries(select_queries)
@@ -215,12 +215,12 @@ module ActiveRecord
215
215
 
216
216
  def create_datastore_preference(datastore_name, procedure_name)
217
217
  drop_ctx_preference(datastore_name)
218
- execute <<-SQL
219
- BEGIN
220
- CTX_DDL.CREATE_PREFERENCE('#{datastore_name}', 'USER_DATASTORE');
221
- CTX_DDL.SET_ATTRIBUTE('#{datastore_name}', 'PROCEDURE', '#{procedure_name}');
222
- END;
223
- SQL
218
+ execute <<~SQL
219
+ BEGIN
220
+ CTX_DDL.CREATE_PREFERENCE('#{datastore_name}', 'USER_DATASTORE');
221
+ CTX_DDL.SET_ATTRIBUTE('#{datastore_name}', 'PROCEDURE', '#{procedure_name}');
222
+ END;
223
+ SQL
224
224
  end
225
225
 
226
226
  def create_storage_preference(storage_name, tablespace)
@@ -281,13 +281,13 @@ module ActiveRecord
281
281
  trigger_name = default_index_column_trigger_name(index_name)
282
282
  columns = Array(index_column_source)
283
283
  quoted_column_names = columns.map { |col| quote_column_name(col) }.join(", ")
284
- execute <<-SQL
285
- CREATE OR REPLACE TRIGGER #{quote_table_name(trigger_name)}
286
- BEFORE UPDATE OF #{quoted_column_names} ON #{quote_table_name(table_name)} FOR EACH ROW
287
- BEGIN
288
- :new.#{quote_column_name(index_column)} := '1';
289
- END;
290
- SQL
284
+ execute <<~SQL
285
+ CREATE OR REPLACE TRIGGER #{quote_table_name(trigger_name)}
286
+ BEFORE UPDATE OF #{quoted_column_names} ON #{quote_table_name(table_name)} FOR EACH ROW
287
+ BEGIN
288
+ :new.#{quote_column_name(index_column)} := '1';
289
+ END;
290
+ SQL
291
291
  end
292
292
 
293
293
  def drop_index_column_trigger(index_name)
@@ -76,7 +76,7 @@ module ActiveRecord
76
76
 
77
77
  # New method in ActiveRecord 3.1
78
78
  # Will add RETURNING clause in case of trigger generated primary keys
79
- def sql_for_insert(sql, pk, sequence_name, binds)
79
+ def sql_for_insert(sql, pk, binds)
80
80
  unless pk == false || pk.nil? || pk.is_a?(Array)
81
81
  sql = "#{sql} RETURNING #{quote_column_name(pk)} INTO :returning_id"
82
82
  (binds = binds.dup) << ActiveRecord::Relation::QueryAttribute.new("returning_id", nil, Type::OracleEnhanced::Integer.new)
@@ -91,7 +91,7 @@ module ActiveRecord
91
91
 
92
92
  # New method in ActiveRecord 3.1
93
93
  def exec_insert(sql, name = nil, binds = [], pk = nil, sequence_name = nil)
94
- sql, binds = sql_for_insert(sql, pk, sequence_name, binds)
94
+ sql, binds = sql_for_insert(sql, pk, binds)
95
95
  type_casted_binds = type_casted_binds(binds)
96
96
 
97
97
  log(sql, name, binds, type_casted_binds) do
@@ -252,7 +252,7 @@ module ActiveRecord
252
252
  value = klass.attribute_types[col.name].serialize(value)
253
253
  end
254
254
  uncached do
255
- unless lob_record = select_one(<<-SQL.strip.gsub(/\s+/, " "), "Writable Large Object")
255
+ unless lob_record = select_one(<<~SQL.squish, "Writable Large Object")
256
256
  SELECT #{quote_column_name(col.name)} FROM #{quote_table_name(table_name)}
257
257
  WHERE #{quote_column_name(klass.primary_key)} = #{id} FOR UPDATE
258
258
  SQL
@@ -76,17 +76,17 @@ module ActiveRecord
76
76
  def action_sql(action, dependency)
77
77
  if action == "UPDATE"
78
78
  raise ArgumentError, <<~MSG
79
- '#{action}' is not supported by Oracle
80
- MSG
79
+ '#{action}' is not supported by Oracle
80
+ MSG
81
81
  end
82
82
  case dependency
83
83
  when :nullify then "ON #{action} SET NULL"
84
84
  when :cascade then "ON #{action} CASCADE"
85
85
  else
86
86
  raise ArgumentError, <<~MSG
87
- '#{dependency}' is not supported for #{action}
88
- Supported values are: :nullify, :cascade
89
- MSG
87
+ '#{dependency}' is not supported for #{action}
88
+ Supported values are: :nullify, :cascade
89
+ MSG
90
90
  end
91
91
  end
92
92
  end
@@ -85,6 +85,8 @@ module ActiveRecord #:nodoc:
85
85
  def table(table, stream)
86
86
  columns = @connection.columns(table)
87
87
  begin
88
+ self.table_name = table
89
+
88
90
  tbl = StringIO.new
89
91
 
90
92
  # first dump primary key column
@@ -144,6 +146,8 @@ module ActiveRecord #:nodoc:
144
146
  stream.puts "# Could not dump table #{table.inspect} because of following #{e.class}"
145
147
  stream.puts "# #{e.message}"
146
148
  stream.puts
149
+ ensure
150
+ self.table_name = nil
147
151
  end
148
152
  end
149
153
 
@@ -164,8 +168,7 @@ module ActiveRecord #:nodoc:
164
168
 
165
169
  def extract_expression_for_virtual_column(column)
166
170
  column_name = column.name
167
- table_name = column.table_name
168
- @connection.select_value(<<-SQL.strip.gsub(/\s+/, " "), "Table comment", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
171
+ @connection.select_value(<<~SQL.squish, "Table comment", [bind_string("table_name", table_name.upcase), bind_string("column_name", column_name.upcase)]).inspect
169
172
  select data_default from all_tab_columns
170
173
  where owner = SYS_CONTEXT('userenv', 'current_schema')
171
174
  and table_name = :table_name
@@ -11,16 +11,16 @@ module ActiveRecord
11
11
  # see: abstract/schema_statements.rb
12
12
 
13
13
  def tables #:nodoc:
14
- select_values(<<-SQL.strip.gsub(/\s+/, " "), "tables")
15
- SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name)
16
- FROM all_tables
17
- WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
18
- AND secondary = 'N'
19
- minus
20
- SELECT DECODE(mview_name, UPPER(mview_name), LOWER(mview_name), mview_name)
21
- FROM all_mviews
22
- WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
23
- SQL
14
+ select_values(<<~SQL.squish, "tables")
15
+ SELECT DECODE(table_name, UPPER(table_name), LOWER(table_name), table_name)
16
+ FROM all_tables
17
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
18
+ AND secondary = 'N'
19
+ minus
20
+ SELECT DECODE(mview_name, UPPER(mview_name), LOWER(mview_name), mview_name)
21
+ FROM all_mviews
22
+ WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
23
+ SQL
24
24
  end
25
25
 
26
26
  def data_sources
@@ -43,12 +43,12 @@ module ActiveRecord
43
43
  table_owner, table_name = default_owner, real_name
44
44
  end
45
45
 
46
- select_values(<<-SQL.strip.gsub(/\s+/, " "), "table exists", [bind_string("owner", table_owner), bind_string("table_name", table_name)]).any?
47
- SELECT owner, table_name
48
- FROM all_tables
49
- WHERE owner = :owner
50
- AND table_name = :table_name
51
- SQL
46
+ select_values(<<~SQL.squish, "table exists", [bind_string("owner", table_owner), bind_string("table_name", table_name)]).any?
47
+ SELECT owner, table_name
48
+ FROM all_tables
49
+ WHERE owner = :owner
50
+ AND table_name = :table_name
51
+ SQL
52
52
  end
53
53
 
54
54
  def data_source_exists?(table_name)
@@ -59,23 +59,23 @@ module ActiveRecord
59
59
  end
60
60
 
61
61
  def views # :nodoc:
62
- select_values(<<-SQL.strip.gsub(/\s+/, " "), "views")
62
+ select_values(<<~SQL.squish, "views")
63
63
  SELECT LOWER(view_name) FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
64
64
  SQL
65
65
  end
66
66
 
67
67
  def materialized_views #:nodoc:
68
- select_values(<<-SQL.strip.gsub(/\s+/, " "), "materialized views")
68
+ select_values(<<~SQL.squish, "materialized views")
69
69
  SELECT LOWER(mview_name) FROM all_mviews WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
70
70
  SQL
71
71
  end
72
72
 
73
73
  # get synonyms for schema dump
74
74
  def synonyms
75
- result = select_all(<<-SQL.strip.gsub(/\s+/, " "), "synonyms")
76
- SELECT synonym_name, table_owner, table_name
77
- FROM all_synonyms where owner = SYS_CONTEXT('userenv', 'current_schema')
78
- SQL
75
+ result = select_all(<<~SQL.squish, "synonyms")
76
+ SELECT synonym_name, table_owner, table_name
77
+ FROM all_synonyms where owner = SYS_CONTEXT('userenv', 'current_schema')
78
+ SQL
79
79
 
80
80
  result.collect do |row|
81
81
  OracleEnhanced::SynonymDefinition.new(oracle_downcase(row["synonym_name"]),
@@ -87,7 +87,7 @@ module ActiveRecord
87
87
  (_owner, table_name) = @connection.describe(table_name)
88
88
  default_tablespace_name = default_tablespace
89
89
 
90
- result = select_all(<<-SQL.strip.gsub(/\s+/, " "), "indexes", [bind_string("table_name", table_name)])
90
+ result = select_all(<<~SQL.squish, "indexes", [bind_string("table_name", table_name)])
91
91
  SELECT LOWER(i.table_name) AS table_name, LOWER(i.index_name) AS index_name, i.uniqueness,
92
92
  i.index_type, i.ityp_owner, i.ityp_name, i.parameters,
93
93
  LOWER(i.tablespace_name) AS tablespace_name,
@@ -117,7 +117,7 @@ module ActiveRecord
117
117
  statement_parameters = nil
118
118
  if row["index_type"] == "DOMAIN" && row["ityp_owner"] == "CTXSYS" && row["ityp_name"] == "CONTEXT"
119
119
  procedure_name = default_datastore_procedure(row["index_name"])
120
- source = select_values(<<-SQL.strip.gsub(/\s+/, " "), "procedure", [bind_string("procedure_name", procedure_name.upcase)]).join
120
+ source = select_values(<<~SQL.squish, "procedure", [bind_string("procedure_name", procedure_name.upcase)]).join
121
121
  SELECT text
122
122
  FROM all_source
123
123
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -361,7 +361,7 @@ module ActiveRecord
361
361
  # Will always query database and not index cache.
362
362
  def index_name_exists?(table_name, index_name)
363
363
  (_owner, table_name) = @connection.describe(table_name)
364
- result = select_value(<<-SQL.strip.gsub(/\s+/, " "), "index name exists")
364
+ result = select_value(<<~SQL.squish, "index name exists")
365
365
  SELECT 1 FROM all_indexes i
366
366
  WHERE i.owner = SYS_CONTEXT('userenv', 'current_schema')
367
367
  AND i.table_owner = SYS_CONTEXT('userenv', 'current_schema')
@@ -477,8 +477,9 @@ module ActiveRecord
477
477
  clear_table_columns_cache(table_name)
478
478
  end
479
479
 
480
- def change_table_comment(table_name, comment)
480
+ def change_table_comment(table_name, comment_or_changes)
481
481
  clear_cache!
482
+ comment = extract_new_comment_value(comment_or_changes)
482
483
  if comment.nil?
483
484
  execute "COMMENT ON TABLE #{quote_table_name(table_name)} IS ''"
484
485
  else
@@ -486,14 +487,15 @@ module ActiveRecord
486
487
  end
487
488
  end
488
489
 
489
- def change_column_comment(table_name, column_name, comment) #:nodoc:
490
+ def change_column_comment(table_name, column_name, comment_or_changes)
490
491
  clear_cache!
492
+ comment = extract_new_comment_value(comment_or_changes)
491
493
  execute "COMMENT ON COLUMN #{quote_table_name(table_name)}.#{quote_column_name(column_name)} IS '#{comment}'"
492
494
  end
493
495
 
494
496
  def table_comment(table_name) #:nodoc:
495
497
  (_owner, table_name) = @connection.describe(table_name)
496
- select_value(<<-SQL.strip.gsub(/\s+/, " "), "Table comment", [bind_string("table_name", table_name)])
498
+ select_value(<<~SQL.squish, "Table comment", [bind_string("table_name", table_name)])
497
499
  SELECT comments FROM all_tab_comments
498
500
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
499
501
  AND table_name = :table_name
@@ -509,7 +511,7 @@ module ActiveRecord
509
511
  def column_comment(table_name, column_name) #:nodoc:
510
512
  # TODO: it does not exist in Abstract adapter
511
513
  (_owner, table_name) = @connection.describe(table_name)
512
- select_value(<<-SQL.strip.gsub(/\s+/, " "), "Column comment", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
514
+ select_value(<<~SQL.squish, "Column comment", [bind_string("table_name", table_name), bind_string("column_name", column_name.upcase)])
513
515
  SELECT comments FROM all_col_comments
514
516
  WHERE owner = SYS_CONTEXT('userenv', 'current_schema')
515
517
  AND table_name = :table_name
@@ -526,7 +528,7 @@ module ActiveRecord
526
528
  end
527
529
 
528
530
  def tablespace(table_name)
529
- select_value(<<-SQL.strip.gsub(/\s+/, " "), "tablespace")
531
+ select_value(<<~SQL.squish, "tablespace")
530
532
  SELECT tablespace_name
531
533
  FROM all_tables
532
534
  WHERE table_name='#{table_name.to_s.upcase}'
@@ -538,7 +540,7 @@ module ActiveRecord
538
540
  def foreign_keys(table_name) #:nodoc:
539
541
  (_owner, desc_table_name) = @connection.describe(table_name)
540
542
 
541
- fk_info = select_all(<<-SQL.strip.gsub(/\s+/, " "), "Foreign Keys", [bind_string("desc_table_name", desc_table_name)])
543
+ fk_info = select_all(<<~SQL.squish, "Foreign Keys", [bind_string("desc_table_name", desc_table_name)])
542
544
  SELECT r.table_name to_table
543
545
  ,rc.column_name references_column
544
546
  ,cc.column_name
@@ -580,12 +582,12 @@ module ActiveRecord
580
582
  # REFERENTIAL INTEGRITY ====================================
581
583
 
582
584
  def disable_referential_integrity(&block) #:nodoc:
583
- old_constraints = select_all(<<-SQL.strip.gsub(/\s+/, " "), "Foreign Keys to disable and enable")
584
- SELECT constraint_name, owner, table_name
585
- FROM all_constraints
586
- WHERE constraint_type = 'R'
587
- AND status = 'ENABLED'
588
- AND owner = SYS_CONTEXT('userenv', 'current_schema')
585
+ old_constraints = select_all(<<~SQL.squish, "Foreign Keys to disable and enable")
586
+ SELECT constraint_name, owner, table_name
587
+ FROM all_constraints
588
+ WHERE constraint_type = 'R'
589
+ AND status = 'ENABLED'
590
+ AND owner = SYS_CONTEXT('userenv', 'current_schema')
589
591
  SQL
590
592
  begin
591
593
  old_constraints.each do |constraint|
@@ -652,8 +654,7 @@ module ActiveRecord
652
654
  default_value,
653
655
  type_metadata,
654
656
  field["nullable"] == "Y",
655
- table_name,
656
- field["column_comment"]
657
+ comment: field["column_comment"]
657
658
  )
658
659
  end
659
660
 
@@ -697,7 +698,7 @@ module ActiveRecord
697
698
 
698
699
  return unless tablespace
699
700
 
700
- index_name = select_value(<<-SQL.strip.gsub(/\s+/, " "), "Index name for primary key", [bind_string("table_name", table_name.upcase)])
701
+ index_name = select_value(<<~SQL.squish, "Index name for primary key", [bind_string("table_name", table_name.upcase)])
701
702
  SELECT index_name FROM all_constraints
702
703
  WHERE table_name = :table_name
703
704
  AND constraint_type = 'P'