ruby-plsql 0.8.0 → 0.9.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.txt +2 -0
- data/VERSION +1 -1
- data/lib/plsql/connection.rb +14 -14
- data/lib/plsql/helpers.rb +3 -3
- data/lib/plsql/jdbc_connection.rb +3 -3
- data/lib/plsql/oci_connection.rb +8 -4
- data/lib/plsql/package.rb +3 -3
- data/lib/plsql/procedure.rb +32 -17
- data/lib/plsql/procedure_call.rb +15 -15
- data/lib/plsql/schema.rb +13 -9
- data/lib/plsql/sequence.rb +2 -2
- data/lib/plsql/table.rb +6 -6
- data/lib/plsql/type.rb +7 -7
- data/lib/plsql/variable.rb +4 -4
- data/lib/plsql/version.rb +1 -1
- data/lib/plsql/view.rb +2 -2
- metadata +13 -138
- data/.github/stale.yml +0 -37
- data/.github/workflows/rubocop.yml +0 -37
- data/.github/workflows/test.yml +0 -69
- data/.rubocop.yml +0 -147
- data/.travis/oracle/download.sh +0 -15
- data/.travis/oracle/install.sh +0 -32
- data/.travis/setup_accounts.sh +0 -9
- data/.travis.yml +0 -88
- data/Gemfile +0 -24
- data/Rakefile +0 -53
- data/Vagrantfile +0 -38
- data/ci/network/admin/tnsnames.ora +0 -7
- data/ci/setup_accounts.sh +0 -9
- data/gemfiles/Gemfile.activerecord-5.0 +0 -21
- data/gemfiles/Gemfile.activerecord-5.1 +0 -21
- data/gemfiles/Gemfile.activerecord-5.2 +0 -21
- data/gemfiles/Gemfile.activerecord-6.0 +0 -21
- data/gemfiles/Gemfile.activerecord-6.1 +0 -21
- data/gemfiles/Gemfile.activerecord-main +0 -21
- data/ruby-plsql.gemspec +0 -114
- data/spec/plsql/connection_spec.rb +0 -505
- data/spec/plsql/package_spec.rb +0 -172
- data/spec/plsql/procedure_spec.rb +0 -2390
- data/spec/plsql/schema_spec.rb +0 -364
- data/spec/plsql/sequence_spec.rb +0 -67
- data/spec/plsql/sql_statements_spec.rb +0 -91
- data/spec/plsql/table_spec.rb +0 -376
- data/spec/plsql/type_spec.rb +0 -299
- data/spec/plsql/variable_spec.rb +0 -497
- data/spec/plsql/version_spec.rb +0 -8
- data/spec/plsql/view_spec.rb +0 -264
- data/spec/spec.opts +0 -6
- data/spec/spec_helper.rb +0 -121
- data/spec/support/create_arunit_user.sql +0 -2
- data/spec/support/custom_config.rb.sample +0 -14
- data/spec/support/file_check_script.sh +0 -9
- data/spec/support/test_db.rb +0 -149
- data/spec/support/unlock_and_setup_hr_user.sql +0 -2
data/spec/plsql/view_spec.rb
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
require "spec_helper"
|
|
2
|
-
|
|
3
|
-
describe "View" do
|
|
4
|
-
before(:all) do
|
|
5
|
-
plsql.connect! CONNECTION_PARAMS
|
|
6
|
-
plsql.connection.autocommit = false
|
|
7
|
-
plsql.execute <<-SQL
|
|
8
|
-
CREATE TABLE test_employees (
|
|
9
|
-
employee_id NUMBER(15) NOT NULL,
|
|
10
|
-
first_name VARCHAR2(50),
|
|
11
|
-
last_name VARCHAR2(50),
|
|
12
|
-
hire_date DATE,
|
|
13
|
-
status VARCHAR2(1) DEFAULT 'N'
|
|
14
|
-
)
|
|
15
|
-
SQL
|
|
16
|
-
plsql.execute "CREATE OR REPLACE VIEW test_employees_v AS SELECT * FROM test_employees"
|
|
17
|
-
|
|
18
|
-
@employees = (1..10).map do |i|
|
|
19
|
-
{
|
|
20
|
-
employee_id: i,
|
|
21
|
-
first_name: "First #{i}",
|
|
22
|
-
last_name: "Last #{i}",
|
|
23
|
-
hire_date: Time.local(2000, 01, i),
|
|
24
|
-
status: "A"
|
|
25
|
-
}
|
|
26
|
-
end
|
|
27
|
-
@employees_all_fields = [:employee_id, :first_name, :last_name, :hire_date, :status]
|
|
28
|
-
@employees_all_values = @employees.map { |e| @employees_all_fields.map { |f| e[f] } }
|
|
29
|
-
@employees_some_fields = [:employee_id, :first_name, :last_name]
|
|
30
|
-
@employees_some_values = @employees.map { |e| @employees_some_fields.map { |f| e[f] } }
|
|
31
|
-
@employee_default_values = { hire_date: nil, status: "N" }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
after(:all) do
|
|
35
|
-
plsql.execute "DROP VIEW test_employees_v"
|
|
36
|
-
plsql.execute "DROP TABLE test_employees"
|
|
37
|
-
plsql.logoff
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
after(:each) do
|
|
41
|
-
plsql.rollback
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe "find" do
|
|
45
|
-
|
|
46
|
-
it "should find existing view" do
|
|
47
|
-
expect(PLSQL::View.find(plsql, :test_employees_v)).not_to be_nil
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it "should not find nonexisting view" do
|
|
51
|
-
expect(PLSQL::View.find(plsql, :qwerty123456)).to be_nil
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
it "should find existing view in schema" do
|
|
55
|
-
expect(plsql.test_employees_v).to be_instance_of(PLSQL::View)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
describe "synonym" do
|
|
61
|
-
|
|
62
|
-
before(:all) do
|
|
63
|
-
plsql.execute "CREATE SYNONYM test_employees_v_synonym FOR hr.test_employees_v"
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
after(:all) do
|
|
67
|
-
plsql.execute "DROP SYNONYM test_employees_v_synonym" rescue nil
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it "should find synonym to view" do
|
|
71
|
-
expect(PLSQL::View.find(plsql, :test_employees_v_synonym)).not_to be_nil
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "should find view using synonym in schema" do
|
|
75
|
-
expect(plsql.test_employees_v_synonym).to be_instance_of(PLSQL::View)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
describe "public synonym" do
|
|
81
|
-
|
|
82
|
-
it "should find public synonym to view" do
|
|
83
|
-
expect(PLSQL::View.find(plsql, :user_tables)).not_to be_nil
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it "should find view using public synonym in schema" do
|
|
87
|
-
expect(plsql.user_tables).to be_instance_of(PLSQL::View)
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
describe "columns" do
|
|
93
|
-
|
|
94
|
-
it "should get column names for view" do
|
|
95
|
-
expect(plsql.test_employees_v.column_names).to eq([:employee_id, :first_name, :last_name, :hire_date, :status])
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it "should get columns metadata for view" do
|
|
99
|
-
expect(plsql.test_employees_v.columns).to eq(
|
|
100
|
-
employee_id: {
|
|
101
|
-
position: 1, data_type: "NUMBER", data_length: 22, data_precision: 15, data_scale: 0, char_used: nil,
|
|
102
|
-
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: false, data_default: nil },
|
|
103
|
-
first_name: {
|
|
104
|
-
position: 2, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
|
|
105
|
-
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
|
|
106
|
-
last_name: {
|
|
107
|
-
position: 3, data_type: "VARCHAR2", data_length: 50, data_precision: nil, data_scale: nil, char_used: "B",
|
|
108
|
-
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
|
|
109
|
-
hire_date: {
|
|
110
|
-
position: 4, data_type: "DATE", data_length: 7, data_precision: nil, data_scale: nil, char_used: nil,
|
|
111
|
-
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil },
|
|
112
|
-
status: {
|
|
113
|
-
position: 5, data_type: "VARCHAR2", data_length: 1, data_precision: nil, data_scale: nil, char_used: "B",
|
|
114
|
-
type_owner: nil, type_name: nil, sql_type_name: nil, nullable: true, data_default: nil }
|
|
115
|
-
)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
describe "insert" do
|
|
121
|
-
it "should insert a record in view" do
|
|
122
|
-
plsql.test_employees_v.insert @employees.first
|
|
123
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first])
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
it "should insert a record in view using partial list of columns" do
|
|
127
|
-
plsql.test_employees_v.insert @employees.first.except(:hire_date)
|
|
128
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first.merge(hire_date: nil)])
|
|
129
|
-
end
|
|
130
|
-
|
|
131
|
-
it "should insert default value from table definition if value not provided" do
|
|
132
|
-
plsql.test_employees_v.insert @employees.first.except(:status)
|
|
133
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first.merge(status: "N")])
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
it "should insert array of records in view" do
|
|
137
|
-
plsql.test_employees_v.insert @employees
|
|
138
|
-
expect(plsql.test_employees_v.all("ORDER BY employee_id")).to eq(@employees)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
describe "insert values" do
|
|
144
|
-
it "should insert a record with array of values" do
|
|
145
|
-
plsql.test_employees_v.insert_values @employees_all_values.first
|
|
146
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first])
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
it "should insert a record with list of all fields and array of values" do
|
|
150
|
-
plsql.test_employees_v.insert_values @employees_all_fields, @employees_all_values.first
|
|
151
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first])
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
it "should insert a record with list of some fields and array of values" do
|
|
155
|
-
plsql.test_employees_v.insert_values @employees_some_fields, @employees_some_values.first
|
|
156
|
-
expect(plsql.test_employees_v.all).to eq([@employees.first.merge(@employee_default_values)])
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
it "should insert many records with array of values" do
|
|
160
|
-
plsql.test_employees_v.insert_values *@employees_all_values
|
|
161
|
-
expect(plsql.test_employees_v.all).to eq(@employees)
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
it "should insert many records with list of all fields and array of values" do
|
|
165
|
-
plsql.test_employees_v.insert_values @employees_all_fields, *@employees_all_values
|
|
166
|
-
expect(plsql.test_employees_v.all).to eq(@employees)
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
it "should insert many records with list of some fields and array of values" do
|
|
170
|
-
plsql.test_employees_v.insert_values @employees_some_fields, *@employees_some_values
|
|
171
|
-
expect(plsql.test_employees_v.all).to eq(@employees.map { |e| e.merge(@employee_default_values) })
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
describe "select" do
|
|
177
|
-
before(:each) do
|
|
178
|
-
plsql.test_employees_v.insert @employees
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
it "should select first record in view" do
|
|
182
|
-
expect(plsql.test_employees_v.select(:first, "ORDER BY employee_id")).to eq(@employees.first)
|
|
183
|
-
expect(plsql.test_employees_v.first("ORDER BY employee_id")).to eq(@employees.first)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
it "should select all records in view" do
|
|
187
|
-
expect(plsql.test_employees_v.select(:all, "ORDER BY employee_id")).to eq(@employees)
|
|
188
|
-
expect(plsql.test_employees_v.all("ORDER BY employee_id")).to eq(@employees)
|
|
189
|
-
expect(plsql.test_employees_v.all(order_by: :employee_id)).to eq(@employees)
|
|
190
|
-
end
|
|
191
|
-
|
|
192
|
-
it "should select record in view using WHERE condition" do
|
|
193
|
-
expect(plsql.test_employees_v.select(:first, "WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
|
194
|
-
expect(plsql.test_employees_v.first("WHERE employee_id = :1", @employees.first[:employee_id])).to eq(@employees.first)
|
|
195
|
-
expect(plsql.test_employees_v.first(employee_id: @employees.first[:employee_id])).to eq(@employees.first)
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
it "should select record in view using :column => nil condition" do
|
|
199
|
-
employee = @employees.last
|
|
200
|
-
employee[:employee_id] = employee[:employee_id] + 1
|
|
201
|
-
employee[:hire_date] = nil
|
|
202
|
-
plsql.test_employees_v.insert employee
|
|
203
|
-
expect(plsql.test_employees_v.first("WHERE hire_date IS NULL")).to eq(employee)
|
|
204
|
-
expect(plsql.test_employees_v.first(hire_date: nil)).to eq(employee)
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
it "should count records in view" do
|
|
208
|
-
expect(plsql.test_employees_v.select(:count)).to eq(@employees.size)
|
|
209
|
-
expect(plsql.test_employees_v.count).to eq(@employees.size)
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
it "should count records in view using condition" do
|
|
213
|
-
expect(plsql.test_employees_v.select(:count, "WHERE employee_id <= :1", @employees[2][:employee_id])).to eq(3)
|
|
214
|
-
expect(plsql.test_employees_v.count("WHERE employee_id <= :1", @employees[2][:employee_id])).to eq(3)
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
describe "update" do
|
|
220
|
-
it "should update a record in view" do
|
|
221
|
-
employee_id = @employees.first[:employee_id]
|
|
222
|
-
plsql.test_employees_v.insert @employees.first
|
|
223
|
-
plsql.test_employees_v.update first_name: "Test", where: { employee_id: employee_id }
|
|
224
|
-
expect(plsql.test_employees_v.first(employee_id: employee_id)[:first_name]).to eq("Test")
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
it "should update a record in view using String WHERE condition" do
|
|
228
|
-
employee_id = @employees.first[:employee_id]
|
|
229
|
-
plsql.test_employees_v.insert @employees
|
|
230
|
-
plsql.test_employees_v.update first_name: "Test", where: "employee_id = #{employee_id}"
|
|
231
|
-
expect(plsql.test_employees_v.first(employee_id: employee_id)[:first_name]).to eq("Test")
|
|
232
|
-
# all other records should not be changed
|
|
233
|
-
plsql.test_employees_v.all("WHERE employee_id > :1", employee_id) do |employee|
|
|
234
|
-
expect(employee[:first_name]).not_to eq("Test")
|
|
235
|
-
end
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
it "should update all records in view" do
|
|
239
|
-
plsql.test_employees_v.insert @employees
|
|
240
|
-
plsql.test_employees_v.update first_name: "Test"
|
|
241
|
-
plsql.test_employees_v.all do |employee|
|
|
242
|
-
expect(employee[:first_name]).to eq("Test")
|
|
243
|
-
end
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
describe "delete" do
|
|
249
|
-
it "should delete record from view" do
|
|
250
|
-
employee_id = @employees.first[:employee_id]
|
|
251
|
-
plsql.test_employees_v.insert @employees
|
|
252
|
-
plsql.test_employees_v.delete employee_id: employee_id
|
|
253
|
-
expect(plsql.test_employees_v.first(employee_id: employee_id)).to be_nil
|
|
254
|
-
expect(plsql.test_employees_v.all(order_by: :employee_id)).to eq(@employees[1, @employees.size - 1])
|
|
255
|
-
end
|
|
256
|
-
|
|
257
|
-
it "should delete all records from view" do
|
|
258
|
-
plsql.test_employees_v.insert @employees
|
|
259
|
-
plsql.test_employees_v.delete
|
|
260
|
-
expect(plsql.test_employees_v.all).to be_empty
|
|
261
|
-
end
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
end
|
data/spec/spec.opts
DELETED
data/spec/spec_helper.rb
DELETED
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
require "rubygems"
|
|
2
|
-
require "bundler"
|
|
3
|
-
Bundler.setup(:default, :development)
|
|
4
|
-
require "simplecov"
|
|
5
|
-
|
|
6
|
-
SimpleCov.configure do
|
|
7
|
-
load_profile "root_filter"
|
|
8
|
-
load_profile "test_frameworks"
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
ENV["COVERAGE"] && SimpleCov.start do
|
|
12
|
-
add_filter "/.rvm/"
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
|
|
16
|
-
require "rspec"
|
|
17
|
-
|
|
18
|
-
unless ENV["NO_ACTIVERECORD"]
|
|
19
|
-
require "active_record"
|
|
20
|
-
else
|
|
21
|
-
puts "Without ActiveRecord"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
require "ruby-plsql"
|
|
25
|
-
|
|
26
|
-
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
27
|
-
# in spec/support/ and its subdirectories.
|
|
28
|
-
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each { |f| require f }
|
|
29
|
-
|
|
30
|
-
if ENV["USE_VM_DATABASE"] == "Y"
|
|
31
|
-
DATABASE_NAME = "XE"
|
|
32
|
-
else
|
|
33
|
-
DATABASE_NAME = ENV["DATABASE_NAME"] || "orcl"
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
DATABASE_SERVICE_NAME = (defined?(JRUBY_VERSION) ? "/" : "") +
|
|
37
|
-
(ENV["DATABASE_SERVICE_NAME"] || DATABASE_NAME)
|
|
38
|
-
DATABASE_HOST = ENV["DATABASE_HOST"] || "localhost"
|
|
39
|
-
DATABASE_PORT = (ENV["DATABASE_PORT"] || 1521).to_i
|
|
40
|
-
DATABASE_USERS_AND_PASSWORDS = [
|
|
41
|
-
[ENV["DATABASE_USER"] || "hr", ENV["DATABASE_PASSWORD"] || "hr"],
|
|
42
|
-
[ENV["DATABASE_USER2"] || "arunit", ENV["DATABASE_PASSWORD2"] || "arunit"]
|
|
43
|
-
]
|
|
44
|
-
# specify which database version is used (will be verified in one test)
|
|
45
|
-
DATABASE_VERSION = ENV["DATABASE_VERSION"] || "10.2.0.4"
|
|
46
|
-
|
|
47
|
-
if ENV["USE_VM_DATABASE"] == "Y"
|
|
48
|
-
RSpec.configure do |config|
|
|
49
|
-
config.before(:suite) do
|
|
50
|
-
TestDb.build
|
|
51
|
-
|
|
52
|
-
# Set Verbose off to hide warning: already initialized constant DATABASE_VERSION
|
|
53
|
-
original_verbosity = $VERBOSE
|
|
54
|
-
$VERBOSE = nil
|
|
55
|
-
DATABASE_VERSION = TestDb.database_version
|
|
56
|
-
$VERBOSE = original_verbosity
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
def oracle_error_class
|
|
62
|
-
unless defined?(JRUBY_VERSION)
|
|
63
|
-
OCIError
|
|
64
|
-
else
|
|
65
|
-
java.sql.SQLException
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def get_eazy_connect_url(svc_separator = "")
|
|
70
|
-
"#{DATABASE_HOST}:#{DATABASE_PORT}#{svc_separator}#{DATABASE_SERVICE_NAME}"
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def get_connection_url
|
|
74
|
-
unless defined?(JRUBY_VERSION)
|
|
75
|
-
(ENV["DATABASE_USE_TNS"] == "NO") ? get_eazy_connect_url("/") : DATABASE_NAME
|
|
76
|
-
else
|
|
77
|
-
"jdbc:oracle:thin:@#{get_eazy_connect_url}"
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def get_connection(user_number = 0)
|
|
82
|
-
database_user, database_password = DATABASE_USERS_AND_PASSWORDS[user_number]
|
|
83
|
-
unless defined?(JRUBY_VERSION)
|
|
84
|
-
try_to_connect(OCIError) do
|
|
85
|
-
OCI8.new(database_user, database_password, get_connection_url)
|
|
86
|
-
end
|
|
87
|
-
else
|
|
88
|
-
try_to_connect(Java::JavaSql::SQLException) do
|
|
89
|
-
java.sql.DriverManager.getConnection(get_connection_url, database_user, database_password)
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
def try_to_connect(exception)
|
|
95
|
-
begin
|
|
96
|
-
yield
|
|
97
|
-
# if connection fails then sleep 5 seconds and retry
|
|
98
|
-
rescue exception
|
|
99
|
-
sleep 5
|
|
100
|
-
yield
|
|
101
|
-
end
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
CONNECTION_PARAMS = {
|
|
105
|
-
adapter: "oracle_enhanced",
|
|
106
|
-
database: DATABASE_SERVICE_NAME,
|
|
107
|
-
host: DATABASE_HOST,
|
|
108
|
-
port: DATABASE_PORT,
|
|
109
|
-
username: DATABASE_USERS_AND_PASSWORDS[0][0],
|
|
110
|
-
password: DATABASE_USERS_AND_PASSWORDS[0][1]
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
class Hash
|
|
114
|
-
def except(*blacklist)
|
|
115
|
-
self.reject { |key, value| blacklist.include?(key) }
|
|
116
|
-
end unless method_defined?(:except)
|
|
117
|
-
|
|
118
|
-
def only(*whitelist)
|
|
119
|
-
self.reject { |key, value| !whitelist.include?(key) }
|
|
120
|
-
end unless method_defined?(:only)
|
|
121
|
-
end
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
# Template file should be copied to locale_support.rb to be automatically included by code
|
|
2
|
-
#
|
|
3
|
-
|
|
4
|
-
# Set Oracle Database session timezone, if not already set in env variable
|
|
5
|
-
# This setting needs to be in place to make sure that Oracle properly represents the timestamp format on your local machine.
|
|
6
|
-
# Do not use 'OS_TZ' value or fixed offset values like '05:00', for daylight saving-enabled timezones.
|
|
7
|
-
# See: http://docs.oracle.com/cd/E18283_01/server.112/e10729/ch4datetime.htm#CBBEEAFB
|
|
8
|
-
# The setting cannot be derived directly from operating system or ruby, as different timezone names are used.
|
|
9
|
-
ENV['ORA_SDTZ'] ||= 'Europe/Riga'
|
|
10
|
-
#Sets the Ruby timezone to be used, if not already set in env variable
|
|
11
|
-
ENV['TZ'] ||= 'Europe/Riga'
|
|
12
|
-
#Sets the Language, locale and encoding settings to be used by Oracle session, if not already set in env variable
|
|
13
|
-
ENV['NLS_LANG'] ||= 'AMERICAN_AMERICA.AL32UTF8'
|
|
14
|
-
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
set -e
|
|
3
|
-
|
|
4
|
-
FILE=/vagrant/oracle-xe-11.2.0-1.0.x86_64.rpm.zip
|
|
5
|
-
|
|
6
|
-
if [ ! -f "$FILE" ] ; then
|
|
7
|
-
echo "Oracle XE database installation (oracle-xe-11.2.0-1.0.x86_64.rpm.zip) can not be found. Please download from Oracle homepage and put it into project home directory."
|
|
8
|
-
exit 1
|
|
9
|
-
fi
|
data/spec/support/test_db.rb
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
class TestDb
|
|
2
|
-
DATABASE_USERS = %w{hr arunit}
|
|
3
|
-
|
|
4
|
-
def self.build
|
|
5
|
-
db = self.new
|
|
6
|
-
db.cleanup_database_users
|
|
7
|
-
db.create_user_tablespace
|
|
8
|
-
db.setup_database_users
|
|
9
|
-
db.connection.logoff
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.database_version
|
|
13
|
-
db = self.new
|
|
14
|
-
db.database_version
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
def connection
|
|
18
|
-
unless defined?(@connection)
|
|
19
|
-
begin
|
|
20
|
-
Timeout::timeout(5) {
|
|
21
|
-
if defined?(JRUBY_VERSION)
|
|
22
|
-
@connection = java.sql.DriverManager.get_connection(
|
|
23
|
-
"jdbc:oracle:thin:@127.0.0.1:1521/XE",
|
|
24
|
-
"system",
|
|
25
|
-
"oracle"
|
|
26
|
-
)
|
|
27
|
-
else
|
|
28
|
-
@connection = OCI8.new(
|
|
29
|
-
"system",
|
|
30
|
-
"oracle",
|
|
31
|
-
"(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=127.0.0.1)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)))"
|
|
32
|
-
)
|
|
33
|
-
end
|
|
34
|
-
}
|
|
35
|
-
rescue Timeout::Error
|
|
36
|
-
raise "Cannot establish connection with Oracle database as SYSTEM user. Seams you need to start local Oracle database"
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
@connection
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
def create_user_tablespace
|
|
43
|
-
return unless connection
|
|
44
|
-
execute_statement(<<-STATEMENT
|
|
45
|
-
DECLARE
|
|
46
|
-
v_exists number;
|
|
47
|
-
BEGIN
|
|
48
|
-
SELECT count(1)
|
|
49
|
-
INTO v_exists
|
|
50
|
-
FROM dba_tablespaces
|
|
51
|
-
WHERE tablespace_name = 'TBS_USERS';
|
|
52
|
-
|
|
53
|
-
IF v_exists = 0 THEN
|
|
54
|
-
EXECUTE IMMEDIATE 'ALTER SYSTEM SET DB_CREATE_FILE_DEST = ''/u01/app/oracle/oradata/XE''';
|
|
55
|
-
EXECUTE IMMEDIATE 'CREATE TABLESPACE TBS_USERS DATAFILE ''tbs_users.dat'' SIZE 10M REUSE AUTOEXTEND ON NEXT 10M MAXSIZE 200M';
|
|
56
|
-
END IF;
|
|
57
|
-
END;
|
|
58
|
-
STATEMENT
|
|
59
|
-
)
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def database_users
|
|
63
|
-
DATABASE_USERS.inject([]) { |array, user| array << [user.upcase, user] }
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def cleanup_database_users
|
|
67
|
-
return unless connection
|
|
68
|
-
database_users.each do | db, _ |
|
|
69
|
-
execute_statement(<<-STATEMENT
|
|
70
|
-
DECLARE
|
|
71
|
-
v_count INTEGER := 0;
|
|
72
|
-
l_cnt INTEGER;
|
|
73
|
-
BEGIN
|
|
74
|
-
|
|
75
|
-
SELECT COUNT (1)
|
|
76
|
-
INTO v_count
|
|
77
|
-
FROM dba_users
|
|
78
|
-
WHERE username = '#{db}';
|
|
79
|
-
|
|
80
|
-
IF v_count != 0 THEN
|
|
81
|
-
FOR x IN (SELECT *
|
|
82
|
-
FROM v$session
|
|
83
|
-
WHERE username = '#{db}')
|
|
84
|
-
LOOP
|
|
85
|
-
EXECUTE IMMEDIATE 'ALTER SYSTEM DISCONNECT SESSION ''' || x.sid || ',' || x.serial# || ''' IMMEDIATE';
|
|
86
|
-
END LOOP;
|
|
87
|
-
|
|
88
|
-
EXECUTE IMMEDIATE ('DROP USER #{db} CASCADE');
|
|
89
|
-
END IF;
|
|
90
|
-
END;
|
|
91
|
-
STATEMENT
|
|
92
|
-
)
|
|
93
|
-
end
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
def setup_database_users
|
|
97
|
-
return unless connection
|
|
98
|
-
database_users.each do | db, passwd |
|
|
99
|
-
execute_statement(<<-STATEMENT
|
|
100
|
-
DECLARE
|
|
101
|
-
v_count INTEGER := 0;
|
|
102
|
-
BEGIN
|
|
103
|
-
|
|
104
|
-
SELECT COUNT (1)
|
|
105
|
-
INTO v_count
|
|
106
|
-
FROM dba_users
|
|
107
|
-
WHERE username = '#{db}';
|
|
108
|
-
|
|
109
|
-
IF v_count = 0 THEN
|
|
110
|
-
EXECUTE IMMEDIATE ('CREATE USER #{db} IDENTIFIED BY #{passwd} DEFAULT TABLESPACE TBS_USERS QUOTA 10m ON TBS_USERS');
|
|
111
|
-
EXECUTE IMMEDIATE ('GRANT create session, create table, create sequence, create procedure, create type, create view, create synonym TO #{db}');
|
|
112
|
-
END IF;
|
|
113
|
-
END;
|
|
114
|
-
STATEMENT
|
|
115
|
-
)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def database_version
|
|
120
|
-
query = "SELECT version FROM V$INSTANCE"
|
|
121
|
-
|
|
122
|
-
if defined?(JRUBY_VERSION)
|
|
123
|
-
statement = connection.create_statement
|
|
124
|
-
resource = statement.execute_query(query)
|
|
125
|
-
|
|
126
|
-
resource.next
|
|
127
|
-
value = resource.get_string("VERSION")
|
|
128
|
-
|
|
129
|
-
resource.close
|
|
130
|
-
statement.close
|
|
131
|
-
else
|
|
132
|
-
cursor = execute_statement(query)
|
|
133
|
-
value = cursor.fetch()[0]
|
|
134
|
-
cursor.close
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
value.match(/(.*)\.\d$/)[1]
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
def execute_statement(statement)
|
|
141
|
-
if defined?(JRUBY_VERSION)
|
|
142
|
-
statement = connection.prepare_call(statement)
|
|
143
|
-
statement.execute
|
|
144
|
-
statement.close
|
|
145
|
-
else
|
|
146
|
-
connection.exec(statement)
|
|
147
|
-
end
|
|
148
|
-
end
|
|
149
|
-
end
|