activerecord-oracle_enhanced-adapter 1.6.9 → 1.7.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +10 -11
  3. data/History.md +126 -14
  4. data/README.md +9 -6
  5. data/RUNNING_TESTS.md +1 -1
  6. data/Rakefile +1 -16
  7. data/VERSION +1 -1
  8. data/activerecord-oracle_enhanced-adapter.gemspec +15 -52
  9. data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +8 -22
  10. data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +53 -45
  11. data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +6 -1
  12. data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +23 -62
  13. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +46 -56
  14. data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +35 -0
  15. data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +34 -21
  16. data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +36 -0
  17. data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +1 -1
  18. data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +174 -0
  19. data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +17 -8
  20. data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +17 -11
  21. data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +160 -178
  22. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +42 -94
  23. data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +50 -54
  24. data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +15 -11
  25. data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +197 -301
  26. data/lib/active_record/oracle_enhanced/type/integer.rb +3 -2
  27. data/lib/active_record/oracle_enhanced/type/national_character_string.rb +25 -0
  28. data/lib/active_record/oracle_enhanced/type/raw.rb +14 -2
  29. data/lib/active_record/oracle_enhanced/type/string.rb +28 -0
  30. data/lib/active_record/oracle_enhanced/type/text.rb +32 -0
  31. data/lib/activerecord-oracle_enhanced-adapter.rb +12 -17
  32. data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +113 -135
  33. data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +51 -59
  34. data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +40 -41
  35. data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +6 -6
  36. data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +281 -233
  37. data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +7 -7
  38. data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +10 -10
  39. data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +22 -22
  40. data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -2
  41. data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +36 -37
  42. data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +86 -46
  43. data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +194 -294
  44. data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +53 -39
  45. data/spec/spec_helper.rb +0 -6
  46. metadata +42 -143
  47. data/.travis.yml +0 -39
  48. data/.travis/oracle/download.sh +0 -14
  49. data/.travis/oracle/install.sh +0 -31
  50. data/.travis/setup_accounts.sh +0 -9
  51. data/lib/active_record/connection_adapters/oracle_enhanced/dirty.rb +0 -40
  52. data/lib/active_record/oracle_enhanced/type/timestamp.rb +0 -11
  53. data/spec/spec_config.yaml.template +0 -11
  54. data/spec/support/alter_system_user_password.sql +0 -2
  55. data/spec/support/create_oracle_enhanced_users.sql +0 -31
@@ -1,4 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
1
  require 'digest/sha1'
3
2
 
4
3
  module ActiveRecord
@@ -40,13 +39,21 @@ module ActiveRecord
40
39
  # t.string :last_name, :comment => “Surname”
41
40
  # end
42
41
 
43
- def create_table(table_name, options = {})
42
+ def create_table(table_name, comment: nil, **options)
44
43
  create_sequence = options[:id] != false
45
- column_comments = {}
46
- temporary = options.delete(:temporary)
47
- additional_options = options
48
- td = create_table_definition table_name, temporary, additional_options
49
- td.primary_key(options[:primary_key] || Base.get_primary_key(table_name.to_s.singularize)) unless options[:id] == false
44
+ td = create_table_definition table_name, options[:temporary], options[:options], options[:as], options[:tablespace], options[:organization], comment: comment
45
+
46
+ if options[:id] != false && !options[:as]
47
+ pk = options.fetch(:primary_key) do
48
+ Base.get_primary_key table_name.to_s.singularize
49
+ end
50
+
51
+ if pk.is_a?(Array)
52
+ td.primary_keys pk
53
+ else
54
+ td.primary_key pk, options.fetch(:id, :primary_key), options
55
+ end
56
+ end
50
57
 
51
58
  # store that primary key was defined in create_table block
52
59
  unless create_sequence
@@ -59,23 +66,10 @@ module ActiveRecord
59
66
  end
60
67
  end
61
68
 
62
- # store column comments
63
- class << td
64
- attr_accessor :column_comments
65
- def column(name, type, options = {})
66
- if options[:comment]
67
- self.column_comments ||= {}
68
- self.column_comments[name] = options[:comment]
69
- end
70
- super(name, type, options)
71
- end
72
- end
73
-
74
69
  yield td if block_given?
75
70
  create_sequence = create_sequence || td.create_sequence
76
- column_comments = td.column_comments if td.column_comments
77
71
 
78
- if options[:force] && table_exists?(table_name)
72
+ if options[:force] && data_source_exists?(table_name)
79
73
  drop_table(table_name, options)
80
74
  end
81
75
 
@@ -83,21 +77,18 @@ module ActiveRecord
83
77
 
84
78
  create_sequence_and_trigger(table_name, options) if create_sequence
85
79
 
86
- add_table_comment table_name, options[:comment]
87
- column_comments.each do |column_name, comment|
88
- add_comment table_name, column_name, comment
80
+ if supports_comments? && !supports_comments_in_create?
81
+ change_table_comment(table_name, comment) if comment
82
+ td.columns.each do |column|
83
+ change_column_comment(table_name, column.name, column.comment) if column.comment
84
+ end
89
85
  end
90
86
  td.indexes.each_pair { |c,o| add_index table_name, c, o }
91
87
 
92
- td.foreign_keys.each do |other_table_name, foreign_key_options|
93
- add_foreign_key(table_name, other_table_name, foreign_key_options)
94
- end
95
-
96
- rebuild_primary_key_index_to_default_tablespace(table_name, options)
97
88
  end
98
89
 
99
- def create_table_definition(name, temporary, options)
100
- ActiveRecord::ConnectionAdapters::OracleEnhanced::TableDefinition.new native_database_types, name, temporary, options
90
+ def create_table_definition(*args)
91
+ ActiveRecord::ConnectionAdapters::OracleEnhanced::TableDefinition.new(*args)
101
92
  end
102
93
 
103
94
  def rename_table(table_name, new_name) #:nodoc:
@@ -122,38 +113,11 @@ module ActiveRecord
122
113
  end
123
114
 
124
115
  def dump_schema_information #:nodoc:
125
- sm_table = ActiveRecord::Migrator.schema_migrations_table_name
126
- migrated = select_values("SELECT version FROM #{sm_table} ORDER BY version")
127
- join_with_statement_token(migrated.map{|v| "INSERT INTO #{sm_table} (version) VALUES ('#{v}')" })
116
+ super
128
117
  end
129
118
 
130
119
  def initialize_schema_migrations_table
131
- sm_table = ActiveRecord::Migrator.schema_migrations_table_name
132
-
133
- unless table_exists?(sm_table)
134
- index_name = "#{Base.table_name_prefix}unique_schema_migrations#{Base.table_name_suffix}"
135
- if index_name.length > index_name_length
136
- truncate_to = index_name_length - index_name.to_s.length - 1
137
- truncated_name = "unique_schema_migrations"[0..truncate_to]
138
- index_name = "#{Base.table_name_prefix}#{truncated_name}#{Base.table_name_suffix}"
139
- end
140
-
141
- create_table(sm_table, :id => false) do |schema_migrations_table|
142
- schema_migrations_table.column :version, :string, :null => false
143
- end
144
- add_index sm_table, :version, :unique => true, :name => index_name
145
-
146
- # Backwards-compatibility: if we find schema_info, assume we've
147
- # migrated up to that point:
148
- si_table = Base.table_name_prefix + 'schema_info' + Base.table_name_suffix
149
- if table_exists?(si_table)
150
- ActiveSupport::Deprecation.warn "Usage of the schema table `#{si_table}` is deprecated. Please switch to using `schema_migrations` table"
151
-
152
- old_version = select_value("SELECT version FROM #{quote_table_name(si_table)}").to_i
153
- assume_migrated_upto_version(old_version)
154
- drop_table(si_table)
155
- end
156
- end
120
+ super
157
121
  end
158
122
 
159
123
  def update_table_definition(table_name, base) #:nodoc:
@@ -172,7 +136,7 @@ module ActiveRecord
172
136
  self.all_schema_indexes = nil
173
137
  end
174
138
 
175
- def add_index_options(table_name, column_name, options = {}) #:nodoc:
139
+ def add_index_options(table_name, column_name, comment: nil, **options) #:nodoc:
176
140
  column_names = Array(column_name)
177
141
  index_name = index_name(table_name, column: column_names)
178
142
 
@@ -199,7 +163,7 @@ module ActiveRecord
199
163
  # Remove the given index from the table.
200
164
  # Gives warning if index does not exist
201
165
  def remove_index(table_name, options = {}) #:nodoc:
202
- index_name = index_name(table_name, options)
166
+ index_name = index_name_for_remove(table_name, options)
203
167
  unless index_name_exists?(table_name, index_name, true)
204
168
  # sometimes options can be String or Array with column names
205
169
  options = {} unless options.is_a?(Hash)
@@ -211,11 +175,6 @@ module ActiveRecord
211
175
  end
212
176
  raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
213
177
  end
214
- remove_index!(table_name, index_name)
215
- end
216
-
217
- # clear cached indexes when removing index
218
- def remove_index!(table_name, index_name) #:nodoc:
219
178
  #TODO: It should execute only when index_type == "UNIQUE"
220
179
  execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{quote_column_name(index_name)}" rescue nil
221
180
  execute "DROP INDEX #{quote_column_name(index_name)}"
@@ -291,6 +250,7 @@ module ActiveRecord
291
250
  execute(add_column_sql)
292
251
 
293
252
  create_sequence_and_trigger(table_name, options) if type && type.to_sym == :primary_key
253
+ change_column_comment(table_name, column_name, options[:comment]) if options.key?(:comment)
294
254
  ensure
295
255
  clear_table_columns_cache(table_name)
296
256
  end
@@ -299,7 +259,8 @@ module ActiveRecord
299
259
  fallback
300
260
  end
301
261
 
302
- def change_column_default(table_name, column_name, default) #:nodoc:
262
+ def change_column_default(table_name, column_name, default_or_changes) #:nodoc:
263
+ default = extract_new_default_value(default_or_changes)
303
264
  execute "ALTER TABLE #{quote_table_name(table_name)} MODIFY #{quote_column_name(column_name)} DEFAULT #{quote(default)}"
304
265
  ensure
305
266
  clear_table_columns_cache(table_name)
@@ -353,14 +314,14 @@ module ActiveRecord
353
314
  self.all_schema_indexes = nil
354
315
  end
355
316
 
356
- def add_comment(table_name, column_name, comment) #:nodoc:
357
- return if comment.blank?
358
- execute "COMMENT ON COLUMN #{quote_table_name(table_name)}.#{column_name} IS '#{comment}'"
317
+ def change_table_comment(table_name, comment)
318
+ clear_cache!
319
+ execute "COMMENT ON TABLE #{quote_table_name(table_name)} IS #{quote(comment)}"
359
320
  end
360
321
 
361
- def add_table_comment(table_name, comment) #:nodoc:
362
- return if comment.blank?
363
- execute "COMMENT ON TABLE #{quote_table_name(table_name)} IS '#{comment}'"
322
+ def change_column_comment(table_name, column_name, comment) #:nodoc:
323
+ clear_cache!
324
+ execute "COMMENT ON COLUMN #{quote_table_name(table_name)}.#{quote_column_name(column_name)} IS '#{comment}'"
364
325
  end
365
326
 
366
327
  def table_comment(table_name) #:nodoc:
@@ -373,6 +334,7 @@ module ActiveRecord
373
334
  end
374
335
 
375
336
  def column_comment(table_name, column_name) #:nodoc:
337
+ # TODO: it does not exist in Abstract adapter
376
338
  (owner, table_name, db_link) = @connection.describe(table_name)
377
339
  select_value <<-SQL
378
340
  SELECT comments FROM all_col_comments#{db_link}
@@ -393,8 +355,9 @@ module ActiveRecord
393
355
  def tablespace(table_name)
394
356
  select_value <<-SQL
395
357
  SELECT tablespace_name
396
- FROM user_tables
358
+ FROM all_tables
397
359
  WHERE table_name='#{table_name.to_s.upcase}'
360
+ AND owner = SYS_CONTEXT('userenv', 'session_user')
398
361
  SQL
399
362
  end
400
363
 
@@ -425,8 +388,8 @@ module ActiveRecord
425
388
  ,cc.column_name
426
389
  ,c.constraint_name name
427
390
  ,c.delete_rule
428
- FROM user_constraints#{db_link} c, user_cons_columns#{db_link} cc,
429
- user_constraints#{db_link} r, user_cons_columns#{db_link} rc
391
+ FROM all_constraints#{db_link} c, all_cons_columns#{db_link} cc,
392
+ all_constraints#{db_link} r, all_cons_columns#{db_link} rc
430
393
  WHERE c.owner = '#{owner}'
431
394
  AND c.table_name = '#{desc_table_name}'
432
395
  AND c.constraint_type = 'R'
@@ -463,9 +426,10 @@ module ActiveRecord
463
426
  def disable_referential_integrity(&block) #:nodoc:
464
427
  sql_constraints = <<-SQL
465
428
  SELECT constraint_name, owner, table_name
466
- FROM user_constraints
429
+ FROM all_constraints
467
430
  WHERE constraint_type = 'R'
468
431
  AND status = 'ENABLED'
432
+ AND owner = SYS_CONTEXT('userenv', 'session_user')
469
433
  SQL
470
434
  old_constraints = select_all(sql_constraints)
471
435
  begin
@@ -540,22 +504,6 @@ module ActiveRecord
540
504
  "#{table_name.to_s[0,table_name_length-4]}_pkt"
541
505
  end
542
506
 
543
- def rebuild_primary_key_index_to_default_tablespace(table_name, options)
544
- tablespace = default_tablespace_for(:index)
545
-
546
- return unless tablespace
547
-
548
- index_name = Base.connection.select_value(
549
- "SELECT index_name FROM all_constraints
550
- WHERE table_name = #{quote(table_name.upcase)}
551
- AND constraint_type = 'P'
552
- AND owner = SYS_CONTEXT('userenv', 'current_schema')")
553
-
554
- return unless index_name
555
-
556
- execute("ALTER INDEX #{quote_column_name(index_name)} REBUILD TABLESPACE #{tablespace}")
557
- end
558
-
559
507
  end
560
508
  end
561
509
  end
@@ -1,65 +1,61 @@
1
- require 'digest/sha1'
2
-
3
1
  module ActiveRecord
4
2
  module ConnectionAdapters
5
- module OracleEnhancedSchemaStatementsExt
6
- # Create primary key trigger (so that you can skip primary key value in INSERT statement).
7
- # By default trigger name will be "table_name_pkt", you can override the name with
8
- # :trigger_name option (but it is not recommended to override it as then this trigger will
9
- # not be detected by ActiveRecord model and it will still do prefetching of sequence value).
10
- #
11
- # add_primary_key_trigger :users
12
- #
13
- # You can also create primary key trigger using +create_table+ with :primary_key_trigger
14
- # option:
15
- #
16
- # create_table :users, :primary_key_trigger => true do |t|
17
- # # ...
18
- # end
19
- #
20
- def add_primary_key_trigger(table_name, options={})
21
- # call the same private method that is used for create_table :primary_key_trigger => true
22
- create_primary_key_trigger(table_name, options)
23
- end
3
+ module OracleEnhanced
4
+ module SchemaStatementsExt
5
+ # Create primary key trigger (so that you can skip primary key value in INSERT statement).
6
+ # By default trigger name will be "table_name_pkt", you can override the name with
7
+ # :trigger_name option (but it is not recommended to override it as then this trigger will
8
+ # not be detected by ActiveRecord model and it will still do prefetching of sequence value).
9
+ #
10
+ # add_primary_key_trigger :users
11
+ #
12
+ # You can also create primary key trigger using +create_table+ with :primary_key_trigger
13
+ # option:
14
+ #
15
+ # create_table :users, :primary_key_trigger => true do |t|
16
+ # # ...
17
+ # end
18
+ #
19
+ def add_primary_key_trigger(table_name, options={})
20
+ # call the same private method that is used for create_table :primary_key_trigger => true
21
+ create_primary_key_trigger(table_name, options)
22
+ end
24
23
 
25
- # Add synonym to existing table or view or sequence. Can be used to create local synonym to
26
- # remote table in other schema or in other database
27
- # Examples:
28
- #
29
- # add_synonym :posts, "blog.posts"
30
- # add_synonym :posts_seq, "blog.posts_seq"
31
- # add_synonym :employees, "hr.employees@dblink", :force => true
32
- #
33
- def add_synonym(name, table_name, options = {})
34
- sql = "CREATE"
35
- if options[:force] == true
36
- sql << " OR REPLACE"
24
+ # Add synonym to existing table or view or sequence. Can be used to create local synonym to
25
+ # remote table in other schema or in other database
26
+ # Examples:
27
+ #
28
+ # add_synonym :posts, "blog.posts"
29
+ # add_synonym :posts_seq, "blog.posts_seq"
30
+ # add_synonym :employees, "hr.employees@dblink", :force => true
31
+ #
32
+ def add_synonym(name, table_name, options = {})
33
+ sql = "CREATE"
34
+ if options[:force] == true
35
+ sql << " OR REPLACE"
36
+ end
37
+ sql << " SYNONYM #{quote_table_name(name)} FOR #{quote_table_name(table_name)}"
38
+ execute sql
37
39
  end
38
- sql << " SYNONYM #{quote_table_name(name)} FOR #{quote_table_name(table_name)}"
39
- execute sql
40
- end
41
40
 
42
- # Remove existing synonym to table or view or sequence
43
- # Example:
44
- #
45
- # remove_synonym :posts, "blog.posts"
46
- #
47
- def remove_synonym(name)
48
- execute "DROP SYNONYM #{quote_table_name(name)}"
49
- end
41
+ # Remove existing synonym to table or view or sequence
42
+ # Example:
43
+ #
44
+ # remove_synonym :posts, "blog.posts"
45
+ #
46
+ def remove_synonym(name)
47
+ execute "DROP SYNONYM #{quote_table_name(name)}"
48
+ end
50
49
 
51
- # get synonyms for schema dump
52
- def synonyms #:nodoc:
53
- select_all("SELECT synonym_name, table_owner, table_name, db_link FROM user_synonyms").collect do |row|
54
- OracleEnhanced::SynonymDefinition.new(oracle_downcase(row['synonym_name']),
55
- oracle_downcase(row['table_owner']), oracle_downcase(row['table_name']), oracle_downcase(row['db_link']))
50
+ # get synonyms for schema dump
51
+ def synonyms #:nodoc:
52
+ select_all("SELECT synonym_name, table_owner, table_name, db_link FROM all_synonyms where owner = SYS_CONTEXT('userenv', 'session_user')").collect do |row|
53
+ OracleEnhanced::SynonymDefinition.new(oracle_downcase(row['synonym_name']),
54
+ oracle_downcase(row['table_owner']), oracle_downcase(row['table_name']), oracle_downcase(row['db_link']))
55
+ end
56
56
  end
57
- end
58
57
 
58
+ end
59
59
  end
60
60
  end
61
61
  end
62
-
63
- ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do
64
- include ActiveRecord::ConnectionAdapters::OracleEnhancedSchemaStatementsExt
65
- end
@@ -6,7 +6,7 @@ module ActiveRecord #:nodoc:
6
6
  STATEMENT_TOKEN = "\n\n/\n\n"
7
7
 
8
8
  def structure_dump #:nodoc:
9
- structure = select_values("SELECT sequence_name FROM user_sequences ORDER BY 1").map do |seq|
9
+ structure = select_values("SELECT sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY 1").map do |seq|
10
10
  "CREATE SEQUENCE \"#{seq}\""
11
11
  end
12
12
  select_values("SELECT table_name FROM all_tables t
@@ -18,8 +18,9 @@ module ActiveRecord #:nodoc:
18
18
  ddl = "CREATE#{ ' GLOBAL TEMPORARY' if temporary_table?(table_name)} TABLE \"#{table_name}\" (\n"
19
19
  cols = select_all(%Q{
20
20
  SELECT column_name, data_type, data_length, char_used, char_length, data_precision, data_scale, data_default, nullable
21
- FROM user_tab_columns
21
+ FROM all_tab_columns
22
22
  WHERE table_name = '#{table_name}'
23
+ AND owner = SYS_CONTEXT('userenv', 'session_user')
23
24
  ORDER BY column_id
24
25
  }).map do |row|
25
26
  if(v = virtual_columns.find {|col| col['column_name'] == row['column_name']})
@@ -74,11 +75,12 @@ module ActiveRecord #:nodoc:
74
75
  opts = {:name => '', :cols => []}
75
76
  pks = select_all(<<-SQL, "Primary Keys")
76
77
  SELECT a.constraint_name, a.column_name, a.position
77
- FROM user_cons_columns a
78
- JOIN user_constraints c
78
+ FROM all_cons_columns a
79
+ JOIN all_constraints c
79
80
  ON a.constraint_name = c.constraint_name
80
81
  WHERE c.table_name = '#{table.upcase}'
81
82
  AND c.constraint_type = 'P'
83
+ AND a.owner = c.owner
82
84
  AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
83
85
  SQL
84
86
  pks.each do |row|
@@ -92,11 +94,12 @@ module ActiveRecord #:nodoc:
92
94
  keys = {}
93
95
  uks = select_all(<<-SQL, "Primary Keys")
94
96
  SELECT a.constraint_name, a.column_name, a.position
95
- FROM user_cons_columns a
96
- JOIN user_constraints c
97
+ FROM all_cons_columns a
98
+ JOIN all_constraints c
97
99
  ON a.constraint_name = c.constraint_name
98
100
  WHERE c.table_name = '#{table.upcase}'
99
101
  AND c.constraint_type = 'U'
102
+ AND a.owner = c.owner
100
103
  AND c.owner = SYS_CONTEXT('userenv', 'current_schema')
101
104
  SQL
102
105
  uks.each do |uk|
@@ -213,7 +216,7 @@ module ActiveRecord #:nodoc:
213
216
  end
214
217
 
215
218
  # export views
216
- select_all("SELECT view_name, text FROM user_views ORDER BY view_name ASC").each do |view|
219
+ select_all("SELECT view_name, text FROM all_views WHERE owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY view_name ASC").each do |view|
217
220
  structure << "CREATE OR REPLACE FORCE VIEW #{view['view_name']} AS\n #{view['text']}"
218
221
  end
219
222
 
@@ -229,7 +232,7 @@ module ActiveRecord #:nodoc:
229
232
  end
230
233
 
231
234
  def structure_drop #:nodoc:
232
- statements = select_values("SELECT sequence_name FROM user_sequences ORDER BY 1").map do |seq|
235
+ statements = select_values("SELECT sequence_name FROM all_sequences where sequence_owner = SYS_CONTEXT('userenv', 'session_user') ORDER BY 1").map do |seq|
233
236
  "DROP SEQUENCE \"#{seq}\""
234
237
  end
235
238
  select_values("SELECT table_name from all_tables t
@@ -302,8 +305,9 @@ module ActiveRecord #:nodoc:
302
305
  begin
303
306
  select_all <<-SQL
304
307
  SELECT column_name, data_default
305
- FROM user_tab_cols
308
+ FROM all_tab_cols
306
309
  WHERE virtual_column = 'YES'
310
+ AND owner = SYS_CONTEXT('userenv', 'session_user')
307
311
  AND table_name = '#{table.upcase}'
308
312
  SQL
309
313
  # feature not supported previous to 11g
@@ -315,14 +319,14 @@ module ActiveRecord #:nodoc:
315
319
  def drop_sql_for_feature(type)
316
320
  short_type = type == 'materialized view' ? 'mview' : type
317
321
  join_with_statement_token(
318
- select_values("SELECT #{short_type}_name FROM user_#{short_type.tableize}").map do |name|
322
+ select_values("SELECT #{short_type}_name FROM all_#{short_type.tableize} where owner = SYS_CONTEXT('userenv', 'session_user')").map do |name|
319
323
  "DROP #{type.upcase} \"#{name}\""
320
324
  end)
321
325
  end
322
326
 
323
327
  def drop_sql_for_object(type)
324
328
  join_with_statement_token(
325
- select_values("SELECT object_name FROM user_objects WHERE object_type = '#{type.upcase}'").map do |name|
329
+ select_values("SELECT object_name FROM all_objects WHERE object_type = '#{type.upcase}' and owner = SYS_CONTEXT('userenv', 'session_user')").map do |name|
326
330
  "DROP #{type.upcase} \"#{name}\""
327
331
  end)
328
332
  end