activerecord-oracle_enhanced-adapter 1.4.3 → 1.5.0.beta1
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.
- checksums.yaml +4 -4
- data/Gemfile +4 -14
- data/History.md +51 -0
- data/README.md +32 -1
- data/VERSION +1 -1
- data/activerecord-oracle_enhanced-adapter.gemspec +2 -4
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +315 -57
- data/lib/active_record/connection_adapters/oracle_enhanced_column_dumper.rb +55 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_context_index.rb +4 -13
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +5 -6
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +19 -11
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +163 -232
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +18 -10
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +20 -32
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements.rb +54 -35
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +5 -74
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +3 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +98 -98
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +5 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +11 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +56 -55
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +15 -8
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +4 -3
- data/spec/spec_helper.rb +25 -54
- metadata +32 -20
- data/lib/active_record/connection_adapters/oracle_enhanced_activerecord_patches.rb +0 -41
- data/lib/active_record/connection_adapters/oracle_enhanced_base_ext.rb +0 -121
- data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +0 -17
@@ -13,8 +13,8 @@ module ActiveRecord
|
|
13
13
|
module OracleEnhancedColumnDefinition
|
14
14
|
def self.included(base) #:nodoc:
|
15
15
|
base.class_eval do
|
16
|
-
alias_method_chain :to_sql, :virtual_columns
|
17
|
-
alias to_s :to_sql
|
16
|
+
#alias_method_chain :to_sql, :virtual_columns
|
17
|
+
#alias to_s :to_sql
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
@@ -60,7 +60,7 @@ module ActiveRecord
|
|
60
60
|
def self.included(base) #:nodoc:
|
61
61
|
base.class_eval do
|
62
62
|
alias_method_chain :references, :foreign_keys
|
63
|
-
alias_method_chain :to_sql, :foreign_keys
|
63
|
+
#alias_method_chain :to_sql, :foreign_keys
|
64
64
|
|
65
65
|
alias_method_chain :column, :virtual_columns
|
66
66
|
end
|
@@ -106,11 +106,15 @@ module ActiveRecord
|
|
106
106
|
# Note: If no name is specified, the database driver creates one for you!
|
107
107
|
def references_with_foreign_keys(*args)
|
108
108
|
options = args.extract_options!
|
109
|
+
index_options = options[:index]
|
109
110
|
fk_options = options.delete(:foreign_key)
|
110
111
|
|
111
112
|
if fk_options && !options[:polymorphic]
|
112
113
|
fk_options = {} if fk_options == true
|
113
|
-
args.each
|
114
|
+
args.each do |to_table|
|
115
|
+
foreign_key(to_table, fk_options)
|
116
|
+
add_index(to_table, "#{to_table}_id", index_options.is_a?(Hash) ? index_options : nil) if index_options
|
117
|
+
end
|
114
118
|
end
|
115
119
|
|
116
120
|
references_without_foreign_keys(*(args << options))
|
@@ -129,7 +133,8 @@ module ActiveRecord
|
|
129
133
|
# ====== Defining the column of the +to_table+.
|
130
134
|
# t.foreign_key(:people, :column => :sender_id, :primary_key => :person_id)
|
131
135
|
def foreign_key(to_table, options = {})
|
132
|
-
|
136
|
+
#TODO
|
137
|
+
if ActiveRecord::Base.connection.supports_foreign_keys?
|
133
138
|
to_table = to_table.to_s.pluralize if ActiveRecord::Base.pluralize_table_names
|
134
139
|
foreign_keys << ForeignKey.new(@base, to_table, options)
|
135
140
|
else
|
@@ -147,10 +152,9 @@ module ActiveRecord
|
|
147
152
|
columns.select(&:lob?)
|
148
153
|
end
|
149
154
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
155
|
+
def foreign_keys
|
156
|
+
@foreign_keys ||= []
|
157
|
+
end
|
154
158
|
end
|
155
159
|
|
156
160
|
module OracleEnhancedTable
|
@@ -208,6 +212,7 @@ module ActiveRecord
|
|
208
212
|
def references_with_foreign_keys(*args)
|
209
213
|
options = args.extract_options!
|
210
214
|
polymorphic = options[:polymorphic]
|
215
|
+
index_options = options[:index]
|
211
216
|
fk_options = options.delete(:foreign_key)
|
212
217
|
|
213
218
|
references_without_foreign_keys(*(args << options))
|
@@ -215,7 +220,10 @@ module ActiveRecord
|
|
215
220
|
args.extract_options!
|
216
221
|
if fk_options && !polymorphic
|
217
222
|
fk_options = {} if fk_options == true
|
218
|
-
args.each
|
223
|
+
args.each do |to_table|
|
224
|
+
foreign_key(to_table, fk_options)
|
225
|
+
add_index(to_table, "#{to_table}_id", index_options.is_a?(Hash) ? index_options : nil) if index_options
|
226
|
+
end
|
219
227
|
end
|
220
228
|
end
|
221
229
|
end
|
@@ -51,7 +51,7 @@ module ActiveRecord #:nodoc:
|
|
51
51
|
if @connection.respond_to?(:has_primary_key_trigger?) && @connection.has_primary_key_trigger?(table_name)
|
52
52
|
pk, pk_seq = @connection.pk_and_sequence_for(table_name)
|
53
53
|
stream.print " add_primary_key_trigger #{table_name.inspect}"
|
54
|
-
stream.print ", :
|
54
|
+
stream.print ", primary_key: \"#{pk}\"" if pk != 'id'
|
55
55
|
stream.print "\n\n"
|
56
56
|
end
|
57
57
|
end
|
@@ -65,20 +65,20 @@ module ActiveRecord #:nodoc:
|
|
65
65
|
if foreign_key.options[:columns].size == 1
|
66
66
|
column = foreign_key.options[:columns].first
|
67
67
|
if column != "#{foreign_key.to_table.singularize}_id"
|
68
|
-
statement_parts << (':
|
68
|
+
statement_parts << ('column: ' + column.inspect)
|
69
69
|
end
|
70
70
|
|
71
71
|
if foreign_key.options[:references].first != 'id'
|
72
|
-
statement_parts << (':
|
72
|
+
statement_parts << ('primary_key: ' + foreign_key.options[:primary_key].inspect)
|
73
73
|
end
|
74
74
|
else
|
75
|
-
statement_parts << (':
|
75
|
+
statement_parts << ('columns: ' + foreign_key.options[:columns].inspect)
|
76
76
|
end
|
77
77
|
|
78
|
-
statement_parts << (':
|
78
|
+
statement_parts << ('name: ' + foreign_key.options[:name].inspect)
|
79
79
|
|
80
80
|
unless foreign_key.options[:dependent].blank?
|
81
|
-
statement_parts << (':
|
81
|
+
statement_parts << ('dependent: ' + foreign_key.options[:dependent].inspect)
|
82
82
|
end
|
83
83
|
|
84
84
|
' ' + statement_parts.join(', ')
|
@@ -97,7 +97,7 @@ module ActiveRecord #:nodoc:
|
|
97
97
|
table_name = syn.table_name
|
98
98
|
table_name = "#{syn.table_owner}.#{table_name}" if syn.table_owner
|
99
99
|
table_name = "#{table_name}@#{syn.db_link}" if syn.db_link
|
100
|
-
stream.print " add_synonym #{syn.name.inspect}, #{table_name.inspect}, :
|
100
|
+
stream.print " add_synonym #{syn.name.inspect}, #{table_name.inspect}, force: true"
|
101
101
|
stream.puts
|
102
102
|
end
|
103
103
|
stream.puts unless syns.empty?
|
@@ -118,9 +118,9 @@ module ActiveRecord #:nodoc:
|
|
118
118
|
# use table.inspect as it will remove prefix and suffix
|
119
119
|
statement_parts = [ ('add_index ' + table.inspect) ]
|
120
120
|
statement_parts << index.columns.inspect
|
121
|
-
statement_parts << (':
|
122
|
-
statement_parts << ':
|
123
|
-
statement_parts << ':
|
121
|
+
statement_parts << ('name: ' + index.name.inspect)
|
122
|
+
statement_parts << 'unique: true' if index.unique
|
123
|
+
statement_parts << 'tablespace: ' + index.tablespace.inspect if index.tablespace
|
124
124
|
when 'CTXSYS.CONTEXT'
|
125
125
|
if index.statement_parameters
|
126
126
|
statement_parts = [ ('add_context_index ' + table.inspect) ]
|
@@ -128,7 +128,7 @@ module ActiveRecord #:nodoc:
|
|
128
128
|
else
|
129
129
|
statement_parts = [ ('add_context_index ' + table.inspect) ]
|
130
130
|
statement_parts << index.columns.inspect
|
131
|
-
statement_parts << (':
|
131
|
+
statement_parts << ('name: ' + index.name.inspect)
|
132
132
|
end
|
133
133
|
else
|
134
134
|
# unrecognized index type
|
@@ -157,42 +157,30 @@ module ActiveRecord #:nodoc:
|
|
157
157
|
tbl.print " create_table #{table.inspect}"
|
158
158
|
|
159
159
|
# addition to make temporary option work
|
160
|
-
tbl.print ", :
|
160
|
+
tbl.print ", temporary: true" if @connection.temporary_table?(table)
|
161
161
|
|
162
162
|
if columns.detect { |c| c.name == pk }
|
163
163
|
if pk != 'id'
|
164
|
-
tbl.print %Q(, :
|
164
|
+
tbl.print %Q(, primary_key: "#{pk}")
|
165
165
|
end
|
166
166
|
else
|
167
|
-
tbl.print ", :
|
167
|
+
tbl.print ", id: false"
|
168
168
|
end
|
169
|
-
tbl.print ", :
|
169
|
+
tbl.print ", force: true"
|
170
170
|
tbl.puts " do |t|"
|
171
171
|
|
172
172
|
# then dump all non-primary key columns
|
173
173
|
column_specs = columns.map do |column|
|
174
174
|
raise StandardError, "Unknown type '#{column.sql_type}' for column '#{column.name}'" if @types[column.type].nil?
|
175
175
|
next if column.name == pk
|
176
|
-
|
177
|
-
spec[:name] = column.name.inspect
|
178
|
-
spec[:type] = column.virtual? ? 'virtual' : column.type.to_s
|
179
|
-
spec[:type] = column.virtual? ? 'virtual' : column.type.to_s
|
180
|
-
spec[:virtual_type] = column.type.inspect if column.virtual? && column.sql_type != 'NUMBER'
|
181
|
-
spec[:limit] = column.limit.inspect if column.limit != @types[column.type][:limit] && column.type != :decimal
|
182
|
-
spec[:precision] = column.precision.inspect if !column.precision.nil?
|
183
|
-
spec[:scale] = column.scale.inspect if !column.scale.nil?
|
184
|
-
spec[:null] = 'false' if !column.null
|
185
|
-
spec[:as] = column.virtual_column_data_default if column.virtual?
|
186
|
-
spec[:default] = default_string(column.default) if column.has_default? && !column.virtual?
|
187
|
-
(spec.keys - [:name, :type]).each do |k|
|
188
|
-
key_s = (k == :virtual_type ? ":type => " : "#{k.inspect} => ")
|
189
|
-
spec[k] = key_s + spec[k]
|
190
|
-
end
|
191
|
-
spec
|
176
|
+
@connection.column_spec(column, @types)
|
192
177
|
end.compact
|
193
178
|
|
194
179
|
# find all migration keys used in this table
|
195
|
-
|
180
|
+
#
|
181
|
+
# TODO `& column_specs.map(&:keys).flatten` should be executed
|
182
|
+
# in migration_keys_with_oracle_enhanced
|
183
|
+
keys = @connection.migration_keys & column_specs.map(&:keys).flatten
|
196
184
|
|
197
185
|
# figure out the lengths for each column based on above keys
|
198
186
|
lengths = keys.map{ |key| column_specs.map{ |spec| spec[key] ? spec[key].length + 2 : 0 }.max }
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
1
2
|
require 'digest/sha1'
|
2
3
|
|
3
4
|
module ActiveRecord
|
@@ -38,11 +39,12 @@ module ActiveRecord
|
|
38
39
|
# t.string :last_name, :comment => “Surname”
|
39
40
|
# end
|
40
41
|
|
41
|
-
def create_table(name, options = {}
|
42
|
+
def create_table(name, options = {})
|
42
43
|
create_sequence = options[:id] != false
|
43
44
|
column_comments = {}
|
44
|
-
|
45
|
-
|
45
|
+
temporary = options.delete(:temporary)
|
46
|
+
additional_options = options
|
47
|
+
table_definition = create_table_definition name, temporary, additional_options
|
46
48
|
table_definition.primary_key(options[:primary_key] || Base.get_primary_key(name.to_s.singularize)) unless options[:id] == false
|
47
49
|
|
48
50
|
# store that primary key was defined in create_table block
|
@@ -68,7 +70,7 @@ module ActiveRecord
|
|
68
70
|
end
|
69
71
|
end
|
70
72
|
|
71
|
-
|
73
|
+
yield table_definition if block_given?
|
72
74
|
create_sequence = create_sequence || table_definition.create_sequence
|
73
75
|
column_comments = table_definition.column_comments if table_definition.column_comments
|
74
76
|
tablespace = tablespace_for(:table, options[:tablespace])
|
@@ -77,16 +79,7 @@ module ActiveRecord
|
|
77
79
|
drop_table(name, options)
|
78
80
|
end
|
79
81
|
|
80
|
-
|
81
|
-
create_sql << quote_table_name(name)
|
82
|
-
create_sql << " (#{table_definition.to_sql})"
|
83
|
-
unless options[:temporary]
|
84
|
-
create_sql << " ORGANIZATION #{options[:organization]}" if options[:organization]
|
85
|
-
create_sql << tablespace
|
86
|
-
table_definition.lob_columns.each{|cd| create_sql << tablespace_for(cd.sql_type.downcase.to_sym, nil, name, cd.name)}
|
87
|
-
end
|
88
|
-
create_sql << " #{options[:options]}"
|
89
|
-
execute create_sql
|
82
|
+
execute schema_creation.accept table_definition
|
90
83
|
|
91
84
|
create_sequence_and_trigger(name, options) if create_sequence
|
92
85
|
|
@@ -94,18 +87,30 @@ module ActiveRecord
|
|
94
87
|
column_comments.each do |column_name, comment|
|
95
88
|
add_comment name, column_name, comment
|
96
89
|
end
|
90
|
+
table_definition.indexes.each_pair { |c,o| add_index name, c, o }
|
91
|
+
|
92
|
+
unless table_definition.foreign_keys.nil?
|
93
|
+
table_definition.foreign_keys.each do |foreign_key|
|
94
|
+
add_foreign_key(table_definition.name, foreign_key.to_table, foreign_key.options)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
97
98
|
|
99
|
+
def create_table_definition(name, temporary, options)
|
100
|
+
TableDefinition.new native_database_types, name, temporary, options
|
98
101
|
end
|
99
102
|
|
100
|
-
def rename_table(
|
103
|
+
def rename_table(table_name, new_name) #:nodoc:
|
101
104
|
if new_name.to_s.length > table_name_length
|
102
105
|
raise ArgumentError, "New table name '#{new_name}' is too long; the limit is #{table_name_length} characters"
|
103
106
|
end
|
104
107
|
if "#{new_name}_seq".to_s.length > sequence_name_length
|
105
108
|
raise ArgumentError, "New sequence name '#{new_name}_seq' is too long; the limit is #{sequence_name_length} characters"
|
106
109
|
end
|
107
|
-
execute "RENAME #{quote_table_name(
|
108
|
-
execute "RENAME #{quote_table_name("#{
|
110
|
+
execute "RENAME #{quote_table_name(table_name)} TO #{quote_table_name(new_name)}"
|
111
|
+
execute "RENAME #{quote_table_name("#{table_name}_seq")} TO #{quote_table_name("#{new_name}_seq")}" rescue nil
|
112
|
+
|
113
|
+
rename_table_indexes(table_name, new_name)
|
109
114
|
end
|
110
115
|
|
111
116
|
def drop_table(name, options = {}) #:nodoc:
|
@@ -114,6 +119,7 @@ module ActiveRecord
|
|
114
119
|
execute "DROP SEQUENCE #{quote_table_name(seq_name)}" rescue nil
|
115
120
|
ensure
|
116
121
|
clear_table_columns_cache(name)
|
122
|
+
self.all_schema_indexes = nil
|
117
123
|
end
|
118
124
|
|
119
125
|
def initialize_schema_migrations_table
|
@@ -148,25 +154,39 @@ module ActiveRecord
|
|
148
154
|
# clear cached indexes when adding new index
|
149
155
|
def add_index(table_name, column_name, options = {}) #:nodoc:
|
150
156
|
column_names = Array(column_name)
|
151
|
-
index_name = index_name(table_name, :
|
157
|
+
index_name = index_name(table_name, column: column_names)
|
152
158
|
|
153
159
|
if Hash === options # legacy support, since this param was a string
|
160
|
+
options.assert_valid_keys(:unique, :order, :name, :where, :length, :internal, :tablespace, :options, :using)
|
161
|
+
|
154
162
|
index_type = options[:unique] ? "UNIQUE" : ""
|
155
163
|
index_name = options[:name].to_s if options.key?(:name)
|
156
164
|
tablespace = tablespace_for(:index, options[:tablespace])
|
165
|
+
max_index_length = options.fetch(:internal, false) ? index_name_length : allowed_index_name_length
|
166
|
+
additional_options = options[:options]
|
157
167
|
else
|
168
|
+
if options
|
169
|
+
message = "Passing a string as third argument of `add_index` is deprecated and will" +
|
170
|
+
" be removed in Rails 4.1." +
|
171
|
+
" Use add_index(#{table_name.inspect}, #{column_name.inspect}, unique: true) instead"
|
172
|
+
|
173
|
+
ActiveSupport::Deprecation.warn message
|
174
|
+
end
|
175
|
+
|
158
176
|
index_type = options
|
177
|
+
additional_options = nil
|
178
|
+
max_index_length = allowed_index_name_length
|
159
179
|
end
|
160
180
|
|
161
|
-
if index_name.to_s.length >
|
162
|
-
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{
|
181
|
+
if index_name.to_s.length > max_index_length
|
182
|
+
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' is too long; the limit is #{max_index_length} characters"
|
163
183
|
end
|
164
184
|
if index_name_exists?(table_name, index_name, false)
|
165
185
|
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' already exists"
|
166
186
|
end
|
167
187
|
quoted_column_names = column_names.map { |e| quote_column_name_or_expression(e) }.join(", ")
|
168
188
|
|
169
|
-
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})#{tablespace} #{
|
189
|
+
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{quote_table_name(table_name)} (#{quoted_column_names})#{tablespace} #{additional_options}"
|
170
190
|
ensure
|
171
191
|
self.all_schema_indexes = nil
|
172
192
|
end
|
@@ -176,6 +196,14 @@ module ActiveRecord
|
|
176
196
|
def remove_index(table_name, options = {}) #:nodoc:
|
177
197
|
index_name = index_name(table_name, options)
|
178
198
|
unless index_name_exists?(table_name, index_name, true)
|
199
|
+
# sometimes options can be String or Array with column names
|
200
|
+
options = {} unless options.is_a?(Hash)
|
201
|
+
if options.has_key? :name
|
202
|
+
options_without_column = options.dup
|
203
|
+
options_without_column.delete :column
|
204
|
+
index_name_without_column = index_name(table_name, options_without_column)
|
205
|
+
return index_name_without_column if index_name_exists?(table_name, index_name_without_column, false)
|
206
|
+
end
|
179
207
|
raise ArgumentError, "Index name '#{index_name}' on table '#{table_name}' does not exist"
|
180
208
|
end
|
181
209
|
remove_index!(table_name, index_name)
|
@@ -295,27 +323,18 @@ module ActiveRecord
|
|
295
323
|
|
296
324
|
def rename_column(table_name, column_name, new_column_name) #:nodoc:
|
297
325
|
execute "ALTER TABLE #{quote_table_name(table_name)} RENAME COLUMN #{quote_column_name(column_name)} to #{quote_column_name(new_column_name)}"
|
326
|
+
self.all_schema_indexes = nil
|
327
|
+
rename_column_indexes(table_name, column_name, new_column_name)
|
298
328
|
ensure
|
299
329
|
clear_table_columns_cache(table_name)
|
300
330
|
end
|
301
331
|
|
302
332
|
def remove_column(table_name, *column_names) #:nodoc:
|
303
|
-
raise ArgumentError.new("You must specify at least one column name.
|
304
|
-
|
305
|
-
major, minor = ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR
|
306
|
-
is_deprecated = (major == 3 and minor >= 2) or major > 3
|
307
|
-
|
308
|
-
if column_names.flatten! and is_deprecated
|
309
|
-
message = 'Passing array to remove_columns is deprecated, please use ' +
|
310
|
-
'multiple arguments, like: `remove_columns(:posts, :foo, :bar)`'
|
311
|
-
ActiveSupport::Deprecation.warn message, caller
|
312
|
-
end
|
313
|
-
|
314
|
-
column_names.each do |column_name|
|
315
|
-
execute "ALTER TABLE #{quote_table_name(table_name)} DROP COLUMN #{quote_column_name(column_name)}"
|
316
|
-
end
|
333
|
+
raise ArgumentError.new("You must specify at least one column name. Example: remove_column(:people, :first_name)") if column_names.empty?
|
334
|
+
column_names.each {|column_name| execute "ALTER TABLE #{quote_table_name(table_name)} DROP COLUMN #{quote_column_name(column_name)}"}
|
317
335
|
ensure
|
318
336
|
clear_table_columns_cache(table_name)
|
337
|
+
self.all_schema_indexes = nil
|
319
338
|
end
|
320
339
|
|
321
340
|
def add_comment(table_name, column_name, comment) #:nodoc:
|
@@ -41,76 +41,6 @@ describe "OracleEnhancedAdapter" do
|
|
41
41
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
42
42
|
end
|
43
43
|
|
44
|
-
describe "database session store" do
|
45
|
-
before(:all) do
|
46
|
-
@conn.execute "DROP TABLE sessions" rescue nil
|
47
|
-
@conn.execute "DROP SEQUENCE sessions_seq" rescue nil
|
48
|
-
@conn = ActiveRecord::Base.connection
|
49
|
-
@conn.execute <<-SQL
|
50
|
-
CREATE TABLE sessions (
|
51
|
-
id NUMBER(38,0) NOT NULL,
|
52
|
-
session_id VARCHAR2(255) DEFAULT NULL,
|
53
|
-
data CLOB DEFAULT NULL,
|
54
|
-
created_at DATE DEFAULT NULL,
|
55
|
-
updated_at DATE DEFAULT NULL,
|
56
|
-
PRIMARY KEY (ID)
|
57
|
-
)
|
58
|
-
SQL
|
59
|
-
@conn.execute <<-SQL
|
60
|
-
CREATE SEQUENCE sessions_seq MINVALUE 1 MAXVALUE 999999999999999999999999999
|
61
|
-
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
62
|
-
SQL
|
63
|
-
if ENV['RAILS_GEM_VERSION'] >= '2.3'
|
64
|
-
@session_class = ActiveRecord::SessionStore::Session
|
65
|
-
else
|
66
|
-
@session_class = CGI::Session::ActiveRecordStore::Session
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
after(:all) do
|
71
|
-
@conn.execute "DROP TABLE sessions"
|
72
|
-
@conn.execute "DROP SEQUENCE sessions_seq"
|
73
|
-
end
|
74
|
-
|
75
|
-
it "should create sessions table" do
|
76
|
-
ActiveRecord::Base.connection.tables.grep("sessions").should_not be_empty
|
77
|
-
end
|
78
|
-
|
79
|
-
it "should save session data" do
|
80
|
-
@session = @session_class.new :session_id => "111111", :data => "something" #, :updated_at => Time.now
|
81
|
-
@session.save!
|
82
|
-
@session = @session_class.find_by_session_id("111111")
|
83
|
-
@session.data.should == "something"
|
84
|
-
end
|
85
|
-
|
86
|
-
it "should change session data when partial updates enabled" do
|
87
|
-
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:partial_updates=)
|
88
|
-
@session_class.partial_updates = true
|
89
|
-
@session = @session_class.new :session_id => "222222", :data => "something" #, :updated_at => Time.now
|
90
|
-
@session.save!
|
91
|
-
@session = @session_class.find_by_session_id("222222")
|
92
|
-
@session.data = "other thing"
|
93
|
-
@session.save!
|
94
|
-
# second save should call again blob writing callback
|
95
|
-
@session.save!
|
96
|
-
@session = @session_class.find_by_session_id("222222")
|
97
|
-
@session.data.should == "other thing"
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should have one enhanced_write_lobs callback" do
|
101
|
-
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:after_save_callback_chain)
|
102
|
-
@session_class.after_save_callback_chain.select{|cb| cb.method == :enhanced_write_lobs}.should have(1).record
|
103
|
-
end
|
104
|
-
|
105
|
-
it "should not set sessions table session_id column type as integer if emulate_integers_by_column_name is true" do
|
106
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
107
|
-
columns = @conn.columns('sessions')
|
108
|
-
column = columns.detect{|c| c.name == "session_id"}
|
109
|
-
column.type.should == :string
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
|
114
44
|
describe "ignore specified table columns" do
|
115
45
|
before(:all) do
|
116
46
|
@conn = ActiveRecord::Base.connection
|
@@ -186,13 +116,14 @@ describe "OracleEnhancedAdapter" do
|
|
186
116
|
before(:all) do
|
187
117
|
@conn = ActiveRecord::Base.connection
|
188
118
|
@conn.execute "DROP TABLE test_employees" rescue nil
|
189
|
-
@
|
119
|
+
@oracle11g_or_higher = !! @conn.select_value(
|
120
|
+
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) >= 11")
|
190
121
|
@conn.execute <<-SQL
|
191
122
|
CREATE TABLE test_employees (
|
192
123
|
id NUMBER PRIMARY KEY,
|
193
124
|
first_name VARCHAR2(20),
|
194
125
|
last_name VARCHAR2(25),
|
195
|
-
#{ @
|
126
|
+
#{ @oracle11g_or_higher ? "full_name AS (first_name || ' ' || last_name)," : "full_name VARCHAR2(46),"}
|
196
127
|
hire_date DATE
|
197
128
|
)
|
198
129
|
SQL
|
@@ -244,7 +175,7 @@ describe "OracleEnhancedAdapter" do
|
|
244
175
|
end
|
245
176
|
|
246
177
|
it 'should identify virtual columns as such' do
|
247
|
-
pending "Not supported in this database version" unless @
|
178
|
+
pending "Not supported in this database version" unless @oracle11g_or_higher
|
248
179
|
te = TestEmployee.connection.columns('test_employees').detect(&:virtual?)
|
249
180
|
te.name.should == 'full_name'
|
250
181
|
end
|
@@ -682,7 +613,7 @@ describe "OracleEnhancedAdapter" do
|
|
682
613
|
end
|
683
614
|
|
684
615
|
it "should load included association with more than 1000 records" do
|
685
|
-
posts = TestPost.includes(:test_comments).
|
616
|
+
posts = TestPost.includes(:test_comments).to_a
|
686
617
|
posts.size.should == @ids.size
|
687
618
|
end
|
688
619
|
|