activerecord-oracle_enhanced-adapter 1.2.1 → 1.2.2
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.
- data/History.txt +34 -0
- data/README.rdoc +10 -5
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced.rake +4 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +534 -170
- data/lib/active_record/connection_adapters/oracle_enhanced_connection.rb +53 -3
- data/lib/active_record/connection_adapters/oracle_enhanced_core_ext.rb +10 -10
- data/lib/active_record/connection_adapters/oracle_enhanced_cpk.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced_dirty.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced_jdbc_connection.rb +86 -58
- data/lib/active_record/connection_adapters/oracle_enhanced_oci_connection.rb +105 -68
- data/lib/active_record/connection_adapters/oracle_enhanced_procedures.rb +27 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_definitions.rb +164 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_dumper.rb +122 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_schema_statements_ext.rb +224 -0
- data/lib/active_record/connection_adapters/oracle_enhanced_tasks.rb +2 -2
- data/lib/active_record/connection_adapters/oracle_enhanced_version.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +230 -455
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +37 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_core_ext_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +6 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +21 -4
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +63 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +1 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +1 -1
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +255 -0
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_spec.rb +720 -0
- data/spec/spec_helper.rb +38 -7
- metadata +13 -15
@@ -1,5 +1,5 @@
|
|
1
|
-
#
|
2
|
-
if defined?(Rake.application) && Rake.application
|
1
|
+
# implementation idea taken from JDBC adapter
|
2
|
+
if defined?(Rake.application) && Rake.application && ActiveRecord::Base.configurations[RAILS_ENV]['adapter'] == 'oracle_enhanced'
|
3
3
|
oracle_enhanced_rakefile = File.dirname(__FILE__) + "/oracle_enhanced.rake"
|
4
4
|
if Rake.application.lookup("environment")
|
5
5
|
# rails tasks already defined; load the override tasks now
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../../spec_helper
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
2
|
|
3
3
|
describe "OracleEnhancedAdapter establish connection" do
|
4
4
|
|
@@ -33,558 +33,333 @@ describe "OracleEnhancedAdapter establish connection" do
|
|
33
33
|
|
34
34
|
end
|
35
35
|
|
36
|
-
describe "OracleEnhancedAdapter
|
37
|
-
|
36
|
+
describe "OracleEnhancedAdapter" do
|
38
37
|
before(:all) do
|
39
|
-
|
40
|
-
|
41
|
-
@old_conn.class.should == ActiveRecord::ConnectionAdapters::OracleAdapter
|
42
|
-
elsif RUBY_ENGINE == 'jruby'
|
43
|
-
@old_conn = ActiveRecord::Base.jdbc_connection(JDBC_CONNECTION_PARAMS)
|
44
|
-
@old_conn.class.should == ActiveRecord::ConnectionAdapters::JdbcAdapter
|
45
|
-
end
|
46
|
-
|
47
|
-
@new_conn = ActiveRecord::Base.oracle_enhanced_connection(CONNECTION_PARAMS)
|
48
|
-
@new_conn.class.should == ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
|
38
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
39
|
+
@conn = ActiveRecord::Base.connection
|
49
40
|
end
|
50
41
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
42
|
+
describe "database session store" do
|
43
|
+
before(:all) do
|
44
|
+
@conn.execute <<-SQL
|
45
|
+
CREATE TABLE sessions (
|
46
|
+
id NUMBER(38,0) NOT NULL,
|
47
|
+
session_id VARCHAR2(255) DEFAULT NULL,
|
48
|
+
data CLOB DEFAULT NULL,
|
49
|
+
created_at DATE DEFAULT NULL,
|
50
|
+
updated_at DATE DEFAULT NULL,
|
51
|
+
PRIMARY KEY (ID)
|
52
|
+
)
|
53
|
+
SQL
|
54
|
+
@conn.execute <<-SQL
|
55
|
+
CREATE SEQUENCE sessions_seq MINVALUE 1 MAXVALUE 999999999999999999999999999
|
56
|
+
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
57
|
+
SQL
|
58
|
+
if ENV['RAILS_GEM_VERSION'] >= '2.3'
|
59
|
+
@session_class = ActiveRecord::SessionStore::Session
|
60
|
+
else
|
61
|
+
@session_class = CGI::Session::ActiveRecordStore::Session
|
58
62
|
end
|
59
63
|
end
|
60
|
-
end
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
@
|
65
|
+
after(:all) do
|
66
|
+
@conn.execute "DROP TABLE sessions"
|
67
|
+
@conn.execute "DROP SEQUENCE sessions_seq"
|
65
68
|
end
|
66
69
|
|
67
|
-
it "should
|
68
|
-
|
70
|
+
it "should create sessions table" do
|
71
|
+
ActiveRecord::Base.connection.tables.grep("sessions").should_not be_empty
|
69
72
|
end
|
70
73
|
|
71
|
-
it "should
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
74
|
+
it "should save session data" do
|
75
|
+
@session = @session_class.new :session_id => "111111", :data => "something" #, :updated_at => Time.now
|
76
|
+
@session.save!
|
77
|
+
@session = @session_class.find_by_session_id("111111")
|
78
|
+
@session.data.should == "something"
|
77
79
|
end
|
78
80
|
|
79
|
-
it "should
|
80
|
-
|
81
|
+
it "should change session data when partial updates enabled" do
|
82
|
+
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:partial_updates=)
|
83
|
+
@session_class.partial_updates = true
|
84
|
+
@session = @session_class.new :session_id => "222222", :data => "something" #, :updated_at => Time.now
|
85
|
+
@session.save!
|
86
|
+
@session = @session_class.find_by_session_id("222222")
|
87
|
+
@session.data = "other thing"
|
88
|
+
@session.save!
|
89
|
+
# second save should call again blob writing callback
|
90
|
+
@session.save!
|
91
|
+
@session = @session_class.find_by_session_id("222222")
|
92
|
+
@session.data.should == "other thing"
|
81
93
|
end
|
82
94
|
|
83
|
-
it "should
|
84
|
-
|
95
|
+
it "should have one enhanced_write_lobs callback" do
|
96
|
+
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:after_save_callback_chain)
|
97
|
+
@session_class.after_save_callback_chain.select{|cb| cb.method == :enhanced_write_lobs}.should have(1).record
|
85
98
|
end
|
86
|
-
end
|
87
99
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
SQL
|
94
|
-
if /.*session_id nvarchar2\((\d+)\).*/ =~ @new_conn.structure_dump
|
95
|
-
"#$1".should == "255"
|
100
|
+
it "should not set sessions table session_id column type as integer if emulate_integers_by_column_name is true" do
|
101
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
102
|
+
columns = @conn.columns('sessions')
|
103
|
+
column = columns.detect{|c| c.name == "session_id"}
|
104
|
+
column.type.should == :string
|
96
105
|
end
|
97
|
-
@new_conn.execute "DROP TABLE nvarchartable"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
describe "OracleEnhancedAdapter database stucture dump extentions" do
|
102
|
-
before(:all) do
|
103
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
104
|
-
@conn = ActiveRecord::Base.connection
|
105
|
-
@conn.execute <<-SQL
|
106
|
-
CREATE TABLE nvarchartable (
|
107
|
-
unq_nvarchar NVARCHAR2(255) DEFAULT NULL
|
108
|
-
)
|
109
|
-
SQL
|
110
|
-
end
|
111
106
|
|
112
|
-
after(:all) do
|
113
|
-
@conn.execute "DROP TABLE nvarchartable"
|
114
107
|
end
|
115
108
|
|
116
|
-
|
117
|
-
|
118
|
-
|
109
|
+
describe "ignore specified table columns" do
|
110
|
+
before(:all) do
|
111
|
+
@conn.execute <<-SQL
|
112
|
+
CREATE TABLE test_employees (
|
113
|
+
id NUMBER,
|
114
|
+
first_name VARCHAR2(20),
|
115
|
+
last_name VARCHAR2(25),
|
116
|
+
email VARCHAR2(25),
|
117
|
+
phone_number VARCHAR2(20),
|
118
|
+
hire_date DATE,
|
119
|
+
job_id NUMBER,
|
120
|
+
salary NUMBER,
|
121
|
+
commission_pct NUMBER(2,2),
|
122
|
+
manager_id NUMBER(6),
|
123
|
+
department_id NUMBER(4,0),
|
124
|
+
created_at DATE
|
125
|
+
)
|
126
|
+
SQL
|
127
|
+
@conn.execute <<-SQL
|
128
|
+
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
129
|
+
INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
|
130
|
+
SQL
|
119
131
|
end
|
120
|
-
end
|
121
|
-
end
|
122
132
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
@conn = ActiveRecord::Base.connection
|
127
|
-
@conn.execute <<-SQL
|
128
|
-
CREATE TABLE sessions (
|
129
|
-
id NUMBER(38,0) NOT NULL,
|
130
|
-
session_id VARCHAR2(255) DEFAULT NULL,
|
131
|
-
data CLOB DEFAULT NULL,
|
132
|
-
created_at DATE DEFAULT NULL,
|
133
|
-
updated_at DATE DEFAULT NULL,
|
134
|
-
PRIMARY KEY (ID)
|
135
|
-
)
|
136
|
-
SQL
|
137
|
-
@conn.execute <<-SQL
|
138
|
-
CREATE SEQUENCE sessions_seq MINVALUE 1 MAXVALUE 999999999999999999999999999
|
139
|
-
INCREMENT BY 1 START WITH 10040 CACHE 20 NOORDER NOCYCLE
|
140
|
-
SQL
|
141
|
-
if ENV['RAILS_GEM_VERSION'] >= '2.3'
|
142
|
-
@session_class = ActiveRecord::SessionStore::Session
|
143
|
-
else
|
144
|
-
@session_class = CGI::Session::ActiveRecordStore::Session
|
133
|
+
after(:all) do
|
134
|
+
@conn.execute "DROP TABLE test_employees"
|
135
|
+
@conn.execute "DROP SEQUENCE test_employees_seq"
|
145
136
|
end
|
146
|
-
end
|
147
|
-
|
148
|
-
after(:all) do
|
149
|
-
@conn.execute "DROP TABLE sessions"
|
150
|
-
@conn.execute "DROP SEQUENCE sessions_seq"
|
151
|
-
end
|
152
|
-
|
153
|
-
it "should create sessions table" do
|
154
|
-
ActiveRecord::Base.connection.tables.grep("sessions").should_not be_empty
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should save session data" do
|
158
|
-
@session = @session_class.new :session_id => "111111", :data => "something" #, :updated_at => Time.now
|
159
|
-
@session.save!
|
160
|
-
@session = @session_class.find_by_session_id("111111")
|
161
|
-
@session.data.should == "something"
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should change session data when partial updates enabled" do
|
165
|
-
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:partial_updates=)
|
166
|
-
@session_class.partial_updates = true
|
167
|
-
@session = @session_class.new :session_id => "222222", :data => "something" #, :updated_at => Time.now
|
168
|
-
@session.save!
|
169
|
-
@session = @session_class.find_by_session_id("222222")
|
170
|
-
@session.data = "other thing"
|
171
|
-
@session.save!
|
172
|
-
# second save should call again blob writing callback
|
173
|
-
@session.save!
|
174
|
-
@session = @session_class.find_by_session_id("222222")
|
175
|
-
@session.data.should == "other thing"
|
176
|
-
end
|
177
|
-
|
178
|
-
it "should have one enhanced_write_lobs callback" do
|
179
|
-
return pending("Not in this ActiveRecord version") unless @session_class.respond_to?(:after_save_callback_chain)
|
180
|
-
@session_class.after_save_callback_chain.select{|cb| cb.method == :enhanced_write_lobs}.should have(1).record
|
181
|
-
end
|
182
|
-
|
183
|
-
it "should not set sessions table session_id column type as integer if emulate_integers_by_column_name is true" do
|
184
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.emulate_integers_by_column_name = true
|
185
|
-
columns = @conn.columns('sessions')
|
186
|
-
column = columns.detect{|c| c.name == "session_id"}
|
187
|
-
column.type.should == :string
|
188
|
-
end
|
189
|
-
|
190
|
-
end
|
191
|
-
|
192
|
-
describe "OracleEnhancedAdapter ignore specified table columns" do
|
193
|
-
before(:all) do
|
194
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
195
|
-
@conn = ActiveRecord::Base.connection
|
196
|
-
@conn.execute <<-SQL
|
197
|
-
CREATE TABLE test_employees (
|
198
|
-
id NUMBER,
|
199
|
-
first_name VARCHAR2(20),
|
200
|
-
last_name VARCHAR2(25),
|
201
|
-
email VARCHAR2(25),
|
202
|
-
phone_number VARCHAR2(20),
|
203
|
-
hire_date DATE,
|
204
|
-
job_id NUMBER,
|
205
|
-
salary NUMBER,
|
206
|
-
commission_pct NUMBER(2,2),
|
207
|
-
manager_id NUMBER(6),
|
208
|
-
department_id NUMBER(4,0),
|
209
|
-
created_at DATE
|
210
|
-
)
|
211
|
-
SQL
|
212
|
-
@conn.execute <<-SQL
|
213
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
214
|
-
INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
|
215
|
-
SQL
|
216
|
-
end
|
217
|
-
|
218
|
-
after(:all) do
|
219
|
-
@conn.execute "DROP TABLE test_employees"
|
220
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
221
|
-
end
|
222
137
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
it "should ignore specified table columns" do
|
228
|
-
class ::TestEmployee < ActiveRecord::Base
|
229
|
-
ignore_table_columns :phone_number, :hire_date
|
138
|
+
after(:each) do
|
139
|
+
Object.send(:remove_const, "TestEmployee")
|
140
|
+
ActiveRecord::Base.connection.clear_ignored_table_columns
|
230
141
|
end
|
231
|
-
TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
|
232
|
-
end
|
233
142
|
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
143
|
+
it "should ignore specified table columns" do
|
144
|
+
class ::TestEmployee < ActiveRecord::Base
|
145
|
+
ignore_table_columns :phone_number, :hire_date
|
146
|
+
end
|
147
|
+
TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
|
238
148
|
end
|
239
|
-
TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
|
240
|
-
end
|
241
149
|
|
242
|
-
|
243
|
-
|
244
|
-
|
150
|
+
it "should ignore specified table columns specified in several lines" do
|
151
|
+
class ::TestEmployee < ActiveRecord::Base
|
152
|
+
ignore_table_columns :phone_number
|
153
|
+
ignore_table_columns :hire_date
|
154
|
+
end
|
155
|
+
TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
|
245
156
|
end
|
246
|
-
TestEmployee.connection.columns('test_employees').select{|c| c.name == 'email' }.should_not be_empty
|
247
|
-
end
|
248
|
-
|
249
157
|
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
before(:all) do
|
255
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
256
|
-
ActiveRecord::Schema.define do
|
257
|
-
suppress_messages do
|
258
|
-
create_table :keyboards, :force => true, :id => false do |t|
|
259
|
-
t.primary_key :key_number
|
260
|
-
t.string :name
|
261
|
-
end
|
262
|
-
create_table :id_keyboards, :force => true do |t|
|
263
|
-
t.string :name
|
264
|
-
end
|
158
|
+
it "should not ignore unspecified table columns" do
|
159
|
+
class ::TestEmployee < ActiveRecord::Base
|
160
|
+
ignore_table_columns :phone_number, :hire_date
|
265
161
|
end
|
162
|
+
TestEmployee.connection.columns('test_employees').select{|c| c.name == 'email' }.should_not be_empty
|
266
163
|
end
|
267
|
-
class ::Keyboard < ActiveRecord::Base
|
268
|
-
set_primary_key :key_number
|
269
|
-
end
|
270
|
-
class ::IdKeyboard < ActiveRecord::Base
|
271
|
-
end
|
272
|
-
end
|
273
164
|
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
drop_table :keyboards
|
278
|
-
drop_table :id_keyboards
|
165
|
+
it "should ignore specified table columns in other connection" do
|
166
|
+
class ::TestEmployee < ActiveRecord::Base
|
167
|
+
ignore_table_columns :phone_number, :hire_date
|
279
168
|
end
|
169
|
+
# establish other connection
|
170
|
+
other_conn = ActiveRecord::Base.oracle_enhanced_connection(CONNECTION_PARAMS)
|
171
|
+
other_conn.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }.should be_empty
|
280
172
|
end
|
281
|
-
Object.send(:remove_const, "Keyboard")
|
282
|
-
Object.send(:remove_const, "IdKeyboard")
|
283
|
-
end
|
284
173
|
|
285
|
-
it "should create sequence for non-default primary key" do
|
286
|
-
ActiveRecord::Base.connection.next_sequence_value(Keyboard.sequence_name).should_not be_nil
|
287
174
|
end
|
288
175
|
|
289
|
-
|
290
|
-
ActiveRecord::Base.connection.next_sequence_value(IdKeyboard.sequence_name).should_not be_nil
|
291
|
-
end
|
292
|
-
end
|
176
|
+
describe "without composite_primary_keys" do
|
293
177
|
|
294
|
-
|
178
|
+
before(:all) do
|
179
|
+
Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
|
180
|
+
class ::Employee < ActiveRecord::Base
|
181
|
+
set_primary_key :employee_id
|
182
|
+
end
|
183
|
+
end
|
295
184
|
|
296
|
-
|
297
|
-
|
298
|
-
Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
|
299
|
-
class ::Employee < ActiveRecord::Base
|
300
|
-
set_primary_key :employee_id
|
185
|
+
it "should tell ActiveRecord that count distinct is supported" do
|
186
|
+
ActiveRecord::Base.connection.supports_count_distinct?.should be_true
|
301
187
|
end
|
302
|
-
end
|
303
188
|
|
304
|
-
|
305
|
-
|
306
|
-
|
189
|
+
it "should execute correct SQL COUNT DISTINCT statement" do
|
190
|
+
lambda { Employee.count(:employee_id, :distinct => true) }.should_not raise_error
|
191
|
+
end
|
307
192
|
|
308
|
-
it "should execute correct SQL COUNT DISTINCT statement" do
|
309
|
-
lambda { Employee.count(:employee_id, :distinct => true) }.should_not raise_error
|
310
193
|
end
|
311
194
|
|
312
|
-
end
|
313
|
-
|
314
|
-
describe "OracleEnhancedAdapter sequence creation parameters" do
|
315
195
|
|
316
|
-
|
317
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
318
|
-
end
|
196
|
+
describe "column quoting" do
|
319
197
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
198
|
+
def create_test_reserved_words_table
|
199
|
+
ActiveRecord::Schema.define do
|
200
|
+
suppress_messages do
|
201
|
+
create_table :test_reserved_words do |t|
|
202
|
+
t.string :varchar2
|
203
|
+
t.integer :integer
|
204
|
+
end
|
326
205
|
end
|
327
206
|
end
|
328
207
|
end
|
329
|
-
end
|
330
|
-
|
331
|
-
def save_default_sequence_start_value
|
332
|
-
@saved_sequence_start_value = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value
|
333
|
-
end
|
334
|
-
|
335
|
-
def restore_default_sequence_start_value
|
336
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_sequence_start_value = @saved_sequence_start_value
|
337
|
-
end
|
338
208
|
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
ActiveRecord::Schema.define do
|
345
|
-
suppress_messages do
|
346
|
-
drop_table :test_employees
|
209
|
+
after(:each) do
|
210
|
+
ActiveRecord::Schema.define do
|
211
|
+
suppress_messages do
|
212
|
+
drop_table :test_reserved_words
|
213
|
+
end
|
347
214
|
end
|
215
|
+
Object.send(:remove_const, "TestReservedWord")
|
216
|
+
ActiveRecord::Base.table_name_prefix = nil
|
348
217
|
end
|
349
|
-
Object.send(:remove_const, "TestEmployee")
|
350
|
-
end
|
351
218
|
|
352
|
-
|
353
|
-
|
219
|
+
it "should allow creation of a table with oracle reserved words as column names" do
|
220
|
+
create_test_reserved_words_table
|
221
|
+
class ::TestReservedWord < ActiveRecord::Base; end
|
354
222
|
|
355
|
-
|
356
|
-
|
223
|
+
[:varchar2, :integer].each do |attr|
|
224
|
+
TestReservedWord.columns_hash[attr.to_s].name.should == attr.to_s
|
225
|
+
end
|
226
|
+
end
|
357
227
|
|
358
|
-
employee = TestEmployee.create!
|
359
|
-
employee.id.should == 10000
|
360
228
|
end
|
361
229
|
|
362
|
-
|
363
|
-
|
230
|
+
describe "valid table names" do
|
231
|
+
before(:all) do
|
232
|
+
@adapter = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
|
233
|
+
end
|
364
234
|
|
365
|
-
|
366
|
-
|
235
|
+
it "should be valid with letters and digits" do
|
236
|
+
@adapter.valid_table_name?("abc_123").should be_true
|
237
|
+
end
|
367
238
|
|
368
|
-
|
369
|
-
|
370
|
-
|
239
|
+
it "should be valid with schema name" do
|
240
|
+
@adapter.valid_table_name?("abc_123.def_456").should be_true
|
241
|
+
end
|
371
242
|
|
372
|
-
|
373
|
-
|
374
|
-
|
243
|
+
it "should be valid with $ in name" do
|
244
|
+
@adapter.valid_table_name?("sys.v$session").should be_true
|
245
|
+
end
|
375
246
|
|
376
|
-
|
377
|
-
|
378
|
-
|
247
|
+
it "should not be valid with two dots in name" do
|
248
|
+
@adapter.valid_table_name?("abc_123.def_456.ghi_789").should be_false
|
249
|
+
end
|
379
250
|
|
380
|
-
|
381
|
-
|
382
|
-
|
251
|
+
it "should not be valid with invalid characters" do
|
252
|
+
@adapter.valid_table_name?("warehouse-things").should be_false
|
253
|
+
end
|
383
254
|
|
384
|
-
employee = TestEmployee.create!
|
385
|
-
employee.id.should == 100
|
386
|
-
employee = TestEmployee.create!
|
387
|
-
employee.id.should == 110
|
388
255
|
end
|
389
256
|
|
390
|
-
|
391
|
-
|
392
|
-
describe "OracleEnhancedAdapter table and column comments" do
|
393
|
-
|
394
|
-
before(:all) do
|
395
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
396
|
-
@conn = ActiveRecord::Base.connection
|
397
|
-
end
|
257
|
+
describe "table quoting" do
|
398
258
|
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
259
|
+
def create_warehouse_things_table
|
260
|
+
ActiveRecord::Schema.define do
|
261
|
+
suppress_messages do
|
262
|
+
create_table "warehouse-things" do |t|
|
263
|
+
t.string :name
|
264
|
+
t.integer :foo
|
265
|
+
end
|
405
266
|
end
|
406
267
|
end
|
407
268
|
end
|
408
|
-
end
|
409
269
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
270
|
+
def create_camel_case_table
|
271
|
+
ActiveRecord::Schema.define do
|
272
|
+
suppress_messages do
|
273
|
+
create_table "CamelCase" do |t|
|
274
|
+
t.string :name
|
275
|
+
t.integer :foo
|
276
|
+
end
|
277
|
+
end
|
414
278
|
end
|
415
279
|
end
|
416
|
-
Object.send(:remove_const, "TestEmployee")
|
417
|
-
ActiveRecord::Base.table_name_prefix = nil
|
418
|
-
end
|
419
|
-
|
420
|
-
it "should create table with table comment" do
|
421
|
-
table_comment = "Test Employees"
|
422
|
-
create_test_employees_table(table_comment)
|
423
|
-
class ::TestEmployee < ActiveRecord::Base; end
|
424
|
-
|
425
|
-
@conn.table_comment("test_employees").should == table_comment
|
426
|
-
TestEmployee.table_comment.should == table_comment
|
427
|
-
end
|
428
|
-
|
429
|
-
it "should create table with columns comment" do
|
430
|
-
column_comments = {:first_name => "Given Name", :last_name => "Surname"}
|
431
|
-
create_test_employees_table(nil, column_comments)
|
432
|
-
class ::TestEmployee < ActiveRecord::Base; end
|
433
|
-
|
434
|
-
[:first_name, :last_name].each do |attr|
|
435
|
-
@conn.column_comment("test_employees", attr.to_s).should == column_comments[attr]
|
436
|
-
end
|
437
|
-
[:first_name, :last_name].each do |attr|
|
438
|
-
TestEmployee.columns_hash[attr.to_s].comment.should == column_comments[attr]
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
it "should create table with table and columns comment and custom table name prefix" do
|
443
|
-
ActiveRecord::Base.table_name_prefix = "xxx_"
|
444
|
-
table_comment = "Test Employees"
|
445
|
-
column_comments = {:first_name => "Given Name", :last_name => "Surname"}
|
446
|
-
create_test_employees_table(table_comment, column_comments)
|
447
|
-
class ::TestEmployee < ActiveRecord::Base; end
|
448
|
-
|
449
|
-
@conn.table_comment(TestEmployee.table_name).should == table_comment
|
450
|
-
TestEmployee.table_comment.should == table_comment
|
451
|
-
[:first_name, :last_name].each do |attr|
|
452
|
-
@conn.column_comment(TestEmployee.table_name, attr.to_s).should == column_comments[attr]
|
453
|
-
end
|
454
|
-
[:first_name, :last_name].each do |attr|
|
455
|
-
TestEmployee.columns_hash[attr.to_s].comment.should == column_comments[attr]
|
456
|
-
end
|
457
|
-
end
|
458
280
|
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
465
|
-
@conn = ActiveRecord::Base.connection
|
466
|
-
end
|
467
|
-
|
468
|
-
def create_test_reserved_words_table
|
469
|
-
ActiveRecord::Schema.define do
|
470
|
-
suppress_messages do
|
471
|
-
create_table :test_reserved_words do |t|
|
472
|
-
t.string :varchar2
|
473
|
-
t.integer :integer
|
281
|
+
after(:each) do
|
282
|
+
ActiveRecord::Schema.define do
|
283
|
+
suppress_messages do
|
284
|
+
drop_table "warehouse-things" rescue nil
|
285
|
+
drop_table "CamelCase" rescue nil
|
474
286
|
end
|
475
287
|
end
|
288
|
+
Object.send(:remove_const, "WarehouseThing") rescue nil
|
289
|
+
Object.send(:remove_const, "CamelCase") rescue nil
|
476
290
|
end
|
477
|
-
end
|
478
291
|
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
292
|
+
it "should allow creation of a table with non alphanumeric characters" do
|
293
|
+
create_warehouse_things_table
|
294
|
+
class ::WarehouseThing < ActiveRecord::Base
|
295
|
+
set_table_name "warehouse-things"
|
483
296
|
end
|
484
|
-
end
|
485
|
-
Object.send(:remove_const, "TestReservedWord")
|
486
|
-
ActiveRecord::Base.table_name_prefix = nil
|
487
|
-
end
|
488
297
|
|
489
|
-
|
490
|
-
|
491
|
-
class ::TestReservedWord < ActiveRecord::Base; end
|
298
|
+
wh = WarehouseThing.create!(:name => "Foo", :foo => 2)
|
299
|
+
wh.id.should_not be_nil
|
492
300
|
|
493
|
-
|
494
|
-
TestReservedWord.columns_hash[attr.to_s].name.should == attr.to_s
|
301
|
+
@conn.tables.should include("warehouse-things")
|
495
302
|
end
|
496
|
-
end
|
497
|
-
|
498
|
-
end
|
499
|
-
|
500
|
-
describe "OracleEnhancedAdapter valid table names" do
|
501
|
-
before(:all) do
|
502
|
-
@adapter = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter
|
503
|
-
end
|
504
|
-
it "should be valid with letters and digits" do
|
505
|
-
@adapter.valid_table_name?("abc_123").should be_true
|
506
|
-
end
|
507
|
-
|
508
|
-
it "should be valid with schema name" do
|
509
|
-
@adapter.valid_table_name?("abc_123.def_456").should be_true
|
510
|
-
end
|
511
|
-
|
512
|
-
it "should be valid with $ in name" do
|
513
|
-
@adapter.valid_table_name?("sys.v$session").should be_true
|
514
|
-
end
|
515
|
-
|
516
|
-
it "should not be valid with two dots in name" do
|
517
|
-
@adapter.valid_table_name?("abc_123.def_456.ghi_789").should be_false
|
518
|
-
end
|
519
|
-
|
520
|
-
it "should not be valid with invalid characters" do
|
521
|
-
@adapter.valid_table_name?("warehouse-things").should be_false
|
522
|
-
end
|
523
303
|
|
524
|
-
|
304
|
+
it "should allow creation of a table with CamelCase name" do
|
305
|
+
create_camel_case_table
|
306
|
+
class ::CamelCase < ActiveRecord::Base
|
307
|
+
set_table_name "CamelCase"
|
308
|
+
end
|
525
309
|
|
526
|
-
|
310
|
+
cc = CamelCase.create!(:name => "Foo", :foo => 2)
|
311
|
+
cc.id.should_not be_nil
|
312
|
+
|
313
|
+
@conn.tables.should include("CamelCase")
|
314
|
+
end
|
527
315
|
|
528
|
-
before(:all) do
|
529
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
530
|
-
@conn = ActiveRecord::Base.connection
|
531
316
|
end
|
532
317
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
318
|
+
describe "access table over database link" do
|
319
|
+
before(:all) do
|
320
|
+
@db_link = "db_link"
|
321
|
+
@sys_conn = ActiveRecord::Base.oracle_enhanced_connection(SYSTEM_CONNECTION_PARAMS)
|
322
|
+
@sys_conn.drop_table :test_posts rescue nil
|
323
|
+
@sys_conn.create_table :test_posts do |t|
|
324
|
+
t.string :title
|
325
|
+
# cannot update LOBs over database link
|
326
|
+
t.string :body
|
327
|
+
t.timestamps
|
540
328
|
end
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
t.integer :foo
|
550
|
-
end
|
329
|
+
@db_link_username = SYSTEM_CONNECTION_PARAMS[:username]
|
330
|
+
@db_link_password = SYSTEM_CONNECTION_PARAMS[:password]
|
331
|
+
@db_link_database = SYSTEM_CONNECTION_PARAMS[:database]
|
332
|
+
@conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
|
333
|
+
@conn.execute "CREATE DATABASE LINK #{@db_link} CONNECT TO #{@db_link_username} IDENTIFIED BY #{@db_link_password} USING '#{@db_link_database}'"
|
334
|
+
@conn.execute "CREATE OR REPLACE SYNONYM test_posts FOR test_posts@#{@db_link}"
|
335
|
+
@conn.execute "CREATE OR REPLACE SYNONYM test_posts_seq FOR test_posts_seq@#{@db_link}"
|
336
|
+
class ::TestPost < ActiveRecord::Base
|
551
337
|
end
|
338
|
+
TestPost.set_table_name "test_posts"
|
552
339
|
end
|
553
|
-
end
|
554
340
|
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
341
|
+
after(:all) do
|
342
|
+
@conn.execute "DROP SYNONYM test_posts"
|
343
|
+
@conn.execute "DROP SYNONYM test_posts_seq"
|
344
|
+
@conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
|
345
|
+
@sys_conn.drop_table :test_posts rescue nil
|
346
|
+
Object.send(:remove_const, "TestPost") rescue nil
|
561
347
|
end
|
562
|
-
Object.send(:remove_const, "WarehouseThing") rescue nil
|
563
|
-
Object.send(:remove_const, "CamelCase") rescue nil
|
564
|
-
end
|
565
348
|
|
566
|
-
|
567
|
-
|
568
|
-
class ::WarehouseThing < ActiveRecord::Base
|
569
|
-
set_table_name "warehouse-things"
|
349
|
+
it "should verify database link" do
|
350
|
+
@conn.select_value("select * from dual@#{@db_link}") == 'X'
|
570
351
|
end
|
571
352
|
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
@conn.tables.should include("warehouse-things")
|
576
|
-
end
|
353
|
+
it "should get column names" do
|
354
|
+
TestPost.column_names.should == ["id", "title", "body", "created_at", "updated_at"]
|
355
|
+
end
|
577
356
|
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
357
|
+
it "should create record" do
|
358
|
+
p = TestPost.create(:title => "Title", :body => "Body")
|
359
|
+
p.id.should_not be_nil
|
360
|
+
TestPost.find(p.id).should_not be_nil
|
582
361
|
end
|
583
362
|
|
584
|
-
cc = CamelCase.create!(:name => "Foo", :foo => 2)
|
585
|
-
cc.id.should_not be_nil
|
586
|
-
|
587
|
-
@conn.tables.should include("CamelCase")
|
588
363
|
end
|
589
364
|
|
590
365
|
end
|