activerecord-oracle_enhanced-adapter 1.7.3 → 1.8.0
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/History.md +288 -0
- data/README.md +44 -0
- data/VERSION +1 -1
- data/lib/active_record/connection_adapters/emulation/oracle_adapter.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced/column.rb +7 -63
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -52
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +13 -16
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -119
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +33 -27
- data/lib/active_record/connection_adapters/oracle_enhanced/database_tasks.rb +10 -10
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_connection.rb +59 -77
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +56 -82
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +77 -77
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +16 -45
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -65
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -51
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +149 -162
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +119 -122
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +69 -107
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +315 -538
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -11
- data/lib/active_record/oracle_enhanced/type/integer.rb +4 -5
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -2
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -4
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -4
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +14 -13
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +129 -166
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +50 -33
- data/spec/active_record/connection_adapters/oracle_enhanced_context_index_spec.rb +44 -42
- data/spec/active_record/connection_adapters/oracle_enhanced_data_types_spec.rb +283 -378
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -7
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +5 -7
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +118 -127
- data/spec/active_record/connection_adapters/oracle_enhanced_emulate_oracle_adapter_spec.rb +2 -3
- data/spec/active_record/connection_adapters/oracle_enhanced_procedures_spec.rb +74 -78
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +68 -83
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +308 -321
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +103 -48
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -60
- data/spec/support/alter_system_user_password.sql +2 -0
- data/spec/support/create_oracle_enhanced_users.sql +31 -0
- metadata +25 -25
- data/.rspec +0 -2
- data/Gemfile +0 -22
- data/RUNNING_TESTS.md +0 -50
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -95
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -21
- data/spec/active_record/connection_adapters/oracle_enhanced_cpk_spec.rb +0 -113
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
1
|
describe "OracleEnhancedAdapter establish connection" do
|
|
4
2
|
|
|
5
3
|
it "should connect to database" do
|
|
@@ -30,7 +28,7 @@ describe "OracleEnhancedAdapter establish connection" do
|
|
|
30
28
|
ActiveRecord::Base.connection.reconnect!
|
|
31
29
|
expect(ActiveRecord::Base.connection).to be_active
|
|
32
30
|
end
|
|
33
|
-
|
|
31
|
+
|
|
34
32
|
end
|
|
35
33
|
|
|
36
34
|
describe "OracleEnhancedAdapter" do
|
|
@@ -40,77 +38,6 @@ describe "OracleEnhancedAdapter" do
|
|
|
40
38
|
before(:all) do
|
|
41
39
|
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
|
|
42
40
|
end
|
|
43
|
-
|
|
44
|
-
describe "ignore specified table columns" do
|
|
45
|
-
before(:all) do
|
|
46
|
-
@conn = ActiveRecord::Base.connection
|
|
47
|
-
@conn.execute "DROP TABLE test_employees" rescue nil
|
|
48
|
-
@conn.execute <<-SQL
|
|
49
|
-
CREATE TABLE test_employees (
|
|
50
|
-
id NUMBER PRIMARY KEY,
|
|
51
|
-
first_name VARCHAR2(20),
|
|
52
|
-
last_name VARCHAR2(25),
|
|
53
|
-
email VARCHAR2(25),
|
|
54
|
-
phone_number VARCHAR2(20),
|
|
55
|
-
hire_date DATE,
|
|
56
|
-
job_id NUMBER,
|
|
57
|
-
salary NUMBER,
|
|
58
|
-
commission_pct NUMBER(2,2),
|
|
59
|
-
manager_id NUMBER(6),
|
|
60
|
-
department_id NUMBER(4,0),
|
|
61
|
-
created_at DATE
|
|
62
|
-
)
|
|
63
|
-
SQL
|
|
64
|
-
@conn.execute "DROP SEQUENCE test_employees_seq" rescue nil
|
|
65
|
-
@conn.execute <<-SQL
|
|
66
|
-
CREATE SEQUENCE test_employees_seq MINVALUE 1
|
|
67
|
-
INCREMENT BY 1 START WITH 1 CACHE 20 NOORDER NOCYCLE
|
|
68
|
-
SQL
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
after(:all) do
|
|
72
|
-
@conn.execute "DROP TABLE test_employees"
|
|
73
|
-
@conn.execute "DROP SEQUENCE test_employees_seq"
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
after(:each) do
|
|
77
|
-
Object.send(:remove_const, "TestEmployee")
|
|
78
|
-
ActiveRecord::Base.connection.clear_ignored_table_columns
|
|
79
|
-
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
it "should ignore specified table columns" do
|
|
83
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
84
|
-
ignore_table_columns :phone_number, :hire_date
|
|
85
|
-
end
|
|
86
|
-
expect(TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }).to be_empty
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it "should ignore specified table columns specified in several lines" do
|
|
90
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
91
|
-
ignore_table_columns :phone_number
|
|
92
|
-
ignore_table_columns :hire_date
|
|
93
|
-
end
|
|
94
|
-
expect(TestEmployee.connection.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }).to be_empty
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it "should not ignore unspecified table columns" do
|
|
98
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
99
|
-
ignore_table_columns :phone_number, :hire_date
|
|
100
|
-
end
|
|
101
|
-
expect(TestEmployee.connection.columns('test_employees').select{|c| c.name == 'email' }).not_to be_empty
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
it "should ignore specified table columns in other connection" do
|
|
105
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
106
|
-
ignore_table_columns :phone_number, :hire_date
|
|
107
|
-
end
|
|
108
|
-
# establish other connection
|
|
109
|
-
other_conn = ActiveRecord::Base.oracle_enhanced_connection(CONNECTION_PARAMS)
|
|
110
|
-
expect(other_conn.columns('test_employees').select{|c| ['phone_number','hire_date'].include?(c.name) }).to be_empty
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
end
|
|
114
41
|
|
|
115
42
|
describe "cache table columns" do
|
|
116
43
|
before(:all) do
|
|
@@ -134,7 +61,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
134
61
|
hire_date DATE
|
|
135
62
|
)
|
|
136
63
|
SQL
|
|
137
|
-
@column_names = [
|
|
64
|
+
@column_names = ["id", "first_name", "last_name", "full_name", "hire_date"]
|
|
138
65
|
@column_sql_types = ["NUMBER", "VARCHAR2(20)", "VARCHAR2(25)", "VARCHAR2(46)", "DATE"]
|
|
139
66
|
class ::TestEmployee < ActiveRecord::Base
|
|
140
67
|
end
|
|
@@ -151,7 +78,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
151
78
|
@conn.execute "DROP TABLE test_employees"
|
|
152
79
|
@conn.execute "DROP TABLE test_employees_without_pk"
|
|
153
80
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = nil
|
|
154
|
-
ActiveRecord::Base.clear_cache!
|
|
81
|
+
ActiveRecord::Base.clear_cache!
|
|
155
82
|
end
|
|
156
83
|
|
|
157
84
|
before(:each) do
|
|
@@ -170,33 +97,33 @@ describe "OracleEnhancedAdapter" do
|
|
|
170
97
|
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.cache_columns = false
|
|
171
98
|
end
|
|
172
99
|
|
|
173
|
-
it
|
|
100
|
+
it "should identify virtual columns as such" do
|
|
174
101
|
skip "Not supported in this database version" unless @oracle11g_or_higher
|
|
175
|
-
te = TestEmployee.connection.columns(
|
|
176
|
-
expect(te.name).to eq(
|
|
102
|
+
te = TestEmployee.connection.columns("test_employees").detect(&:virtual?)
|
|
103
|
+
expect(te.name).to eq("full_name")
|
|
177
104
|
end
|
|
178
105
|
|
|
179
106
|
it "should get columns from database at first time" do
|
|
180
|
-
expect(TestEmployee.connection.columns(
|
|
107
|
+
expect(TestEmployee.connection.columns("test_employees").map(&:name)).to eq(@column_names)
|
|
181
108
|
expect(@logger.logged(:debug).last).to match(/select .* from all_tab_cols/im)
|
|
182
109
|
end
|
|
183
110
|
|
|
184
111
|
it "should get columns from database at second time" do
|
|
185
|
-
TestEmployee.connection.columns(
|
|
112
|
+
TestEmployee.connection.columns("test_employees")
|
|
186
113
|
@logger.clear(:debug)
|
|
187
|
-
expect(TestEmployee.connection.columns(
|
|
114
|
+
expect(TestEmployee.connection.columns("test_employees").map(&:name)).to eq(@column_names)
|
|
188
115
|
expect(@logger.logged(:debug).last).to match(/select .* from all_tab_cols/im)
|
|
189
116
|
end
|
|
190
117
|
|
|
191
118
|
it "should get primary key from database at first time" do
|
|
192
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
119
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees")).to eq(["id", nil])
|
|
193
120
|
expect(@logger.logged(:debug).last).to match(/select .* from all_constraints/im)
|
|
194
121
|
end
|
|
195
122
|
|
|
196
123
|
it "should get primary key from database at first time" do
|
|
197
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
124
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees")).to eq(["id", nil])
|
|
198
125
|
@logger.clear(:debug)
|
|
199
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
126
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees")).to eq(["id", nil])
|
|
200
127
|
expect(@logger.logged(:debug).last).to match(/select .* from all_constraints/im)
|
|
201
128
|
end
|
|
202
129
|
|
|
@@ -216,33 +143,33 @@ describe "OracleEnhancedAdapter" do
|
|
|
216
143
|
end
|
|
217
144
|
|
|
218
145
|
it "should get columns from database at first time" do
|
|
219
|
-
expect(TestEmployee.connection.columns(
|
|
146
|
+
expect(TestEmployee.connection.columns("test_employees").map(&:name)).to eq(@column_names)
|
|
220
147
|
expect(@logger.logged(:debug).last).to match(/select .* from all_tab_cols/im)
|
|
221
148
|
end
|
|
222
149
|
|
|
223
150
|
it "should get columns from cache at second time" do
|
|
224
|
-
TestEmployee.connection.columns(
|
|
151
|
+
TestEmployee.connection.columns("test_employees")
|
|
225
152
|
@logger.clear(:debug)
|
|
226
|
-
expect(TestEmployee.connection.columns(
|
|
153
|
+
expect(TestEmployee.connection.columns("test_employees").map(&:name)).to eq(@column_names)
|
|
227
154
|
expect(@logger.logged(:debug).last).to be_blank
|
|
228
155
|
end
|
|
229
156
|
|
|
230
157
|
it "should get primary key from database at first time" do
|
|
231
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
158
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees")).to eq(["id", nil])
|
|
232
159
|
expect(@logger.logged(:debug).last).to match(/select .* from all_constraints/im)
|
|
233
160
|
end
|
|
234
161
|
|
|
235
162
|
it "should get primary key from cache at first time" do
|
|
236
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
163
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees")).to eq(["id", nil])
|
|
237
164
|
@logger.clear(:debug)
|
|
238
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
165
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees")).to eq(["id", nil])
|
|
239
166
|
expect(@logger.logged(:debug).last).to be_blank
|
|
240
167
|
end
|
|
241
168
|
|
|
242
169
|
it "should store primary key as nil in cache at first time for table without primary key" do
|
|
243
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
170
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees_without_pk")).to eq(nil)
|
|
244
171
|
@logger.clear(:debug)
|
|
245
|
-
expect(TestEmployee.connection.pk_and_sequence_for(
|
|
172
|
+
expect(TestEmployee.connection.pk_and_sequence_for("test_employees_without_pk")).to eq(nil)
|
|
246
173
|
expect(@logger.logged(:debug).last).to be_blank
|
|
247
174
|
end
|
|
248
175
|
|
|
@@ -250,40 +177,6 @@ describe "OracleEnhancedAdapter" do
|
|
|
250
177
|
|
|
251
178
|
end
|
|
252
179
|
|
|
253
|
-
describe "without composite_primary_keys" do
|
|
254
|
-
|
|
255
|
-
before(:all) do
|
|
256
|
-
@conn = ActiveRecord::Base.connection
|
|
257
|
-
@conn.execute "DROP TABLE test_employees" rescue nil
|
|
258
|
-
@conn.execute <<-SQL
|
|
259
|
-
CREATE TABLE test_employees (
|
|
260
|
-
employee_id NUMBER PRIMARY KEY,
|
|
261
|
-
name VARCHAR2(50)
|
|
262
|
-
)
|
|
263
|
-
SQL
|
|
264
|
-
Object.send(:remove_const, 'CompositePrimaryKeys') if defined?(CompositePrimaryKeys)
|
|
265
|
-
class ::TestEmployee < ActiveRecord::Base
|
|
266
|
-
self.primary_key = :employee_id
|
|
267
|
-
end
|
|
268
|
-
end
|
|
269
|
-
|
|
270
|
-
after(:all) do
|
|
271
|
-
Object.send(:remove_const, "TestEmployee")
|
|
272
|
-
@conn.execute "DROP TABLE test_employees"
|
|
273
|
-
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
|
274
|
-
end
|
|
275
|
-
|
|
276
|
-
it "should tell ActiveRecord that count distinct is supported" do
|
|
277
|
-
expect(ActiveRecord::Base.connection.supports_count_distinct?).to be_truthy
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
it "should execute correct SQL COUNT DISTINCT statement" do
|
|
281
|
-
expect { TestEmployee.distinct.count(:employee_id) }.not_to raise_error
|
|
282
|
-
end
|
|
283
|
-
|
|
284
|
-
end
|
|
285
|
-
|
|
286
|
-
|
|
287
180
|
describe "reserved words column quoting" do
|
|
288
181
|
|
|
289
182
|
before(:all) do
|
|
@@ -303,7 +196,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
303
196
|
end
|
|
304
197
|
Object.send(:remove_const, "TestReservedWord")
|
|
305
198
|
ActiveRecord::Base.table_name_prefix = nil
|
|
306
|
-
ActiveRecord::Base.clear_cache!
|
|
199
|
+
ActiveRecord::Base.clear_cache!
|
|
307
200
|
end
|
|
308
201
|
|
|
309
202
|
before(:each) do
|
|
@@ -322,9 +215,9 @@ describe "OracleEnhancedAdapter" do
|
|
|
322
215
|
|
|
323
216
|
it "should create record" do
|
|
324
217
|
attrs = {
|
|
325
|
-
:
|
|
326
|
-
:
|
|
327
|
-
:
|
|
218
|
+
varchar2: "dummy",
|
|
219
|
+
integer: 1,
|
|
220
|
+
comment: "dummy"
|
|
328
221
|
}
|
|
329
222
|
record = TestReservedWord.create!(attrs)
|
|
330
223
|
record.reload
|
|
@@ -377,19 +270,19 @@ describe "OracleEnhancedAdapter" do
|
|
|
377
270
|
expect(@adapter.valid_table_name?("aBc")).to be_falsey
|
|
378
271
|
expect(@adapter.valid_table_name?("abC")).to be_falsey
|
|
379
272
|
end
|
|
380
|
-
|
|
273
|
+
|
|
381
274
|
it "should not be valid for names > 30 characters" do
|
|
382
275
|
expect(@adapter.valid_table_name?("a" * 31)).to be_falsey
|
|
383
276
|
end
|
|
384
|
-
|
|
277
|
+
|
|
385
278
|
it "should not be valid for schema names > 30 characters" do
|
|
386
279
|
expect(@adapter.valid_table_name?(("a" * 31) + ".validname")).to be_falsey
|
|
387
280
|
end
|
|
388
|
-
|
|
281
|
+
|
|
389
282
|
it "should not be valid for database links > 128 characters" do
|
|
390
283
|
expect(@adapter.valid_table_name?("name@" + "a" * 129)).to be_falsey
|
|
391
284
|
end
|
|
392
|
-
|
|
285
|
+
|
|
393
286
|
it "should not be valid for names that do not begin with alphabetic characters" do
|
|
394
287
|
expect(@adapter.valid_table_name?("1abc")).to be_falsey
|
|
395
288
|
expect(@adapter.valid_table_name?("_abc")).to be_falsey
|
|
@@ -443,7 +336,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
443
336
|
self.table_name = "warehouse-things"
|
|
444
337
|
end
|
|
445
338
|
|
|
446
|
-
wh = WarehouseThing.create!(:
|
|
339
|
+
wh = WarehouseThing.create!(name: "Foo", foo: 2)
|
|
447
340
|
expect(wh.id).not_to be_nil
|
|
448
341
|
|
|
449
342
|
expect(@conn.tables).to include("warehouse-things")
|
|
@@ -455,14 +348,14 @@ describe "OracleEnhancedAdapter" do
|
|
|
455
348
|
self.table_name = "CamelCase"
|
|
456
349
|
end
|
|
457
350
|
|
|
458
|
-
cc = CamelCase.create!(:
|
|
351
|
+
cc = CamelCase.create!(name: "Foo", foo: 2)
|
|
459
352
|
expect(cc.id).not_to be_nil
|
|
460
|
-
|
|
353
|
+
|
|
461
354
|
expect(@conn.tables).to include("CamelCase")
|
|
462
355
|
end
|
|
463
356
|
|
|
464
357
|
it "properly quotes database links" do
|
|
465
|
-
expect(@conn.quote_table_name(
|
|
358
|
+
expect(@conn.quote_table_name("asdf@some.link")).to eq('"ASDF"@"SOME.LINK"')
|
|
466
359
|
end
|
|
467
360
|
end
|
|
468
361
|
|
|
@@ -496,11 +389,11 @@ describe "OracleEnhancedAdapter" do
|
|
|
496
389
|
@conn.execute "DROP DATABASE LINK #{@db_link}" rescue nil
|
|
497
390
|
@sys_conn.drop_table :test_posts rescue nil
|
|
498
391
|
Object.send(:remove_const, "TestPost") rescue nil
|
|
499
|
-
ActiveRecord::Base.clear_cache!
|
|
392
|
+
ActiveRecord::Base.clear_cache!
|
|
500
393
|
end
|
|
501
394
|
|
|
502
395
|
it "should verify database link" do
|
|
503
|
-
@conn.select_value("select * from dual@#{@db_link}") ==
|
|
396
|
+
@conn.select_value("select * from dual@#{@db_link}") == "X"
|
|
504
397
|
end
|
|
505
398
|
|
|
506
399
|
it "should get column names" do
|
|
@@ -508,7 +401,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
508
401
|
end
|
|
509
402
|
|
|
510
403
|
it "should create record" do
|
|
511
|
-
p = TestPost.create(:
|
|
404
|
+
p = TestPost.create(title: "Title", body: "Body")
|
|
512
405
|
expect(p.id).not_to be_nil
|
|
513
406
|
expect(TestPost.find(p.id)).not_to be_nil
|
|
514
407
|
end
|
|
@@ -522,7 +415,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
522
415
|
|
|
523
416
|
it "should get current database name" do
|
|
524
417
|
# get database name if using //host:port/database connection string
|
|
525
|
-
database_name = CONNECTION_PARAMS[:database].split(
|
|
418
|
+
database_name = CONNECTION_PARAMS[:database].split("/").last
|
|
526
419
|
expect(@conn.current_database.upcase).to eq(database_name.upcase)
|
|
527
420
|
end
|
|
528
421
|
|
|
@@ -533,25 +426,25 @@ describe "OracleEnhancedAdapter" do
|
|
|
533
426
|
|
|
534
427
|
describe "temporary tables" do
|
|
535
428
|
before(:all) do
|
|
536
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:table] =
|
|
537
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] =
|
|
429
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:table] = "UNUSED"
|
|
430
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces[:clob] = "UNUSED"
|
|
538
431
|
@conn = ActiveRecord::Base.connection
|
|
539
432
|
end
|
|
540
433
|
after(:all) do
|
|
541
|
-
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces={}
|
|
434
|
+
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.default_tablespaces = {}
|
|
542
435
|
end
|
|
543
436
|
|
|
544
437
|
after(:each) do
|
|
545
438
|
@conn.drop_table :foos rescue nil
|
|
546
439
|
end
|
|
547
440
|
it "should create ok" do
|
|
548
|
-
@conn.create_table :foos, :
|
|
441
|
+
@conn.create_table :foos, temporary: true, id: false do |t|
|
|
549
442
|
t.integer :id
|
|
550
443
|
t.text :bar
|
|
551
444
|
end
|
|
552
445
|
end
|
|
553
446
|
it "should show up as temporary" do
|
|
554
|
-
@conn.create_table :foos, :
|
|
447
|
+
@conn.create_table :foos, temporary: true, id: false do |t|
|
|
555
448
|
t.integer :id
|
|
556
449
|
end
|
|
557
450
|
expect(@conn.temporary_table?("foos")).to be_truthy
|
|
@@ -579,8 +472,8 @@ describe "OracleEnhancedAdapter" do
|
|
|
579
472
|
@ids = (1..1010).to_a
|
|
580
473
|
TestPost.transaction do
|
|
581
474
|
@ids.each do |id|
|
|
582
|
-
TestPost.create!(:
|
|
583
|
-
TestComment.create!(:
|
|
475
|
+
TestPost.create!(id: id, title: "Title #{id}")
|
|
476
|
+
TestComment.create!(test_post_id: id, description: "Description #{id}")
|
|
584
477
|
end
|
|
585
478
|
end
|
|
586
479
|
end
|
|
@@ -592,7 +485,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
592
485
|
end
|
|
593
486
|
Object.send(:remove_const, "TestPost")
|
|
594
487
|
Object.send(:remove_const, "TestComment")
|
|
595
|
-
ActiveRecord::Base.clear_cache!
|
|
488
|
+
ActiveRecord::Base.clear_cache!
|
|
596
489
|
end
|
|
597
490
|
|
|
598
491
|
it "should load included association with more than 1000 records" do
|
|
@@ -604,7 +497,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
604
497
|
|
|
605
498
|
describe "with statement pool" do
|
|
606
499
|
before(:all) do
|
|
607
|
-
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS.merge(:
|
|
500
|
+
ActiveRecord::Base.establish_connection(CONNECTION_PARAMS.merge(statement_limit: 3))
|
|
608
501
|
@conn = ActiveRecord::Base.connection
|
|
609
502
|
schema_define do
|
|
610
503
|
drop_table :test_posts rescue nil
|
|
@@ -624,7 +517,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
624
517
|
drop_table :test_posts
|
|
625
518
|
end
|
|
626
519
|
Object.send(:remove_const, "TestPost")
|
|
627
|
-
ActiveRecord::Base.clear_cache!
|
|
520
|
+
ActiveRecord::Base.clear_cache!
|
|
628
521
|
end
|
|
629
522
|
|
|
630
523
|
it "should clear older cursors when statement limit is reached" do
|
|
@@ -672,16 +565,17 @@ describe "OracleEnhancedAdapter" do
|
|
|
672
565
|
drop_table :test_posts
|
|
673
566
|
end
|
|
674
567
|
Object.send(:remove_const, "TestPost")
|
|
675
|
-
ActiveRecord::Base.clear_cache!
|
|
568
|
+
ActiveRecord::Base.clear_cache!
|
|
676
569
|
end
|
|
677
570
|
|
|
678
571
|
it "should explain query" do
|
|
679
|
-
explain = TestPost.where(:
|
|
572
|
+
explain = TestPost.where(id: 1).explain
|
|
680
573
|
expect(explain).to include("Cost")
|
|
681
574
|
expect(explain).to include("INDEX UNIQUE SCAN")
|
|
682
575
|
end
|
|
683
576
|
|
|
684
577
|
it "should explain query with binds" do
|
|
578
|
+
pending "Pending until further investigation made for #908" if RUBY_ENGINE == "jruby"
|
|
685
579
|
pk = TestPost.columns_hash[TestPost.primary_key]
|
|
686
580
|
sub = Arel::Nodes::BindParam.new.to_sql
|
|
687
581
|
binds = [ActiveRecord::Relation::QueryAttribute.new(pk, 1, ActiveRecord::Type::Integer.new)]
|
|
@@ -714,13 +608,11 @@ describe "OracleEnhancedAdapter" do
|
|
|
714
608
|
self.table_name = :test_employees
|
|
715
609
|
end
|
|
716
610
|
i = 0
|
|
717
|
-
@employee.create!(sort_order: i+=1, first_name:
|
|
718
|
-
@employee.create!(sort_order: i+=1, first_name:
|
|
719
|
-
@employee.create!(sort_order: i+=1, first_name:
|
|
720
|
-
@employee.create!(sort_order: i+=1, first_name:
|
|
721
|
-
@employee.create!(sort_order: i+=1, first_name:
|
|
722
|
-
@oracle11g_or_lower = !! @conn.select_value(
|
|
723
|
-
"select * from product_component_version where product like 'Oracle%' and to_number(substr(version,1,2)) <= 11")
|
|
611
|
+
@employee.create!(sort_order: i += 1, first_name: "Peter", last_name: "Parker")
|
|
612
|
+
@employee.create!(sort_order: i += 1, first_name: "Tony", last_name: "Stark")
|
|
613
|
+
@employee.create!(sort_order: i += 1, first_name: "Steven", last_name: "Rogers")
|
|
614
|
+
@employee.create!(sort_order: i += 1, first_name: "Bruce", last_name: "Banner")
|
|
615
|
+
@employee.create!(sort_order: i += 1, first_name: "Natasha", last_name: "Romanova")
|
|
724
616
|
end
|
|
725
617
|
|
|
726
618
|
after(:all) do
|
|
@@ -729,8 +621,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
729
621
|
end
|
|
730
622
|
|
|
731
623
|
after(:each) do
|
|
732
|
-
ActiveRecord::Base.
|
|
733
|
-
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
|
624
|
+
ActiveRecord::Base.clear_cache!
|
|
734
625
|
end
|
|
735
626
|
|
|
736
627
|
it "should return n records with limit(n)" do
|
|
@@ -742,7 +633,6 @@ describe "OracleEnhancedAdapter" do
|
|
|
742
633
|
end
|
|
743
634
|
|
|
744
635
|
it "should return the records starting from offset n with offset(n)" do
|
|
745
|
-
skip "Skipped until #848 or rails/arel#438 resolved " if @oracle11g_or_lower
|
|
746
636
|
expect(@employee.order(:sort_order).first.first_name).to eq("Peter")
|
|
747
637
|
expect(@employee.order(:sort_order).offset(0).first.first_name).to eq("Peter")
|
|
748
638
|
expect(@employee.order(:sort_order).offset(1).first.first_name).to eq("Tony")
|
|
@@ -765,7 +655,7 @@ describe "OracleEnhancedAdapter" do
|
|
|
765
655
|
end
|
|
766
656
|
|
|
767
657
|
it "returns true when passed a valid type" do
|
|
768
|
-
column = @conn.columns(
|
|
658
|
+
column = @conn.columns("test_employees").find { |col| col.name == "first_name" }
|
|
769
659
|
expect(@conn.valid_type?(column.type)).to be true
|
|
770
660
|
end
|
|
771
661
|
|
|
@@ -773,4 +663,77 @@ describe "OracleEnhancedAdapter" do
|
|
|
773
663
|
expect(@conn.valid_type?(:foobar)).to be false
|
|
774
664
|
end
|
|
775
665
|
end
|
|
666
|
+
|
|
667
|
+
describe "serialized column" do
|
|
668
|
+
before(:all) do
|
|
669
|
+
schema_define do
|
|
670
|
+
create_table :test_serialized_columns do |t|
|
|
671
|
+
t.text :serialized
|
|
672
|
+
end
|
|
673
|
+
end
|
|
674
|
+
class ::TestSerializedColumn < ActiveRecord::Base
|
|
675
|
+
serialize :serialized, Array
|
|
676
|
+
end
|
|
677
|
+
end
|
|
678
|
+
|
|
679
|
+
after(:all) do
|
|
680
|
+
schema_define do
|
|
681
|
+
drop_table :test_serialized_columns
|
|
682
|
+
end
|
|
683
|
+
Object.send(:remove_const, "TestSerializedColumn")
|
|
684
|
+
ActiveRecord::Base.table_name_prefix = nil
|
|
685
|
+
ActiveRecord::Base.clear_cache!
|
|
686
|
+
end
|
|
687
|
+
|
|
688
|
+
before(:each) do
|
|
689
|
+
set_logger
|
|
690
|
+
end
|
|
691
|
+
|
|
692
|
+
after(:each) do
|
|
693
|
+
clear_logger
|
|
694
|
+
end
|
|
695
|
+
|
|
696
|
+
it "should serialize" do
|
|
697
|
+
new_value = "new_value"
|
|
698
|
+
serialized_column = TestSerializedColumn.new
|
|
699
|
+
|
|
700
|
+
expect(serialized_column.serialized).to eq([])
|
|
701
|
+
serialized_column.serialized << new_value
|
|
702
|
+
expect(serialized_column.serialized).to eq([new_value])
|
|
703
|
+
serialized_column.save
|
|
704
|
+
expect(serialized_column.save!).to eq(true)
|
|
705
|
+
|
|
706
|
+
serialized_column.reload
|
|
707
|
+
expect(serialized_column.serialized).to eq([new_value])
|
|
708
|
+
serialized_column.serialized = []
|
|
709
|
+
expect(serialized_column.save!).to eq(true)
|
|
710
|
+
end
|
|
711
|
+
end
|
|
712
|
+
|
|
713
|
+
describe "quoting" do
|
|
714
|
+
before(:all) do
|
|
715
|
+
schema_define do
|
|
716
|
+
create_table :test_logs, force: true do |t|
|
|
717
|
+
t.timestamp :send_time
|
|
718
|
+
end
|
|
719
|
+
end
|
|
720
|
+
class TestLog < ActiveRecord::Base
|
|
721
|
+
validates_uniqueness_of :send_time
|
|
722
|
+
end
|
|
723
|
+
end
|
|
724
|
+
|
|
725
|
+
after(:all) do
|
|
726
|
+
schema_define do
|
|
727
|
+
drop_table :test_logs
|
|
728
|
+
end
|
|
729
|
+
Object.send(:remove_const, "TestLog")
|
|
730
|
+
ActiveRecord::Base.clear_cache! if ActiveRecord::Base.respond_to?(:"clear_cache!")
|
|
731
|
+
end
|
|
732
|
+
|
|
733
|
+
it "should create records including Time" do
|
|
734
|
+
TestLog.create! send_time: Time.now + 1.seconds
|
|
735
|
+
TestLog.create! send_time: Time.now + 2.seconds
|
|
736
|
+
expect(TestLog.count).to eq 2
|
|
737
|
+
end
|
|
738
|
+
end
|
|
776
739
|
end
|