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.
Files changed (56) hide show
  1. checksums.yaml +4 -4
  2. data/History.txt +2 -0
  3. data/VERSION +1 -1
  4. data/lib/plsql/connection.rb +14 -14
  5. data/lib/plsql/helpers.rb +3 -3
  6. data/lib/plsql/jdbc_connection.rb +3 -3
  7. data/lib/plsql/oci_connection.rb +8 -4
  8. data/lib/plsql/package.rb +3 -3
  9. data/lib/plsql/procedure.rb +32 -17
  10. data/lib/plsql/procedure_call.rb +15 -15
  11. data/lib/plsql/schema.rb +13 -9
  12. data/lib/plsql/sequence.rb +2 -2
  13. data/lib/plsql/table.rb +6 -6
  14. data/lib/plsql/type.rb +7 -7
  15. data/lib/plsql/variable.rb +4 -4
  16. data/lib/plsql/version.rb +1 -1
  17. data/lib/plsql/view.rb +2 -2
  18. metadata +13 -138
  19. data/.github/stale.yml +0 -37
  20. data/.github/workflows/rubocop.yml +0 -37
  21. data/.github/workflows/test.yml +0 -69
  22. data/.rubocop.yml +0 -147
  23. data/.travis/oracle/download.sh +0 -15
  24. data/.travis/oracle/install.sh +0 -32
  25. data/.travis/setup_accounts.sh +0 -9
  26. data/.travis.yml +0 -88
  27. data/Gemfile +0 -24
  28. data/Rakefile +0 -53
  29. data/Vagrantfile +0 -38
  30. data/ci/network/admin/tnsnames.ora +0 -7
  31. data/ci/setup_accounts.sh +0 -9
  32. data/gemfiles/Gemfile.activerecord-5.0 +0 -21
  33. data/gemfiles/Gemfile.activerecord-5.1 +0 -21
  34. data/gemfiles/Gemfile.activerecord-5.2 +0 -21
  35. data/gemfiles/Gemfile.activerecord-6.0 +0 -21
  36. data/gemfiles/Gemfile.activerecord-6.1 +0 -21
  37. data/gemfiles/Gemfile.activerecord-main +0 -21
  38. data/ruby-plsql.gemspec +0 -114
  39. data/spec/plsql/connection_spec.rb +0 -505
  40. data/spec/plsql/package_spec.rb +0 -172
  41. data/spec/plsql/procedure_spec.rb +0 -2390
  42. data/spec/plsql/schema_spec.rb +0 -364
  43. data/spec/plsql/sequence_spec.rb +0 -67
  44. data/spec/plsql/sql_statements_spec.rb +0 -91
  45. data/spec/plsql/table_spec.rb +0 -376
  46. data/spec/plsql/type_spec.rb +0 -299
  47. data/spec/plsql/variable_spec.rb +0 -497
  48. data/spec/plsql/version_spec.rb +0 -8
  49. data/spec/plsql/view_spec.rb +0 -264
  50. data/spec/spec.opts +0 -6
  51. data/spec/spec_helper.rb +0 -121
  52. data/spec/support/create_arunit_user.sql +0 -2
  53. data/spec/support/custom_config.rb.sample +0 -14
  54. data/spec/support/file_check_script.sh +0 -9
  55. data/spec/support/test_db.rb +0 -149
  56. data/spec/support/unlock_and_setup_hr_user.sql +0 -2
@@ -1,364 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Schema" do
4
-
5
- it "should create Schema object" do
6
- expect(plsql.class).to eq(PLSQL::Schema)
7
- end
8
-
9
- end
10
-
11
- describe "Schema connection" do
12
-
13
- before(:each) do
14
- @conn = get_connection
15
- end
16
-
17
- after(:each) do
18
- unless defined? JRUBY_VERSION
19
- @conn.logoff
20
- else
21
- @conn.close
22
- end
23
- end
24
-
25
- it "should connect to test database" do
26
- plsql.connection = @conn
27
- expect(plsql.connection.raw_connection).to eq(@conn)
28
- end
29
-
30
- it "should connect to test database using connection alias" do
31
- plsql(:hr).connection = @conn
32
- expect(plsql(:hr).connection.raw_connection).to eq(@conn)
33
- end
34
-
35
- it "should return schema name" do
36
- plsql.connection = @conn
37
- expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
38
- end
39
-
40
- it "should match altered current_schema in database session" do
41
- plsql.connection = @conn
42
- expected_current_schema = DATABASE_USERS_AND_PASSWORDS[1][0]
43
- plsql.execute "ALTER SESSION set current_schema=#{expected_current_schema}"
44
- expect(plsql.schema_name).to eq(expected_current_schema.upcase)
45
- end
46
-
47
- it "should return new schema name after reconnection" do
48
- plsql.connection = @conn
49
- expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[0][0].upcase)
50
- plsql.connection = get_connection(1)
51
- expect(plsql.schema_name).to eq(DATABASE_USERS_AND_PASSWORDS[1][0].upcase)
52
- end
53
-
54
- it "should return nil schema name if not connected" do
55
- expect(plsql(:xxx).schema_name).to eq(nil)
56
- end
57
-
58
- end
59
-
60
- describe "Connection with connect!" do
61
-
62
- before(:all) do
63
- @username, @password = DATABASE_USERS_AND_PASSWORDS[0]
64
- @database = DATABASE_NAME
65
- @database_service = DATABASE_SERVICE_NAME
66
- @host = DATABASE_HOST
67
- @port = DATABASE_PORT
68
- end
69
-
70
- after(:each) do
71
- plsql.logoff if plsql.connection
72
- end
73
-
74
- it "should connect with username, password and database alias" do
75
- plsql.connect! @username, @password, @database
76
- expect(plsql.connection).not_to be_nil
77
- expect(plsql.schema_name).to eq(@username.upcase)
78
- end
79
-
80
- it "should connect with username, password, host, port and database name" do
81
- plsql.connect! @username, @password, host: @host, port: @port, database: @database_service
82
- expect(plsql.connection).not_to be_nil
83
- expect(plsql.schema_name).to eq(@username.upcase)
84
- end
85
-
86
- it "should connect with username, password, host, database name and default port" do
87
- skip "Non-default port used for test database" unless @port == 1521
88
- plsql.connect! @username, @password, host: @host, database: @database_service
89
- expect(plsql.connection).not_to be_nil
90
- expect(plsql.schema_name).to eq(@username.upcase)
91
- end
92
-
93
- it "should not connect with wrong port number" do
94
- expect {
95
- plsql.connect! @username, @password, host: @host, port: 9999, database: @database
96
- }.to raise_error(/ORA-12541|could not establish the connection/)
97
- end
98
-
99
- it "should connect with one Hash parameter" do
100
- plsql.connect! username: @username, password: @password, database: @database
101
- expect(plsql.connection).not_to be_nil
102
- expect(plsql.schema_name).to eq(@username.upcase)
103
- end
104
-
105
- it "should set session time zone from ORA_SDTZ environment variable" do
106
- plsql.connect! @username, @password, @database
107
- expect(plsql.connection.time_zone).to eq(ENV["ORA_SDTZ"])
108
- end if ENV["ORA_SDTZ"]
109
-
110
- it "should set session time zone from :time_zone parameter" do
111
- plsql.connect! username: @username, password: @password, database: @database, time_zone: "EET"
112
- expect(plsql.connection.time_zone).to eq("EET")
113
- end
114
-
115
- end
116
-
117
- describe "Named Schema" do
118
- before(:all) do
119
- plsql.connection = @conn = get_connection
120
- end
121
-
122
- after(:all) do
123
- plsql.connection.logoff
124
- end
125
-
126
- it "should find existing schema" do
127
- expect(plsql.hr.class).to eq(PLSQL::Schema)
128
- end
129
-
130
- it "should have the same connection as default schema" do
131
- expect(plsql.hr.connection.raw_connection).to eq(@conn)
132
- end
133
-
134
- it "should return schema name" do
135
- expect(plsql.hr.schema_name).to eq("HR")
136
- end
137
-
138
- it "should not find named schema if specified twice" do
139
- expect { plsql.hr.hr }.to raise_error(ArgumentError)
140
- end
141
-
142
- end
143
-
144
- describe "Schema commit and rollback" do
145
- before(:all) do
146
- plsql.connection = @conn = get_connection
147
- plsql.connection.autocommit = false
148
- plsql.execute "CREATE TABLE test_commit (dummy VARCHAR2(100))"
149
- @data = { dummy: "test" }
150
- @data2 = { dummy: "test2" }
151
- end
152
-
153
- after(:all) do
154
- plsql.execute "DROP TABLE test_commit"
155
- plsql.logoff
156
- end
157
-
158
- after(:each) do
159
- plsql.test_commit.delete
160
- plsql.commit
161
- end
162
-
163
- it "should do commit" do
164
- plsql.test_commit.insert @data
165
- plsql.commit
166
- expect(plsql.test_commit.first).to eq(@data)
167
- end
168
-
169
- it "should do rollback" do
170
- plsql.test_commit.insert @data
171
- plsql.rollback
172
- expect(plsql.test_commit.first).to be_nil
173
- end
174
-
175
- it "should create savepoint and rollback to savepoint" do
176
- plsql.test_commit.insert @data
177
- plsql.savepoint "test"
178
- plsql.test_commit.insert @data2
179
- expect(plsql.test_commit.all).to eq([@data, @data2])
180
- plsql.rollback_to "test"
181
- expect(plsql.test_commit.all).to eq([@data])
182
- end
183
-
184
- end
185
-
186
- describe "ActiveRecord connection" do
187
- before(:all) do
188
- ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
189
- class TestBaseModel < ActiveRecord::Base
190
- self.abstract_class = true
191
- end
192
- class TestModel < TestBaseModel
193
- end
194
- end
195
-
196
- before(:each) do
197
- plsql.activerecord_class = ActiveRecord::Base
198
- end
199
-
200
- it "should connect to test database" do
201
- unless defined?(JRUBY_VERSION)
202
- expect(plsql.connection.is_a?(PLSQL::OCIConnection)).to be_truthy
203
- else
204
- expect(plsql.connection.is_a?(PLSQL::JDBCConnection)).to be_truthy
205
- end
206
- end
207
-
208
- it "should return schema name" do
209
- expect(plsql.schema_name).to eq("HR")
210
- end
211
-
212
- it "should use ActiveRecord::Base.default_timezone as default" do
213
- ActiveRecord::Base.default_timezone = :utc
214
- expect(plsql.default_timezone).to eq(:utc)
215
- end
216
-
217
- it "should have the same connection as default schema" do
218
- expect(plsql.hr.connection).to eq(plsql.connection)
219
- end
220
-
221
- it "should accept inherited ActiveRecord class" do
222
- plsql.activerecord_class = TestBaseModel
223
- expect(plsql.schema_name).to eq("HR")
224
- end
225
-
226
- it "should accept subclass of inherited ActiveRecord class" do
227
- plsql.activerecord_class = TestModel
228
- expect(plsql.schema_name).to eq("HR")
229
- end
230
-
231
- it "should safely close cursors in threaded environment" do
232
- if (plsql.connection.database_version <=> [18, 0, 0, 0]) >= 0
233
- expect {
234
- t1 = Thread.new { plsql.dbms_session.sleep(1) }.tap { |t| t.abort_on_exception = true }
235
- t2 = Thread.new { plsql.dbms_session.sleep(2) }.tap { |t| t.abort_on_exception = true }
236
- [t2, t1].each { |t| t.join }
237
- }.not_to raise_error
238
- else
239
- expect {
240
- t1 = Thread.new { plsql.dbms_lock.sleep(1) }.tap { |t| t.abort_on_exception = true }
241
- t2 = Thread.new { plsql.dbms_lock.sleep(2) }.tap { |t| t.abort_on_exception = true }
242
- [t2, t1].each { |t| t.join }
243
- }.not_to raise_error
244
- end
245
- end
246
-
247
- end if defined?(ActiveRecord)
248
-
249
- describe "DBMS_OUTPUT logging" do
250
-
251
- before(:all) do
252
- plsql.connection = get_connection
253
- plsql.execute <<-SQL
254
- CREATE OR REPLACE PROCEDURE test_dbms_output(p_string VARCHAR2, p_raise_error BOOLEAN := false)
255
- IS
256
- BEGIN
257
- DBMS_OUTPUT.PUT_LINE(p_string);
258
- IF p_raise_error THEN
259
- RAISE_APPLICATION_ERROR(-20000 - 12, 'Test Error');
260
- END IF;
261
- END;
262
- SQL
263
- plsql.execute <<-SQL
264
- CREATE OR REPLACE PROCEDURE test_dbms_output_large(p_string VARCHAR2, p_times INTEGER)
265
- IS
266
- i INTEGER;
267
- BEGIN
268
- FOR i IN 1..p_times LOOP
269
- DBMS_OUTPUT.PUT_LINE(p_string);
270
- END LOOP;
271
- END;
272
- SQL
273
- @buffer = StringIO.new
274
- end
275
-
276
- before(:each) do
277
- @buffer.rewind
278
- @buffer.reopen
279
- end
280
-
281
- after(:all) do
282
- plsql.dbms_output_stream = nil
283
- plsql.execute "DROP PROCEDURE test_dbms_output"
284
- plsql.execute "DROP PROCEDURE test_dbms_output_large"
285
- plsql.logoff
286
- end
287
-
288
- describe "with standard connection" do
289
- before(:all) do
290
- plsql.dbms_output_stream = @buffer
291
- end
292
-
293
- before(:each) do
294
- plsql.dbms_output_buffer_size = nil
295
- end
296
-
297
- it "should log output to specified stream" do
298
- plsql.test_dbms_output("test_dbms_output")
299
- expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
300
- end
301
-
302
- it "should log output to specified stream in case of exception" do
303
- expect { plsql.test_dbms_output("test_dbms_output", true) }.to raise_error /Test Error/
304
- expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
305
- end
306
-
307
- it "should not log output to stream when output is disabled" do
308
- plsql.test_dbms_output("enabled")
309
- plsql.dbms_output_stream = nil
310
- plsql.test_dbms_output("disabled")
311
- plsql.dbms_output_stream = @buffer
312
- plsql.test_dbms_output("enabled again")
313
- expect(@buffer.string).to eq("DBMS_OUTPUT: enabled\nDBMS_OUTPUT: enabled again\n")
314
- end
315
-
316
- it "should log 20_000 character output with default buffer size" do
317
- times = 2_000
318
- plsql.test_dbms_output_large("1234567890", times)
319
- expect(@buffer.string).to eq("DBMS_OUTPUT: 1234567890\n" * times)
320
- end
321
-
322
- it "should log 100_000 character output with specified buffer size" do
323
- times = 10_000
324
- plsql.dbms_output_buffer_size = 10 * times
325
- plsql.test_dbms_output_large("1234567890", times)
326
- expect(@buffer.string).to eq("DBMS_OUTPUT: 1234567890\n" * times)
327
- end
328
-
329
- it "should log output when database version is less than 10.2" do
330
- allow(plsql.connection).to receive(:database_version).and_return([9, 2, 0, 0])
331
- times = 2_000
332
- plsql.test_dbms_output_large("1234567890", times)
333
- expect(@buffer.string).to eq("DBMS_OUTPUT: 1234567890\n" * times)
334
- end
335
-
336
- it "should log output when calling procedure with schema prefix" do
337
- plsql.hr.test_dbms_output("test_dbms_output")
338
- expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
339
- end
340
-
341
- end
342
-
343
- describe "with Activerecord connection" do
344
-
345
- before(:all) do
346
- ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
347
- plsql(:ar).activerecord_class = ActiveRecord::Base
348
- plsql(:ar).dbms_output_stream = @buffer
349
- end
350
-
351
- it "should log output to specified stream" do
352
- plsql(:ar).test_dbms_output("test_dbms_output")
353
- expect(@buffer.string).to eq("DBMS_OUTPUT: test_dbms_output\n")
354
- end
355
-
356
- it "should log output after reconnection" do
357
- ActiveRecord::Base.connection.reconnect!
358
- plsql(:ar).test_dbms_output("after reconnection")
359
- expect(@buffer.string).to eq("DBMS_OUTPUT: after reconnection\n")
360
- end
361
-
362
- end if defined?(ActiveRecord)
363
-
364
- end
@@ -1,67 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Table" do
4
- before(:all) do
5
- plsql.connection = get_connection
6
- plsql.connection.autocommit = false
7
- plsql.execute "CREATE SEQUENCE test_employees_seq"
8
- end
9
-
10
- after(:all) do
11
- plsql.execute "DROP SEQUENCE test_employees_seq"
12
- plsql.logoff
13
- end
14
-
15
- after(:each) do
16
- plsql.rollback
17
- end
18
-
19
- describe "find" do
20
-
21
- it "should find existing sequence" do
22
- expect(PLSQL::Sequence.find(plsql, :test_employees_seq)).not_to be_nil
23
- end
24
-
25
- it "should not find nonexisting table" do
26
- expect(PLSQL::Sequence.find(plsql, :qwerty123456)).to be_nil
27
- end
28
-
29
- it "should find existing sequence in schema" do
30
- expect(plsql.test_employees_seq).to be_a(PLSQL::Sequence)
31
- end
32
-
33
- end
34
-
35
- describe "synonym" do
36
-
37
- before(:all) do
38
- plsql.connection.exec "CREATE SYNONYM test_employees_seq_synonym FOR hr.test_employees_seq"
39
- end
40
-
41
- after(:all) do
42
- plsql.connection.exec "DROP SYNONYM test_employees_seq_synonym" rescue nil
43
- end
44
-
45
- it "should find synonym to sequence" do
46
- expect(PLSQL::Sequence.find(plsql, :test_employees_seq_synonym)).not_to be_nil
47
- end
48
-
49
- it "should find sequence using synonym in schema" do
50
- expect(plsql.test_employees_seq_synonym).to be_a(PLSQL::Sequence)
51
- end
52
-
53
- end
54
-
55
- describe "values" do
56
- it "should get next value from sequence" do
57
- next_value = plsql.select_one "SELECT test_employees_seq.NEXTVAL FROM dual"
58
- expect(plsql.test_employees_seq.nextval).to eq(next_value + 1)
59
- end
60
-
61
- it "should get current value from sequence" do
62
- next_value = plsql.test_employees_seq.nextval
63
- expect(plsql.test_employees_seq.currval).to eq(next_value)
64
- end
65
- end
66
-
67
- end
@@ -1,91 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "SQL statements /" do
4
- before(:all) do
5
- plsql.connect! CONNECTION_PARAMS
6
- plsql.connection.autocommit = false
7
- end
8
-
9
- after(:all) do
10
- plsql.logoff
11
- end
12
-
13
- after(:each) do
14
- plsql.rollback
15
- end
16
-
17
- describe "SELECT" do
18
- before(:all) do
19
- plsql.execute "DROP TABLE test_employees" rescue nil
20
- plsql.execute <<-SQL
21
- CREATE TABLE test_employees (
22
- employee_id NUMBER(15),
23
- first_name VARCHAR2(50),
24
- last_name VARCHAR(50),
25
- hire_date DATE
26
- )
27
- SQL
28
- plsql.execute <<-SQL
29
- CREATE OR REPLACE PROCEDURE test_insert_employee(p_employee test_employees%ROWTYPE)
30
- IS
31
- BEGIN
32
- INSERT INTO test_employees
33
- VALUES p_employee;
34
- END;
35
- SQL
36
- @employees = (1..10).map do |i|
37
- {
38
- employee_id: i,
39
- first_name: "First #{i}",
40
- last_name: "Last #{i}",
41
- hire_date: Time.local(2000, 01, i)
42
- }
43
- end
44
- plsql.connection.prefetch_rows = 100
45
- end
46
-
47
- before(:each) do
48
- @employees.each do |e|
49
- plsql.test_insert_employee(e)
50
- end
51
- end
52
-
53
- after(:all) do
54
- plsql.execute "DROP PROCEDURE test_insert_employee"
55
- plsql.execute "DROP TABLE test_employees"
56
- plsql.connection.prefetch_rows = 1
57
- end
58
-
59
- it "should select first result" do
60
- expect(plsql.select(:first, "SELECT * FROM test_employees WHERE employee_id = :employee_id",
61
- @employees.first[:employee_id])).to eq(@employees.first)
62
- end
63
-
64
- it "should prefetch only one row when selecting first result" do
65
- expect {
66
- plsql.select(:first, "SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual")
67
- }.not_to raise_error
68
- end
69
-
70
- it "should select one value" do
71
- expect(plsql.select_one("SELECT count(*) FROM test_employees")).to eq(@employees.size)
72
- end
73
-
74
- it "should return nil when selecting non-existing one value" do
75
- expect(plsql.select_one("SELECT employee_id FROM test_employees WHERE 1=2")).to be_nil
76
- end
77
-
78
- it "should prefetch only one row when selecting one value" do
79
- expect {
80
- plsql.select_one("SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual")
81
- }.not_to raise_error
82
- end
83
-
84
- it "should select all results" do
85
- expect(plsql.select(:all, "SELECT * FROM test_employees ORDER BY employee_id")).to eq(@employees)
86
- expect(plsql.select("SELECT * FROM test_employees ORDER BY employee_id")).to eq(@employees)
87
- end
88
-
89
- end
90
-
91
- end