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,505 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "spec_helper"
4
-
5
- describe "Connection" do
6
-
7
- before(:all) do
8
- @raw_conn = get_connection
9
- @conn = PLSQL::Connection.create(@raw_conn)
10
- end
11
-
12
- after(:all) do
13
- unless defined?(JRuby)
14
- @raw_conn.logoff rescue nil
15
- else
16
- @raw_conn.close rescue nil
17
- end
18
- end
19
-
20
- describe "create and destroy" do
21
- before(:all) do
22
- @raw_conn1 = get_connection
23
- end
24
-
25
- before(:each) do
26
- @conn1 = PLSQL::Connection.create(@raw_conn1)
27
- end
28
-
29
- it "should create connection" do
30
- expect(@conn1.raw_connection).to eq @raw_conn1
31
- end
32
-
33
- unless defined?(JRuby)
34
- it "should be oci connection" do
35
- expect(@conn1).to be_oci
36
- expect(@conn1.raw_driver).to eq :oci
37
- end
38
- else
39
- it "should be jdbc connection" do
40
- expect(@conn1).to be_jdbc
41
- expect(@conn1.raw_driver).to eq :jdbc
42
- end
43
- end
44
-
45
- it "should logoff connection" do
46
- expect(@conn1.logoff).to be true
47
- end
48
-
49
- end
50
-
51
- # Ruby 1.8 and 1.9
52
- unless defined?(JRuby)
53
- describe "OCI data type conversions" do
54
- it "should translate PL/SQL VARCHAR to Ruby String" do
55
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: 100)).to eq [String, 100]
56
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: nil)).to eq [String, 32767]
57
- end
58
-
59
- it "should translate PL/SQL VARCHAR2 to Ruby String" do
60
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: 100)).to eq [String, 100]
61
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: nil)).to eq [String, 32767]
62
- end
63
-
64
- it "should translate PL/SQL CLOB to Ruby String" do
65
- expect(@conn.plsql_to_ruby_data_type(data_type: "CLOB", data_length: 100_000)).to eq [OCI8::CLOB, nil]
66
- expect(@conn.plsql_to_ruby_data_type(data_type: "CLOB", data_length: nil)).to eq [OCI8::CLOB, nil]
67
- end
68
-
69
- it "should translate PL/SQL NUMBER to Ruby OraNumber" do
70
- expect(@conn.plsql_to_ruby_data_type(data_type: "NUMBER", data_length: 15)).to eq [OraNumber, nil]
71
- end
72
-
73
- it "should translate PL/SQL DATE to Ruby DateTime" do
74
- expect(@conn.plsql_to_ruby_data_type(data_type: "DATE", data_length: nil)).to eq [DateTime, nil]
75
- end
76
-
77
- it "should translate PL/SQL TIMESTAMP to Ruby Time" do
78
- expect(@conn.plsql_to_ruby_data_type(data_type: "TIMESTAMP", data_length: nil)).to eq [Time, nil]
79
- end
80
-
81
- it "should not translate small Ruby Integer when OraNumber type specified" do
82
- expect(@conn.ruby_value_to_ora_value(100, OraNumber)).to eql(100)
83
- end
84
-
85
- it "should not translate big Ruby Integer when OraNumber type specified" do
86
- ora_number = @conn.ruby_value_to_ora_value(12345678901234567890, OraNumber)
87
- expect(ora_number).to be_an Integer
88
- expect(ora_number.to_s).to eq "12345678901234567890"
89
- # OraNumber has more numeric comparison methods in ruby-oci8 2.0
90
- expect(ora_number).to eq OraNumber.new("12345678901234567890") if OCI8::VERSION >= "2.0.0"
91
- end
92
-
93
- it "should translate Ruby String value to OCI8::CLOB when OCI8::CLOB type specified" do
94
- large_text = "x" * 100_000
95
- ora_value = @conn.ruby_value_to_ora_value(large_text, OCI8::CLOB)
96
- expect(ora_value.class).to eq OCI8::CLOB
97
- expect(ora_value.size).to eq 100_000
98
- ora_value.rewind
99
- expect(ora_value.read).to eq large_text
100
- end
101
-
102
- it "should translate Oracle OraNumber integer value to Integer" do
103
- expect(@conn.ora_value_to_ruby_value(OraNumber.new(100))).to eql(100)
104
- end
105
-
106
- it "should translate Oracle OraNumber float value to BigDecimal" do
107
- expect(@conn.ora_value_to_ruby_value(OraNumber.new(100.11))).to eql(BigDecimal("100.11"))
108
- end
109
-
110
- # ruby-oci8 2.0 returns DATE as Time or DateTime
111
- if OCI8::VERSION < "2.0.0"
112
- it "should translate Oracle OraDate value to Time" do
113
- now = OraDate.now
114
- expect(@conn.ora_value_to_ruby_value(now)).to eql(now.to_time)
115
- end
116
- end
117
-
118
- it "should translate Oracle CLOB value to String" do
119
- large_text = "x" * 100_000
120
- clob = OCI8::CLOB.new(@raw_conn, large_text)
121
- expect(@conn.ora_value_to_ruby_value(clob)).to eq large_text
122
- end
123
-
124
- end
125
-
126
- # JRuby
127
- else
128
-
129
- describe "JDBC data type conversions" do
130
- it "should translate PL/SQL VARCHAR to Ruby String" do
131
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: 100)).to eq [String, 100]
132
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR", data_length: nil)).to eq [String, 32767]
133
- end
134
- it "should translate PL/SQL VARCHAR2 to Ruby String" do
135
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: 100)).to eq [String, 100]
136
- expect(@conn.plsql_to_ruby_data_type(data_type: "VARCHAR2", data_length: nil)).to eq [String, 32767]
137
- end
138
-
139
- it "should translate PL/SQL NUMBER to Ruby BigDecimal" do
140
- expect(@conn.plsql_to_ruby_data_type(data_type: "NUMBER", data_length: 15)).to eq [BigDecimal, nil]
141
- end
142
-
143
- it "should translate PL/SQL DATE to Ruby DateTime" do
144
- expect(@conn.plsql_to_ruby_data_type(data_type: "DATE", data_length: nil)).to eq [DateTime, nil]
145
- end
146
-
147
- it "should translate PL/SQL TIMESTAMP to Ruby Time" do
148
- expect(@conn.plsql_to_ruby_data_type(data_type: "TIMESTAMP", data_length: nil)).to eq [Time, nil]
149
- end
150
-
151
- it "should not translate Ruby Integer when BigDecimal type specified" do
152
- expect(@conn.ruby_value_to_ora_value(100, BigDecimal)).to eq java.math.BigDecimal.new(100)
153
- end
154
-
155
- it "should translate Ruby String to string value" do
156
- expect(@conn.ruby_value_to_ora_value(1.1, String)).to eq "1.1"
157
- end
158
-
159
- it "should translate Ruby Integer value to BigDecimal when BigDecimal type specified" do
160
- big_decimal = @conn.ruby_value_to_ora_value(12345678901234567890, BigDecimal)
161
- expect(big_decimal).to eq java.math.BigDecimal.new("12345678901234567890")
162
- end
163
-
164
- it "should translate Ruby String value to Java::OracleSql::CLOB when Java::OracleSql::CLOB type specified" do
165
- large_text = "x" * 100_000
166
- ora_value = @conn.ruby_value_to_ora_value(large_text, Java::OracleSql::CLOB)
167
- expect(ora_value.class).to eq Java::OracleSql::CLOB
168
- expect(ora_value.length).to eq 100_000
169
- expect(ora_value.getSubString(1, ora_value.length)).to eq large_text
170
- ora_value.freeTemporary
171
- end
172
-
173
- it "should translate Ruby nil value to nil when Java::OracleSql::CLOB type specified" do
174
- ora_value = @conn.ruby_value_to_ora_value(nil, Java::OracleSql::CLOB)
175
- expect(ora_value).to be_nil
176
- end
177
-
178
- it "should translate Oracle BigDecimal integer value to Integer" do
179
- expect(@conn.ora_value_to_ruby_value(BigDecimal("100"))).to eql(100)
180
- end
181
-
182
- it "should translate Oracle BigDecimal float value to BigDecimal" do
183
- expect(@conn.ora_value_to_ruby_value(BigDecimal("100.11"))).to eql(BigDecimal("100.11"))
184
- end
185
-
186
- it "should translate Oracle CLOB value to String" do
187
- large_text = "āčē" * 100_000
188
- clob = @conn.ruby_value_to_ora_value(large_text, Java::OracleSql::CLOB)
189
- expect(@conn.ora_value_to_ruby_value(clob)).to eq large_text
190
- clob.freeTemporary
191
- end
192
-
193
- it "should translate empty Oracle CLOB value to nil" do
194
- clob = @conn.ruby_value_to_ora_value(nil, Java::OracleSql::CLOB)
195
- expect(@conn.ora_value_to_ruby_value(clob)).to be_nil
196
- end
197
-
198
- end
199
-
200
- end
201
-
202
- describe "SQL SELECT statements" do
203
-
204
- it "should execute SQL statement and return first result" do
205
- @now = Time.local(2008, 05, 31, 23, 22, 11)
206
- expect(@conn.select_first("SELECT 'abc',123,123.456,
207
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
208
- FROM dual")).to eq ["abc", 123, 123.456, @now]
209
- end
210
-
211
- it "should execute SQL statement and return first result as hash" do
212
- @now = Time.local(2008, 05, 31, 23, 22, 11)
213
- expect(@conn.select_hash_first("SELECT 'abc' a, 123 b, 123.456 c,
214
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}', 'YYYY-MM-DD HH24:MI:SS') d
215
- FROM dual")).to eq(a: "abc", b: 123, c: 123.456, d: @now)
216
- end
217
-
218
- it "should execute SQL statement with bind parameters and return first result" do
219
- @today = Date.parse("2008-05-31")
220
- @now = Time.local(2008, 05, 31, 23, 22, 11)
221
- expect(@conn.select_first("SELECT :1,:2,:3,:4,:5 FROM dual",
222
- "abc", 123, 123.456, @now, @today)).to eq ["abc", 123, 123.456, @now, Time.parse(@today.to_s)]
223
- end
224
-
225
- it "should execute SQL statement with NULL values and return first result" do
226
- @now = Time.local(2008, 05, 31, 23, 22, 11)
227
- expect(@conn.select_first("SELECT NULL,123,123.456,
228
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
229
- FROM dual")).to eq [nil, 123, 123.456, @now]
230
- end
231
-
232
- if defined?(JRuby)
233
-
234
- it "should execute SQL statement with NULL values as bind parameters and return first result" do
235
- @today = Date.parse("2008-05-31")
236
- @now = Time.local(2008, 05, 31, 23, 22, 11)
237
- expect(@conn.select_first("SELECT :1,:2,:3,:4,:5 FROM dual",
238
- nil, 123, 123.456, @now, @today)).to eq [nil, 123, 123.456, @now, Time.parse(@today.to_s)]
239
- end
240
-
241
- end
242
-
243
- it "should execute SQL statement and return all results" do
244
- @now = Time.local(2008, 05, 31, 23, 22, 11)
245
- expect(@conn.select_all("SELECT 'abc',123,123.456,
246
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
247
- FROM dual
248
- UNION ALL SELECT 'abc',123,123.456,
249
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
250
- FROM dual")).to eq [["abc", 123, 123.456, @now], ["abc", 123, 123.456, @now]]
251
- end
252
-
253
- it "should execute SQL statement and return all results as hash" do
254
- @now = Time.local(2008, 05, 31, 23, 22, 11)
255
- expect(@conn.select_hash_all("SELECT 'abc' a, 123 b, 123.456 c,
256
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS') d
257
- FROM dual
258
- UNION ALL SELECT 'def' a, 123 b, 123.456 c,
259
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS') d
260
- FROM dual")).to eq [{ a: "abc", b: 123, c: 123.456, d: @now }, { a: "def", b: 123, c: 123.456, d: @now }]
261
- end
262
-
263
- it "should execute SQL statement with bind parameters and return all results" do
264
- @now = Time.local(2008, 05, 31, 23, 22, 11)
265
- expect(@conn.select_all("SELECT :1,:2,:3,:4 FROM dual UNION ALL SELECT :1,:2,:3,:4 FROM dual",
266
- "abc", 123, 123.456, @now, "abc", 123, 123.456, @now)).to eq [["abc", 123, 123.456, @now], ["abc", 123, 123.456, @now]]
267
- end
268
-
269
- it "should execute SQL statement and yield all results in block" do
270
- @now = Time.local(2008, 05, 31, 23, 22, 11)
271
- expect(@conn.select_all("SELECT 'abc',123,123.456,
272
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
273
- FROM dual
274
- UNION ALL SELECT 'abc',123,123.456,
275
- TO_DATE('#{@now.strftime("%Y-%m-%d %H:%M:%S")}','YYYY-MM-DD HH24:MI:SS')
276
- FROM dual") do |r|
277
- expect(r).to eq ["abc", 123, 123.456, @now]
278
- end).to eq 2
279
- end
280
-
281
- it "should execute SQL statement with bind parameters and yield all results in block" do
282
- @now = Time.local(2008, 05, 31, 23, 22, 11)
283
- expect(@conn.select_all("SELECT :1,:2,:3,:4 FROM dual UNION ALL SELECT :1,:2,:3,:4 FROM dual",
284
- "abc", 123, 123.456, @now, "abc", 123, 123.456, @now) do |r|
285
- expect(r).to eq ["abc", 123, 123.456, @now]
286
- end).to eq 2
287
- end
288
-
289
- end
290
-
291
- describe "PL/SQL procedures" do
292
- before(:all) do
293
- @random = rand(1000)
294
- @now = Time.local(2008, 05, 31, 23, 22, 11)
295
- sql = <<-SQL
296
- CREATE OR REPLACE FUNCTION test_add_random (p_number NUMBER, p_varchar IN OUT VARCHAR2, p_date IN OUT DATE)
297
- RETURN NUMBER
298
- IS
299
- BEGIN
300
- RETURN p_number + #{@random};
301
- END test_add_random;
302
- SQL
303
- expect(@conn.exec(sql)).to be true
304
- end
305
-
306
- after(:all) do
307
- @conn.exec "DROP FUNCTION test_add_random"
308
- end
309
-
310
- it "should parse PL/SQL procedure call and bind parameters and exec and get bind parameter value" do
311
- sql = <<-SQL
312
- BEGIN
313
- :result := test_add_random (:p_number, :p_varchar, :p_date);
314
- END;
315
- SQL
316
- cursor = @conn.parse(sql)
317
- cursor.bind_param(":result", nil, data_type: "NUMBER", in_out: "OUT")
318
- cursor.bind_param(":p_number", 100, data_type: "NUMBER", in_out: "IN")
319
- cursor.bind_param(":p_varchar", "abc", data_type: "VARCHAR2", in_out: "IN/OUT")
320
- cursor.bind_param(":p_date", @now, data_type: "DATE", in_out: "IN/OUT")
321
- cursor.exec
322
- expect(cursor[":result"]).to eq @random + 100
323
- expect(cursor[":p_varchar"]).to eq "abc"
324
- expect(cursor[":p_date"]).to eq @now
325
- expect(cursor.close).to be_nil
326
- end
327
-
328
- end
329
-
330
- describe "commit and rollback" do
331
- before(:all) do
332
- expect(@conn.exec("CREATE TABLE test_commit (dummy VARCHAR2(100))")).to be true
333
- @conn.autocommit = false
334
- expect(@conn).not_to be_autocommit
335
- end
336
-
337
- after(:all) do
338
- @conn.exec "DROP TABLE test_commit"
339
- end
340
-
341
- after(:each) do
342
- @conn.exec "DELETE FROM test_commit"
343
- @conn.commit
344
- end
345
-
346
- it "should do commit" do
347
- @conn.exec("INSERT INTO test_commit VALUES ('test')")
348
- @conn.commit
349
- expect(@conn.select_first("SELECT COUNT(*) FROM test_commit")[0]).to eq 1
350
- end
351
-
352
- it "should do rollback" do
353
- @conn.exec("INSERT INTO test_commit VALUES ('test')")
354
- @conn.rollback
355
- expect(@conn.select_first("SELECT COUNT(*) FROM test_commit")[0]).to eq 0
356
- end
357
-
358
- it "should do commit and rollback should not undo commited transaction" do
359
- @conn.exec("INSERT INTO test_commit VALUES ('test')")
360
- @conn.commit
361
- @conn.rollback
362
- expect(@conn.select_first("SELECT COUNT(*) FROM test_commit")[0]).to eq 1
363
- end
364
-
365
- end
366
-
367
- describe "prefetch rows" do
368
- after(:each) do
369
- @conn.prefetch_rows = 1 # set back to default
370
- end
371
-
372
- it "should set prefetch rows for connection" do
373
- sql = "SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual"
374
- @conn.prefetch_rows = 2
375
- expect {
376
- @conn.cursor_from_query(sql)
377
- }.to raise_error(/divisor is equal to zero/)
378
- @conn.prefetch_rows = 1
379
- expect {
380
- @conn.cursor_from_query(sql)
381
- }.not_to raise_error
382
- end
383
-
384
- it "should fetch just one row when using select_first" do
385
- sql = "SELECT 1 FROM dual UNION ALL SELECT 1/0 FROM dual"
386
- @conn.prefetch_rows = 2
387
- expect {
388
- @conn.select_first(sql)
389
- }.not_to raise_error
390
- end
391
-
392
- end
393
-
394
- describe "describe synonym" do
395
- before(:all) do
396
- @conn.exec "CREATE SYNONYM hr.synonym_for_dual FOR sys.dual"
397
- end
398
-
399
- after(:all) do
400
- @conn.exec "DROP SYNONYM hr.synonym_for_dual"
401
- end
402
-
403
- it "should describe local synonym" do
404
- expect(@conn.describe_synonym("HR", "SYNONYM_FOR_DUAL")).to eq ["SYS", "DUAL"]
405
- expect(@conn.describe_synonym("hr", "synonym_for_dual")).to eq ["SYS", "DUAL"]
406
- expect(@conn.describe_synonym(:hr, :synonym_for_dual)).to eq ["SYS", "DUAL"]
407
- end
408
-
409
- it "should return nil on non-existing synonym" do
410
- expect(@conn.describe_synonym("HR", "SYNONYM_FOR_XXX")).to be_nil
411
- expect(@conn.describe_synonym("hr", "synonym_for_xxx")).to be_nil
412
- expect(@conn.describe_synonym(:hr, :synonym_for_xxx)).to be_nil
413
- end
414
-
415
- it "should describe public synonym" do
416
- expect(@conn.describe_synonym("PUBLIC", "DUAL")).to eq ["SYS", "DUAL"]
417
- expect(@conn.describe_synonym("PUBLIC", "dual")).to eq ["SYS", "DUAL"]
418
- expect(@conn.describe_synonym("PUBLIC", :dual)).to eq ["SYS", "DUAL"]
419
- end
420
-
421
- end
422
-
423
- describe "session information" do
424
- it "should get database version" do
425
- # using Oracle version 10.2.0.4 for unit tests
426
- expect(@conn.database_version).to eq DATABASE_VERSION.split(".").map { |n| n.to_i }
427
- end
428
-
429
- it "should get session ID" do
430
- expect(@conn.session_id).to eq @conn.select_first("SELECT USERENV('SESSIONID') FROM dual")[0].to_i
431
- end
432
- end
433
-
434
- describe "drop ruby temporary tables" do
435
- after(:all) do
436
- @conn.drop_all_ruby_temporary_tables
437
- end
438
-
439
- it "should drop all ruby temporary tables" do
440
- tmp_table = "ruby_111_222_333"
441
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
442
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
443
- @conn.drop_all_ruby_temporary_tables
444
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.to raise_error(/table or view does not exist/)
445
- end
446
-
447
- it "should drop current session ruby temporary tables" do
448
- tmp_table = "ruby_#{@conn.session_id}_222_333"
449
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
450
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
451
- @conn.drop_session_ruby_temporary_tables
452
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.to raise_error(/table or view does not exist/)
453
- end
454
-
455
- it "should not drop other session ruby temporary tables" do
456
- tmp_table = "ruby_#{@conn.session_id + 1}_222_333"
457
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
458
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
459
- @conn.drop_session_ruby_temporary_tables
460
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
461
- end
462
-
463
- end
464
-
465
- describe "logoff" do
466
- before(:each) do
467
- # restore connection before each test
468
- reconnect_connection
469
- end
470
-
471
- after(:all) do
472
- @conn.exec "DROP TABLE test_dummy_table" rescue nil
473
- end
474
-
475
- def reconnect_connection
476
- @raw_conn = get_connection
477
- @conn = PLSQL::Connection.create(@raw_conn)
478
- end
479
-
480
- it "should drop current session ruby temporary tables" do
481
- tmp_table = "ruby_#{@conn.session_id}_222_333"
482
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
483
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.not_to raise_error
484
- @conn.logoff
485
- reconnect_connection
486
- expect { @conn.select_first("SELECT * FROM #{tmp_table}") }.to raise_error(/table or view does not exist/)
487
- end
488
-
489
- it "should rollback any uncommited transactions" do
490
- tmp_table = "ruby_#{@conn.session_id}_222_333"
491
- old_autocommit = @conn.autocommit?
492
- @conn.autocommit = false
493
- @conn.exec "CREATE GLOBAL TEMPORARY TABLE #{tmp_table} (dummy CHAR(1))"
494
- @conn.exec "CREATE TABLE test_dummy_table (dummy CHAR(1))"
495
- @conn.exec "INSERT INTO test_dummy_table VALUES ('1')"
496
- # logoff will drop ruby temporary tables, it should do rollback before drop table
497
- @conn.logoff
498
- reconnect_connection
499
- expect(@conn.select_first("SELECT * FROM test_dummy_table")).to eq nil
500
- @conn.autocommit = old_autocommit
501
- end
502
-
503
- end
504
-
505
- end
@@ -1,172 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe "Package" do
4
- before(:all) do
5
- plsql.connection = get_connection
6
- plsql.execute <<-SQL
7
- CREATE OR REPLACE PACKAGE test_package IS
8
- test_variable NUMBER;
9
- FUNCTION test_procedure ( p_string VARCHAR2 )
10
- RETURN VARCHAR2;
11
- END;
12
- SQL
13
- plsql.execute <<-SQL
14
- CREATE OR REPLACE PACKAGE BODY test_package IS
15
- FUNCTION test_procedure ( p_string VARCHAR2 )
16
- RETURN VARCHAR2
17
- IS
18
- BEGIN
19
- RETURN UPPER(p_string);
20
- END test_procedure;
21
- END;
22
- SQL
23
- end
24
-
25
- after(:all) do
26
- plsql.execute "DROP PACKAGE test_package"
27
- plsql.logoff
28
- end
29
-
30
- before(:each) do
31
- end
32
-
33
- it "should find existing package" do
34
- expect(PLSQL::Package.find(plsql, :test_package)).not_to be_nil
35
- end
36
-
37
- it "should not find nonexisting package" do
38
- expect(PLSQL::Package.find(plsql, :qwerty123456)).to be_nil
39
- end
40
-
41
- it "should find existing package in schema" do
42
- expect(plsql.test_package.class).to eq(PLSQL::Package)
43
- end
44
-
45
- it "should execute package function and return correct value" do
46
- expect(plsql.test_package.test_procedure("xxx")).to eq("XXX")
47
- end
48
-
49
- it "should report an existing procedure as existing" do
50
- expect(plsql.test_package.procedure_defined?(:test_procedure)).to be_truthy
51
- end
52
-
53
- it "should report an inexistent procedure as not existing" do
54
- expect(plsql.test_package.procedure_defined?(:inexistent_procedure)).to be_falsey
55
- end
56
-
57
- it "should search objects via []" do
58
- package = PLSQL::Package.find(plsql, :test_package)
59
-
60
- [:Test_Procedure, :test_procedure, "test_procedure", "TEST_PROCEDURE"].each do |name_variant|
61
- expect(package[name_variant]).to be_a PLSQL::Procedure
62
- end
63
-
64
- [:Test_Variable, :test_variable, "test_variable", "TEST_VARIABLE"].each do |name_variant|
65
- expect(package[name_variant]).to be_a PLSQL::Variable
66
- end
67
- end
68
-
69
- context "with a user with execute privilege who is not the package owner" do
70
- before(:all) do
71
- plsql.execute("grant execute on TEST_PACKAGE to #{DATABASE_USERS_AND_PASSWORDS[1][0]}")
72
- @original_connection = plsql.connection
73
- @conn = get_connection(1)
74
- end
75
-
76
- before(:each) do
77
- # resetting connection clears cached package objects and schema name
78
- plsql.connection = @conn
79
- end
80
-
81
- after(:all) do
82
- plsql.logoff
83
- plsql.connection = @original_connection
84
- end
85
-
86
- it "should not find existing package" do
87
- expect(PLSQL::Package.find(plsql, :test_package)).to be_nil
88
- end
89
-
90
- context "who sets current_schema to match the package owner" do
91
- before(:all) do
92
- plsql.execute "ALTER SESSION set current_schema=#{DATABASE_USERS_AND_PASSWORDS[0][0]}"
93
- end
94
-
95
- it "should find existing package" do
96
- expect(PLSQL::Package.find(plsql, :test_package)).not_to be_nil
97
- end
98
-
99
- it "should report an existing procedure as existing" do
100
- expect(plsql.test_package.procedure_defined?(:test_procedure)).to be_truthy
101
- end
102
-
103
- end
104
-
105
- end
106
-
107
- describe "variables" do
108
- it "should set and get package variable value" do
109
- plsql.test_package.test_variable = 1
110
- expect(plsql.test_package.test_variable).to eq(1)
111
- end
112
- end
113
-
114
- end
115
-
116
- describe "Synonym to package" do
117
-
118
- before(:all) do
119
- plsql.connection = get_connection
120
- plsql.execute <<-SQL
121
- CREATE OR REPLACE PACKAGE hr.test_package IS
122
- FUNCTION test_procedure ( p_string VARCHAR2 )
123
- RETURN VARCHAR2;
124
- END;
125
- SQL
126
- plsql.execute <<-SQL
127
- CREATE OR REPLACE PACKAGE BODY hr.test_package IS
128
- FUNCTION test_procedure ( p_string VARCHAR2 )
129
- RETURN VARCHAR2
130
- IS
131
- BEGIN
132
- RETURN UPPER(p_string);
133
- END test_procedure;
134
- END;
135
- SQL
136
- plsql.execute "CREATE SYNONYM test_pkg_synonym FOR hr.test_package"
137
- end
138
-
139
- after(:all) do
140
- plsql.execute "DROP SYNONYM test_pkg_synonym" rescue nil
141
- plsql.logoff
142
- end
143
-
144
- it "should find synonym to package" do
145
- expect(PLSQL::Package.find(plsql, :test_pkg_synonym)).not_to be_nil
146
- end
147
-
148
- it "should execute package function using synonym and return correct value" do
149
- expect(plsql.test_pkg_synonym.test_procedure("xxx")).to eq("XXX")
150
- end
151
-
152
- end
153
-
154
- describe "Public synonym to package" do
155
-
156
- before(:all) do
157
- plsql.connection = get_connection
158
- end
159
-
160
- after(:all) do
161
- plsql.logoff
162
- end
163
-
164
- it "should find public synonym to package" do
165
- expect(PLSQL::Package.find(plsql, :utl_encode)).not_to be_nil
166
- end
167
-
168
- it "should execute package function using public synonym and return correct value" do
169
- expect(plsql.utl_encode.base64_encode("abc")).to eq("4372773D")
170
- end
171
-
172
- end