activerecord-oracle_enhanced-adapter 1.7.11 → 1.8.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.
- checksums.yaml +4 -4
- data/History.md +206 -4
- data/README.md +37 -1
- 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 -59
- data/lib/active_record/connection_adapters/oracle_enhanced/column_dumper.rb +6 -50
- data/lib/active_record/connection_adapters/oracle_enhanced/connection.rb +11 -11
- data/lib/active_record/connection_adapters/oracle_enhanced/context_index.rb +117 -117
- data/lib/active_record/connection_adapters/oracle_enhanced/database_statements.rb +37 -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 +56 -71
- data/lib/active_record/connection_adapters/oracle_enhanced/jdbc_quoting.rb +0 -7
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_connection.rb +51 -69
- data/lib/active_record/connection_adapters/oracle_enhanced/oci_quoting.rb +4 -4
- data/lib/active_record/connection_adapters/oracle_enhanced/procedures.rb +76 -76
- data/lib/active_record/connection_adapters/oracle_enhanced/quoting.rb +14 -43
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_creation.rb +60 -64
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_definitions.rb +33 -47
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_dumper.rb +150 -160
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements.rb +95 -133
- data/lib/active_record/connection_adapters/oracle_enhanced/schema_statements_ext.rb +3 -3
- data/lib/active_record/connection_adapters/oracle_enhanced/structure_dump.rb +66 -101
- data/lib/active_record/connection_adapters/oracle_enhanced/version.rb +1 -1
- data/lib/active_record/connection_adapters/oracle_enhanced_adapter.rb +290 -533
- data/lib/active_record/oracle_enhanced/type/boolean.rb +7 -10
- data/lib/active_record/oracle_enhanced/type/integer.rb +3 -4
- data/lib/active_record/oracle_enhanced/type/json.rb +8 -0
- data/lib/active_record/oracle_enhanced/type/national_character_string.rb +1 -1
- data/lib/active_record/oracle_enhanced/type/raw.rb +2 -3
- data/lib/active_record/oracle_enhanced/type/string.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/text.rb +2 -2
- data/lib/active_record/oracle_enhanced/type/timestamptz.rb +23 -0
- data/lib/activerecord-oracle_enhanced-adapter.rb +2 -2
- data/spec/active_record/connection_adapters/oracle_enhanced_adapter_spec.rb +55 -162
- data/spec/active_record/connection_adapters/oracle_enhanced_connection_spec.rb +32 -34
- 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 +250 -357
- data/spec/active_record/connection_adapters/oracle_enhanced_database_tasks_spec.rb +14 -6
- data/spec/active_record/connection_adapters/oracle_enhanced_dbms_output_spec.rb +3 -5
- data/spec/active_record/connection_adapters/oracle_enhanced_dirty_spec.rb +115 -124
- 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 +68 -72
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_dump_spec.rb +64 -80
- data/spec/active_record/connection_adapters/oracle_enhanced_schema_statements_spec.rb +223 -329
- data/spec/active_record/connection_adapters/oracle_enhanced_structure_dump_spec.rb +18 -20
- data/spec/spec_config.yaml.template +11 -0
- data/spec/spec_helper.rb +59 -59
- 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 -83
- data/Rakefile +0 -45
- data/activerecord-oracle_enhanced-adapter.gemspec +0 -94
- data/lib/active_record/connection_adapters/oracle_enhanced/cpk.rb +0 -19
- 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 "OracleEnhancedConnection" do
|
4
2
|
|
5
3
|
describe "create connection" do
|
@@ -61,26 +59,26 @@ describe "OracleEnhancedConnection" do
|
|
61
59
|
|
62
60
|
describe "create connection with NLS parameters" do
|
63
61
|
after do
|
64
|
-
ENV[
|
62
|
+
ENV["NLS_DATE_FORMAT"] = nil
|
65
63
|
end
|
66
64
|
|
67
65
|
it "should use NLS_DATE_FORMAT environment variable" do
|
68
|
-
ENV[
|
66
|
+
ENV["NLS_DATE_FORMAT"] = "YYYY-MM-DD"
|
69
67
|
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
70
|
-
expect(@conn.select("
|
68
|
+
expect(@conn.select("select SYS_CONTEXT('userenv', 'NLS_DATE_FORMAT') as value from dual")).to eq([{ "value" => "YYYY-MM-DD" }])
|
71
69
|
end
|
72
70
|
|
73
71
|
it "should use configuration value and ignore NLS_DATE_FORMAT environment variable" do
|
74
|
-
ENV[
|
75
|
-
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS.merge(:
|
76
|
-
expect(@conn.select("
|
72
|
+
ENV["NLS_DATE_FORMAT"] = "YYYY-MM-DD"
|
73
|
+
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS.merge(nls_date_format: "YYYY-MM-DD HH24:MI"))
|
74
|
+
expect(@conn.select("select SYS_CONTEXT('userenv', 'NLS_DATE_FORMAT') as value from dual")).to eq([{ "value" => "YYYY-MM-DD HH24:MI" }])
|
77
75
|
end
|
78
76
|
|
79
77
|
it "should use default value when NLS_DATE_FORMAT environment variable is not set" do
|
80
|
-
ENV[
|
78
|
+
ENV["NLS_DATE_FORMAT"] = nil
|
81
79
|
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
82
80
|
default = ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter::DEFAULT_NLS_PARAMETERS[:nls_date_format]
|
83
|
-
expect(@conn.select("
|
81
|
+
expect(@conn.select("select SYS_CONTEXT('userenv', 'NLS_DATE_FORMAT') as value from dual")).to eq([{ "value" => default }])
|
84
82
|
end
|
85
83
|
end
|
86
84
|
|
@@ -116,7 +114,7 @@ describe "OracleEnhancedConnection" do
|
|
116
114
|
before(:all) do
|
117
115
|
ActiveRecord::Base.establish_connection(CONNECTION_WITH_TIMEZONE_PARAMS)
|
118
116
|
schema_define do
|
119
|
-
create_table :posts, :
|
117
|
+
create_table :posts, force: true do |t|
|
120
118
|
t.timestamps null: false
|
121
119
|
end
|
122
120
|
end
|
@@ -143,9 +141,9 @@ describe "OracleEnhancedConnection" do
|
|
143
141
|
let(:username) { CONNECTION_PARAMS[:username] }
|
144
142
|
let(:password) { CONNECTION_PARAMS[:password] }
|
145
143
|
let(:connection_string) { "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=tcp)(HOST=#{DATABASE_HOST})(PORT=#{DATABASE_PORT})))(CONNECT_DATA=(SERVICE_NAME=#{DATABASE_NAME})))" }
|
146
|
-
let(:params) { { username: username, password: password, host:
|
144
|
+
let(:params) { { username: username, password: password, host: "connection-string", database: connection_string } }
|
147
145
|
|
148
|
-
it
|
146
|
+
it "uses the database param as the connection string" do
|
149
147
|
if ORACLE_ENHANCED_CONNECTION == :jdbc
|
150
148
|
expect(java.sql.DriverManager).to receive(:getConnection).with("jdbc:oracle:thin:@#{connection_string}", anything).and_call_original
|
151
149
|
else
|
@@ -156,7 +154,7 @@ describe "OracleEnhancedConnection" do
|
|
156
154
|
end
|
157
155
|
end
|
158
156
|
|
159
|
-
if defined?(RUBY_ENGINE) && RUBY_ENGINE ==
|
157
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
160
158
|
|
161
159
|
describe "create JDBC connection" do
|
162
160
|
|
@@ -189,11 +187,11 @@ describe "OracleEnhancedConnection" do
|
|
189
187
|
it "should create a new connection using JNDI" do
|
190
188
|
|
191
189
|
begin
|
192
|
-
import
|
193
|
-
import
|
194
|
-
import
|
195
|
-
import
|
196
|
-
import
|
190
|
+
import "oracle.jdbc.driver.OracleDriver"
|
191
|
+
import "org.apache.commons.pool.impl.GenericObjectPool"
|
192
|
+
import "org.apache.commons.dbcp.PoolingDataSource"
|
193
|
+
import "org.apache.commons.dbcp.PoolableConnectionFactory"
|
194
|
+
import "org.apache.commons.dbcp.DriverManagerConnectionFactory"
|
197
195
|
rescue NameError => e
|
198
196
|
return skip e.message
|
199
197
|
end
|
@@ -203,12 +201,12 @@ describe "OracleEnhancedConnection" do
|
|
203
201
|
connection_pool = GenericObjectPool.new(nil)
|
204
202
|
uri = "jdbc:oracle:thin:@#{DATABASE_HOST && "#{DATABASE_HOST}:"}#{DATABASE_PORT && "#{DATABASE_PORT}:"}#{DATABASE_NAME}"
|
205
203
|
connection_factory = DriverManagerConnectionFactory.new(uri, DATABASE_USER, DATABASE_PASSWORD)
|
206
|
-
poolable_connection_factory = PoolableConnectionFactory.new(connection_factory,connection_pool,nil,nil,false,true)
|
204
|
+
poolable_connection_factory = PoolableConnectionFactory.new(connection_factory, connection_pool, nil, nil, false, true)
|
207
205
|
@data_source = PoolingDataSource.new(connection_pool)
|
208
206
|
@data_source.access_to_underlying_connection_allowed = true
|
209
207
|
end
|
210
208
|
def lookup(path)
|
211
|
-
if (path ==
|
209
|
+
if (path == "java:/comp/env")
|
212
210
|
return self
|
213
211
|
else
|
214
212
|
return @data_source
|
@@ -219,7 +217,7 @@ describe "OracleEnhancedConnection" do
|
|
219
217
|
allow(javax.naming.InitialContext).to receive(:new).and_return(InitialContextMock.new)
|
220
218
|
|
221
219
|
params = {}
|
222
|
-
params[:jndi] =
|
220
|
+
params[:jndi] = "java:comp/env/jdbc/test"
|
223
221
|
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
224
222
|
expect(@conn).to be_active
|
225
223
|
end
|
@@ -231,7 +229,7 @@ describe "OracleEnhancedConnection" do
|
|
231
229
|
params[:url] = "jdbc:oracle:thin:@#{DATABASE_HOST && "//#{DATABASE_HOST}#{DATABASE_PORT && ":#{DATABASE_PORT}"}/"}#{DATABASE_NAME}"
|
232
230
|
params[:host] = nil
|
233
231
|
params[:database] = nil
|
234
|
-
allow(java.sql.DriverManager).to receive(:getConnection).and_raise(
|
232
|
+
allow(java.sql.DriverManager).to receive(:getConnection).and_raise("no suitable driver found")
|
235
233
|
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(params)
|
236
234
|
expect(@conn).to be_active
|
237
235
|
end
|
@@ -248,11 +246,11 @@ describe "OracleEnhancedConnection" do
|
|
248
246
|
end
|
249
247
|
|
250
248
|
it "should execute SQL select" do
|
251
|
-
expect(@conn.select("SELECT * FROM dual")).to eq([{
|
249
|
+
expect(@conn.select("SELECT * FROM dual")).to eq([{ "dummy" => "X" }])
|
252
250
|
end
|
253
251
|
|
254
252
|
it "should execute SQL select and return also columns" do
|
255
|
-
expect(@conn.select("SELECT * FROM dual", nil, true)).to eq([ [{
|
253
|
+
expect(@conn.select("SELECT * FROM dual", nil, true)).to eq([ [{ "dummy" => "X" }], ["dummy"] ])
|
256
254
|
end
|
257
255
|
|
258
256
|
end
|
@@ -266,7 +264,7 @@ describe "OracleEnhancedConnection" do
|
|
266
264
|
cursor = @conn.prepare("SELECT * FROM dual WHERE :1 = 1")
|
267
265
|
cursor.bind_param(1, 1)
|
268
266
|
cursor.exec
|
269
|
-
expect(cursor.get_col_names).to eq([
|
267
|
+
expect(cursor.get_col_names).to eq(["DUMMY"])
|
270
268
|
expect(cursor.fetch).to eq(["X"])
|
271
269
|
cursor.close
|
272
270
|
end
|
@@ -285,20 +283,20 @@ describe "OracleEnhancedConnection" do
|
|
285
283
|
|
286
284
|
describe "SQL with bind parameters when NLS_NUMERIC_CHARACTERS is set to ', '" do
|
287
285
|
before(:all) do
|
288
|
-
ENV[
|
286
|
+
ENV["NLS_NUMERIC_CHARACTERS"] = ", "
|
289
287
|
@conn = ActiveRecord::ConnectionAdapters::OracleEnhancedConnection.create(CONNECTION_PARAMS)
|
290
288
|
@conn.exec "CREATE TABLE test_employees (age NUMBER(10,2))"
|
291
289
|
end
|
292
290
|
|
293
291
|
after(:all) do
|
294
|
-
ENV[
|
292
|
+
ENV["NLS_NUMERIC_CHARACTERS"] = nil
|
295
293
|
@conn.exec "DROP TABLE test_employees" rescue nil
|
296
294
|
end
|
297
295
|
|
298
296
|
it "should execute prepared statement with decimal bind parameter " do
|
299
297
|
cursor = @conn.prepare("INSERT INTO test_employees VALUES(:1)")
|
300
298
|
type_metadata = ActiveRecord::ConnectionAdapters::SqlTypeMetadata.new(sql_type: "NUMBER", type: :decimal, limit: 10, precision: nil, scale: 2)
|
301
|
-
column = ActiveRecord::ConnectionAdapters::OracleEnhancedColumn.new(
|
299
|
+
column = ActiveRecord::ConnectionAdapters::OracleEnhancedColumn.new("age", nil, type_metadata, false, "test_employees", false, false, nil)
|
302
300
|
expect(column.type).to eq(:decimal)
|
303
301
|
# Here 1.5 expects that this value has been type casted already
|
304
302
|
# it should use bind_params in the long term.
|
@@ -324,10 +322,10 @@ describe "OracleEnhancedConnection" do
|
|
324
322
|
end
|
325
323
|
|
326
324
|
def kill_current_session
|
327
|
-
audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first[
|
325
|
+
audsid = @conn.select("SELECT userenv('sessionid') audsid FROM dual").first["audsid"]
|
328
326
|
sid_serial = @sys_conn.select("SELECT s.sid||','||s.serial# sid_serial
|
329
327
|
FROM v$session s
|
330
|
-
WHERE audsid = '#{audsid}'").first[
|
328
|
+
WHERE audsid = '#{audsid}'").first["sid_serial"]
|
331
329
|
@sys_conn.exec "ALTER SYSTEM KILL SESSION '#{sid_serial}' IMMEDIATE"
|
332
330
|
end
|
333
331
|
|
@@ -342,7 +340,7 @@ describe "OracleEnhancedConnection" do
|
|
342
340
|
# @conn.auto_retry = false
|
343
341
|
ActiveRecord::Base.connection.auto_retry = false
|
344
342
|
kill_current_session
|
345
|
-
if defined?(RUBY_ENGINE) && RUBY_ENGINE ==
|
343
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
346
344
|
expect { @conn.exec("SELECT * FROM dual") }.to raise_error(NativeException)
|
347
345
|
else
|
348
346
|
expect { @conn.exec("SELECT * FROM dual") }.to raise_error(OCIError)
|
@@ -353,14 +351,14 @@ describe "OracleEnhancedConnection" do
|
|
353
351
|
# @conn.auto_retry = true
|
354
352
|
ActiveRecord::Base.connection.auto_retry = true
|
355
353
|
kill_current_session
|
356
|
-
expect(@conn.select("SELECT * FROM dual")).to eq([{
|
354
|
+
expect(@conn.select("SELECT * FROM dual")).to eq([{ "dummy" => "X" }])
|
357
355
|
end
|
358
356
|
|
359
357
|
it "should not reconnect and execute SQL select if connection is lost and auto retry is disabled" do
|
360
358
|
# @conn.auto_retry = false
|
361
359
|
ActiveRecord::Base.connection.auto_retry = false
|
362
360
|
kill_current_session
|
363
|
-
if defined?(RUBY_ENGINE) && RUBY_ENGINE ==
|
361
|
+
if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
364
362
|
expect { @conn.select("SELECT * FROM dual") }.to raise_error(NativeException)
|
365
363
|
else
|
366
364
|
expect { @conn.select("SELECT * FROM dual") }.to raise_error(OCIError)
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
1
|
describe "OracleEnhancedAdapter context index" do
|
4
2
|
include SchemaSpecHelper
|
5
3
|
include LoggerSpecHelper
|
@@ -68,8 +66,8 @@ describe "OracleEnhancedAdapter context index" do
|
|
68
66
|
has_context_index
|
69
67
|
end
|
70
68
|
@post0 = Post.create(title: "dummy title", body: "dummy body")
|
71
|
-
@post1 = Post.create(title: @title_words.join(
|
72
|
-
@post2 = Post.create(title: (@title_words*2).join(
|
69
|
+
@post1 = Post.create(title: @title_words.join(" "), body: @body_words.join(" "))
|
70
|
+
@post2 = Post.create(title: (@title_words * 2).join(" "), body: (@body_words * 2).join(" "))
|
73
71
|
@post_with_null_body = Post.create(title: "withnull", body: nil)
|
74
72
|
@post_with_null_title = Post.create(title: nil, body: "withnull")
|
75
73
|
end
|
@@ -77,7 +75,11 @@ describe "OracleEnhancedAdapter context index" do
|
|
77
75
|
after(:all) do
|
78
76
|
drop_table_posts
|
79
77
|
Object.send(:remove_const, "Post")
|
80
|
-
ActiveRecord::Base.clear_cache!
|
78
|
+
ActiveRecord::Base.clear_cache!
|
79
|
+
end
|
80
|
+
|
81
|
+
before(:each) do
|
82
|
+
@post = nil
|
81
83
|
end
|
82
84
|
|
83
85
|
after(:each) do
|
@@ -102,13 +104,13 @@ describe "OracleEnhancedAdapter context index" do
|
|
102
104
|
|
103
105
|
it "should not include text index secondary tables in user tables list" do
|
104
106
|
@conn.add_context_index :posts, :title
|
105
|
-
expect(@conn.tables.any?{|t| t =~ /^dr\$/i}).to be_falsey
|
107
|
+
expect(@conn.tables.any? { |t| t =~ /^dr\$/i }).to be_falsey
|
106
108
|
@conn.remove_context_index :posts, :title
|
107
109
|
end
|
108
110
|
|
109
111
|
it "should create multiple column index" do
|
110
112
|
@conn.add_context_index :posts, [:title, :body]
|
111
|
-
(@title_words
|
113
|
+
(@title_words + @body_words).each do |word|
|
112
114
|
expect(Post.contains(:title, word).to_a).to eq([@post2, @post1])
|
113
115
|
end
|
114
116
|
@conn.remove_context_index :posts, [:title, :body]
|
@@ -122,7 +124,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
122
124
|
|
123
125
|
it "should create multiple column index with specified main index column" do
|
124
126
|
@conn.add_context_index :posts, [:title, :body],
|
125
|
-
index_column: :all_text, sync:
|
127
|
+
index_column: :all_text, sync: "ON COMMIT"
|
126
128
|
@post = Post.create(title: "abc", body: "def")
|
127
129
|
expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
|
128
130
|
expect(Post.contains(:all_text, "def").to_a).to eq([@post])
|
@@ -138,7 +140,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
138
140
|
it "should create multiple column index with trigger updated main index column" do
|
139
141
|
@conn.add_context_index :posts, [:title, :body],
|
140
142
|
index_column: :all_text, index_column_trigger_on: [:created_at, :updated_at],
|
141
|
-
sync:
|
143
|
+
sync: "ON COMMIT"
|
142
144
|
@post = Post.create(title: "abc", body: "def")
|
143
145
|
expect(Post.contains(:all_text, "abc").to_a).to eq([@post])
|
144
146
|
expect(Post.contains(:all_text, "def").to_a).to eq([@post])
|
@@ -151,7 +153,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
151
153
|
it "should use base letter conversion with BASIC_LEXER" do
|
152
154
|
@post = Post.create!(title: "āčē", body: "dummy")
|
153
155
|
@conn.add_context_index :posts, :title,
|
154
|
-
lexer: { type: "BASIC_LEXER", base_letter_type:
|
156
|
+
lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true }
|
155
157
|
expect(Post.contains(:title, "āčē").to_a).to eq([@post])
|
156
158
|
expect(Post.contains(:title, "ace").to_a).to eq([@post])
|
157
159
|
expect(Post.contains(:title, "ACE").to_a).to eq([@post])
|
@@ -172,7 +174,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
172
174
|
it "should use index when contains has schema_name.table_name syntax" do
|
173
175
|
@conn.add_context_index :posts, :title
|
174
176
|
@title_words.each do |word|
|
175
|
-
Post.contains(
|
177
|
+
expect(Post.contains("posts.title", word).to_a).to eq([@post2, @post1])
|
176
178
|
end
|
177
179
|
@conn.remove_context_index :posts, :title
|
178
180
|
end
|
@@ -195,11 +197,11 @@ describe "OracleEnhancedAdapter context index" do
|
|
195
197
|
drop_tables
|
196
198
|
Object.send(:remove_const, "Comment")
|
197
199
|
Object.send(:remove_const, "Post")
|
198
|
-
ActiveRecord::Base.clear_cache!
|
200
|
+
ActiveRecord::Base.clear_cache!
|
199
201
|
end
|
200
202
|
|
201
203
|
after(:each) do
|
202
|
-
@conn.remove_context_index :posts, name:
|
204
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index" rescue nil
|
203
205
|
@conn.remove_context_index :posts, index_column: :all_text rescue nil
|
204
206
|
Post.destroy_all
|
205
207
|
end
|
@@ -210,9 +212,9 @@ describe "OracleEnhancedAdapter context index" do
|
|
210
212
|
# specify aliases always with AS keyword
|
211
213
|
"SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
212
214
|
],
|
213
|
-
name:
|
215
|
+
name: "post_and_comments_index",
|
214
216
|
index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
|
215
|
-
sync:
|
217
|
+
sync: "ON COMMIT"
|
216
218
|
@post = Post.create!(title: "aaa", body: "bbb")
|
217
219
|
@post.comments.create!(author: "ccc", body: "ddd")
|
218
220
|
@post.comments.create!(author: "eee", body: "fff")
|
@@ -231,9 +233,9 @@ describe "OracleEnhancedAdapter context index" do
|
|
231
233
|
FROM comments
|
232
234
|
WHERE comments.post_id = :id }
|
233
235
|
],
|
234
|
-
name:
|
236
|
+
name: "post_and_comments_index",
|
235
237
|
index_column: :all_text, index_column_trigger_on: [:updated_at, :comments_count],
|
236
|
-
sync:
|
238
|
+
sync: "ON COMMIT"
|
237
239
|
@post = Post.create!(title: "aaa", body: "bbb")
|
238
240
|
@post.comments.create!(author: "ccc", body: "ddd")
|
239
241
|
@post.comments.create!(author: "eee", body: "fff")
|
@@ -270,7 +272,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
270
272
|
class ::Post < ActiveRecord::Base
|
271
273
|
has_context_index
|
272
274
|
end
|
273
|
-
@post = Post.create(title:
|
275
|
+
@post = Post.create(title: "aaa", body: "bbb")
|
274
276
|
@tablespace = @conn.default_tablespace
|
275
277
|
set_logger
|
276
278
|
@conn = ActiveRecord::Base.connection
|
@@ -279,7 +281,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
279
281
|
after(:all) do
|
280
282
|
drop_table_posts
|
281
283
|
Object.send(:remove_const, "Post")
|
282
|
-
ActiveRecord::Base.clear_cache!
|
284
|
+
ActiveRecord::Base.clear_cache!
|
283
285
|
end
|
284
286
|
|
285
287
|
after(:each) do
|
@@ -287,7 +289,7 @@ describe "OracleEnhancedAdapter context index" do
|
|
287
289
|
end
|
288
290
|
|
289
291
|
def verify_logged_statements
|
290
|
-
[
|
292
|
+
["K_TABLE_CLAUSE", "R_TABLE_CLAUSE", "N_TABLE_CLAUSE", "I_INDEX_CLAUSE", "P_TABLE_CLAUSE"].each do |clause|
|
291
293
|
expect(@logger.output(:debug)).to match(/CTX_DDL\.SET_ATTRIBUTE\('index_posts_on_title_sto', '#{clause}', '.*TABLESPACE #{@tablespace}'\)/)
|
292
294
|
end
|
293
295
|
expect(@logger.output(:debug)).to match(/CREATE INDEX .* PARAMETERS \('STORAGE index_posts_on_title_sto'\)/)
|
@@ -296,15 +298,15 @@ describe "OracleEnhancedAdapter context index" do
|
|
296
298
|
it "should create index on single column" do
|
297
299
|
@conn.add_context_index :posts, :title, tablespace: @tablespace
|
298
300
|
verify_logged_statements
|
299
|
-
expect(Post.contains(:title,
|
301
|
+
expect(Post.contains(:title, "aaa").to_a).to eq([@post])
|
300
302
|
@conn.remove_context_index :posts, :title
|
301
303
|
end
|
302
304
|
|
303
305
|
it "should create index on multiple columns" do
|
304
|
-
@conn.add_context_index :posts, [:title, :body], name:
|
306
|
+
@conn.add_context_index :posts, [:title, :body], name: "index_posts_text", tablespace: @conn.default_tablespace
|
305
307
|
verify_logged_statements
|
306
|
-
expect(Post.contains(:title,
|
307
|
-
@conn.remove_context_index :posts, name:
|
308
|
+
expect(Post.contains(:title, "aaa AND bbb").to_a).to eq([@post])
|
309
|
+
@conn.remove_context_index :posts, name: "index_posts_text"
|
308
310
|
end
|
309
311
|
|
310
312
|
end
|
@@ -343,56 +345,56 @@ describe "OracleEnhancedAdapter context index" do
|
|
343
345
|
|
344
346
|
it "should dump definition of multiple table index with options" do
|
345
347
|
options = {
|
346
|
-
name:
|
348
|
+
name: "post_and_comments_index",
|
347
349
|
index_column: :all_text, index_column_trigger_on: :updated_at,
|
348
350
|
transactional: true,
|
349
|
-
sync:
|
351
|
+
sync: "ON COMMIT"
|
350
352
|
}
|
351
353
|
sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"
|
352
354
|
@conn.add_context_index :posts, [:title, :body, sub_query], options
|
353
355
|
expect(standard_dump).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
|
354
|
-
@conn.remove_context_index :posts, name:
|
356
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index"
|
355
357
|
end
|
356
358
|
|
357
359
|
it "should dump definition of multiple table index with options (when definition is larger than 4000 bytes)" do
|
358
360
|
options = {
|
359
|
-
name:
|
361
|
+
name: "post_and_comments_index",
|
360
362
|
index_column: :all_text, index_column_trigger_on: :updated_at,
|
361
363
|
transactional: true,
|
362
|
-
sync:
|
364
|
+
sync: "ON COMMIT"
|
363
365
|
}
|
364
366
|
sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id#{' AND 1=1' * 500}"
|
365
367
|
@conn.add_context_index :posts, [:title, :body, sub_query], options
|
366
368
|
expect(standard_dump).to match(/add_context_index "posts", \[:title, :body, "#{sub_query}"\], #{options.inspect[1..-2]}$/)
|
367
|
-
@conn.remove_context_index :posts, name:
|
369
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index"
|
368
370
|
end
|
369
371
|
|
370
372
|
it "should dump definition of multiple table index with options (when subquery has newlines)" do
|
371
373
|
options = {
|
372
|
-
name:
|
374
|
+
name: "post_and_comments_index",
|
373
375
|
index_column: :all_text, index_column_trigger_on: :updated_at,
|
374
376
|
transactional: true,
|
375
|
-
sync:
|
377
|
+
sync: "ON COMMIT"
|
376
378
|
}
|
377
379
|
sub_query = "SELECT comments.author AS comment_author, comments.body AS comment_body\nFROM comments\nWHERE comments.post_id = :id"
|
378
380
|
@conn.add_context_index :posts, [:title, :body, sub_query], options
|
379
381
|
expect(standard_dump).to match(/add_context_index "posts", \[:title, :body, "#{sub_query.gsub(/\n/, ' ')}"\], #{options.inspect[1..-2]}$/)
|
380
|
-
@conn.remove_context_index :posts, name:
|
382
|
+
@conn.remove_context_index :posts, name: "post_and_comments_index"
|
381
383
|
end
|
382
384
|
|
383
385
|
end
|
384
386
|
|
385
387
|
describe "with table prefix and suffix" do
|
386
388
|
before(:all) do
|
387
|
-
ActiveRecord::Base.table_name_prefix =
|
388
|
-
ActiveRecord::Base.table_name_suffix =
|
389
|
+
ActiveRecord::Base.table_name_prefix = "xxx_"
|
390
|
+
ActiveRecord::Base.table_name_suffix = "_xxx"
|
389
391
|
create_tables
|
390
392
|
end
|
391
393
|
|
392
394
|
after(:all) do
|
393
395
|
drop_tables
|
394
|
-
ActiveRecord::Base.table_name_prefix =
|
395
|
-
ActiveRecord::Base.table_name_suffix =
|
396
|
+
ActiveRecord::Base.table_name_prefix = ""
|
397
|
+
ActiveRecord::Base.table_name_suffix = ""
|
396
398
|
end
|
397
399
|
|
398
400
|
it "should dump definition of single column index" do
|
@@ -409,11 +411,11 @@ describe "OracleEnhancedAdapter context index" do
|
|
409
411
|
|
410
412
|
it "should dump definition of multiple table index with options" do
|
411
413
|
options = {
|
412
|
-
name:
|
414
|
+
name: "xxx_post_and_comments_i",
|
413
415
|
index_column: :all_text, index_column_trigger_on: :updated_at,
|
414
|
-
lexer: { type: "BASIC_LEXER", base_letter_type:
|
416
|
+
lexer: { type: "BASIC_LEXER", base_letter_type: "GENERIC", base_letter: true },
|
415
417
|
wordlist: { type: "BASIC_WORDLIST", prefix_index: true },
|
416
|
-
sync:
|
418
|
+
sync: "ON COMMIT"
|
417
419
|
}
|
418
420
|
schema_define do
|
419
421
|
add_context_index :posts,
|
@@ -422,8 +424,8 @@ describe "OracleEnhancedAdapter context index" do
|
|
422
424
|
], options
|
423
425
|
end
|
424
426
|
expect(standard_dump).to match(/add_context_index "posts", \[:title, :body, "SELECT comments.author AS comment_author, comments.body AS comment_body FROM comments WHERE comments.post_id = :id"\], #{
|
425
|
-
options.inspect[1..-2].gsub(/[{}]/){|s| '\\'<<s }}$/)
|
426
|
-
schema_define { remove_context_index :posts, name:
|
427
|
+
options.inspect[1..-2].gsub(/[{}]/) { |s| '\\' << s }}$/)
|
428
|
+
schema_define { remove_context_index :posts, name: "xxx_post_and_comments_i" }
|
427
429
|
end
|
428
430
|
|
429
431
|
end
|