ruby-plsql 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -82,6 +82,9 @@ module PLSQL
82
82
  }
83
83
  end
84
84
  end
85
+ # if procedure is without arguments then create default empty argument list for default overload
86
+ @arguments[0] = {} if @arguments.keys.empty?
87
+
85
88
  @overloads = @arguments.keys.sort
86
89
  @overloads.each do |overload|
87
90
  @argument_list[overload] = @arguments[overload].keys.sort {|k1, k2| @arguments[overload][k1][:position] <=> @arguments[overload][k2][:position]}
data/lib/ruby_plsql.rb CHANGED
@@ -20,7 +20,7 @@ else
20
20
  java.lang.Thread.currentThread.setContextClassLoader(JRuby.runtime.jruby_class_loader)
21
21
 
22
22
  ojdbc_jar = "ojdbc14.jar"
23
- if ojdbc_jar_path = ENV["PATH"].split(":").find{|d| File.exists?(File.join(d,ojdbc_jar))}
23
+ if ojdbc_jar_path = ENV["PATH"].split(/[:;]/).find{|d| File.exists?(File.join(d,ojdbc_jar))}
24
24
  require File.join(ojdbc_jar_path,ojdbc_jar)
25
25
  else
26
26
  require ojdbc_jar
@@ -42,6 +42,6 @@ require "time"
42
42
  require "date"
43
43
  require "bigdecimal"
44
44
 
45
- %w(connection schema procedure package).each do |file|
45
+ %w(connection oci_connection jdbc_connection schema procedure package).each do |file|
46
46
  require File.dirname(__FILE__) + "/plsql/#{file}"
47
47
  end
@@ -2,7 +2,7 @@ module RubyPlsql #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -355,7 +355,7 @@ describe "Function with output parameters" do
355
355
 
356
356
  end
357
357
 
358
- describe "Function without parameters" do
358
+ describe "Function or procedure without parameters" do
359
359
  before(:all) do
360
360
  plsql.connection = get_connection
361
361
  plsql.connection.exec <<-EOS
@@ -366,13 +366,112 @@ describe "Function without parameters" do
366
366
  RETURN 'dummy';
367
367
  END test_no_params;
368
368
  EOS
369
+ plsql.connection.exec <<-EOS
370
+ CREATE OR REPLACE PROCEDURE test_proc_no_params
371
+ IS
372
+ BEGIN
373
+ NULL;
374
+ END test_proc_no_params;
375
+ EOS
369
376
  end
370
377
 
371
378
  after(:all) do
372
379
  plsql.logoff
373
380
  end
374
381
 
375
- it "should return value" do
382
+ it "should find function" do
383
+ PLSQL::Procedure.find(plsql, :test_no_params).should_not be_nil
384
+ end
385
+
386
+ it "should return function value" do
376
387
  plsql.test_no_params.should == "dummy"
377
388
  end
378
- end
389
+
390
+ it "should find procedure" do
391
+ PLSQL::Procedure.find(plsql, :test_proc_no_params).should_not be_nil
392
+ end
393
+
394
+ it "should execute procedure" do
395
+ plsql.test_proc_no_params.should be_nil
396
+ end
397
+
398
+ end
399
+
400
+ describe "Function with CLOB parameter and return value" do
401
+
402
+ before(:all) do
403
+ plsql.connection = get_connection
404
+ plsql.connection.exec <<-EOS
405
+ CREATE OR REPLACE FUNCTION test_clob
406
+ ( p_clob CLOB )
407
+ RETURN CLOB
408
+ IS
409
+ BEGIN
410
+ RETURN p_clob;
411
+ END test_clob;
412
+ EOS
413
+ end
414
+
415
+ after(:all) do
416
+ plsql.logoff
417
+ end
418
+
419
+ it "should find existing procedure" do
420
+ PLSQL::Procedure.find(plsql, :test_clob).should_not be_nil
421
+ end
422
+
423
+ it "should execute function and return correct value" do
424
+ large_text = 'ābčdēfghij' * 10_000
425
+ plsql.test_clob(large_text).should == large_text
426
+ end
427
+
428
+ unless defined?(JRUBY_VERSION)
429
+
430
+ it "should execute function with empty string and return nil (oci8 cannot pass empty CLOB parameter)" do
431
+ text = ''
432
+ plsql.test_clob(text).should be_nil
433
+ end
434
+
435
+ else
436
+
437
+ it "should execute function with empty string and return empty string" do
438
+ text = ''
439
+ plsql.test_clob(text).should == text
440
+ end
441
+
442
+ end
443
+
444
+ it "should execute function with nil and return nil" do
445
+ plsql.test_clob(nil).should be_nil
446
+ end
447
+
448
+ end
449
+
450
+ describe "Procedrue with CLOB parameter and return value" do
451
+
452
+ before(:all) do
453
+ plsql.connection = get_connection
454
+ plsql.connection.exec <<-EOS
455
+ CREATE OR REPLACE PROCEDURE test_clob_proc
456
+ ( p_clob CLOB,
457
+ p_return OUT CLOB)
458
+ IS
459
+ BEGIN
460
+ p_return := p_clob;
461
+ END test_clob_proc;
462
+ EOS
463
+ end
464
+
465
+ after(:all) do
466
+ plsql.logoff
467
+ end
468
+
469
+ it "should find existing procedure" do
470
+ PLSQL::Procedure.find(plsql, :test_clob_proc).should_not be_nil
471
+ end
472
+
473
+ it "should execute function and return correct value" do
474
+ large_text = 'ābčdēfghij' * 10_000
475
+ plsql.test_clob_proc(large_text)[:p_return].should == large_text
476
+ end
477
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,8 +10,20 @@ require File.expand_path(File.dirname(__FILE__) + "/../lib/ruby_plsql")
10
10
 
11
11
  def get_connection
12
12
  unless defined?(JRUBY_VERSION)
13
- OCI8.new("hr","hr","xe")
13
+ begin
14
+ OCI8.new("hr","hr","xe")
15
+ # if connection fails then sleep 5 seconds and retry
16
+ rescue OCIError
17
+ sleep 5
18
+ OCI8.new("hr","hr","xe")
19
+ end
14
20
  else
15
- DriverManager.getConnection("jdbc:oracle:thin:@ubuntu710:1521:XE","hr","hr")
21
+ begin
22
+ DriverManager.getConnection("jdbc:oracle:thin:@ubuntu710:1521:XE","hr","hr")
23
+ # if connection fails then sleep 5 seconds and retry
24
+ rescue NativeException
25
+ sleep 5
26
+ DriverManager.getConnection("jdbc:oracle:thin:@ubuntu710:1521:XE","hr","hr")
27
+ end
16
28
  end
17
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-plsql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-20 00:00:00 +03:00
12
+ date: 2008-10-17 00:00:00 +03:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.7.0
24
+ version:
16
25
  description: ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures.
17
26
  email:
18
27
  - raymonds72@gmail.com
@@ -23,43 +32,25 @@ extensions: []
23
32
  extra_rdoc_files:
24
33
  - History.txt
25
34
  - License.txt
26
- - Manifest.txt
27
35
  - README.txt
28
- - website/index.txt
29
36
  files:
30
37
  - History.txt
31
38
  - License.txt
32
- - Manifest.txt
33
39
  - README.txt
34
- - Rakefile
35
- - config/hoe.rb
36
- - config/requirements.rb
37
40
  - lib/oradate_patch.rb
38
41
  - lib/plsql/connection.rb
42
+ - lib/plsql/jdbc_connection.rb
43
+ - lib/plsql/oci_connection.rb
39
44
  - lib/plsql/package.rb
40
45
  - lib/plsql/procedure.rb
41
46
  - lib/plsql/schema.rb
42
47
  - lib/ruby_plsql.rb
43
48
  - lib/ruby_plsql/version.rb
44
- - log/debug.log
45
- - script/destroy
46
- - script/generate
47
- - script/txt2html
48
- - setup.rb
49
49
  - spec/plsql/package_spec.rb
50
50
  - spec/plsql/procedure_spec.rb
51
51
  - spec/plsql/schema_spec.rb
52
52
  - spec/spec.opts
53
53
  - spec/spec_helper.rb
54
- - tasks/deployment.rake
55
- - tasks/environment.rake
56
- - tasks/rspec.rake
57
- - tasks/website.rake
58
- - website/index.html
59
- - website/index.txt
60
- - website/javascripts/rounded_corners_lite.inc.js
61
- - website/stylesheets/screen.css
62
- - website/template.rhtml
63
54
  has_rdoc: true
64
55
  homepage: http://ruby-plsql.rubyforge.org
65
56
  post_install_message:
data/Manifest.txt DELETED
@@ -1,33 +0,0 @@
1
- History.txt
2
- License.txt
3
- Manifest.txt
4
- README.txt
5
- Rakefile
6
- config/hoe.rb
7
- config/requirements.rb
8
- lib/oradate_patch.rb
9
- lib/plsql/connection.rb
10
- lib/plsql/package.rb
11
- lib/plsql/procedure.rb
12
- lib/plsql/schema.rb
13
- lib/ruby_plsql.rb
14
- lib/ruby_plsql/version.rb
15
- log/debug.log
16
- script/destroy
17
- script/generate
18
- script/txt2html
19
- setup.rb
20
- spec/plsql/package_spec.rb
21
- spec/plsql/procedure_spec.rb
22
- spec/plsql/schema_spec.rb
23
- spec/spec.opts
24
- spec/spec_helper.rb
25
- tasks/deployment.rake
26
- tasks/environment.rake
27
- tasks/rspec.rake
28
- tasks/website.rake
29
- website/index.html
30
- website/index.txt
31
- website/javascripts/rounded_corners_lite.inc.js
32
- website/stylesheets/screen.css
33
- website/template.rhtml
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- require 'config/requirements'
2
- require 'config/hoe' # setup Hoe + all gem configuration
3
-
4
- Dir['tasks/**/*.rake'].each { |rake| load rake }
data/config/hoe.rb DELETED
@@ -1,70 +0,0 @@
1
- require 'ruby_plsql/version'
2
-
3
- AUTHOR = 'Raimonds Simanovskis' # can also be an array of Authors
4
- EMAIL = "raymonds72@gmail.com"
5
- DESCRIPTION = "ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures."
6
- GEM_NAME = 'ruby-plsql' # what ppl will type to install your gem
7
- RUBYFORGE_PROJECT = 'ruby-plsql' # The unix name for your project
8
- HOMEPATH = "http://#{RUBYFORGE_PROJECT}.rubyforge.org"
9
- DOWNLOAD_PATH = "http://rubyforge.org/projects/#{RUBYFORGE_PROJECT}"
10
-
11
- @config_file = "~/.rubyforge/user-config.yml"
12
- @config = nil
13
- RUBYFORGE_USERNAME = "unknown"
14
- def rubyforge_username
15
- unless @config
16
- begin
17
- @config = YAML.load(File.read(File.expand_path(@config_file)))
18
- rescue
19
- puts <<-EOS
20
- ERROR: No rubyforge config file found: #{@config_file}
21
- Run 'rubyforge setup' to prepare your env for access to Rubyforge
22
- - See http://newgem.rubyforge.org/rubyforge.html for more details
23
- EOS
24
- exit
25
- end
26
- end
27
- RUBYFORGE_USERNAME.replace @config["username"]
28
- end
29
-
30
-
31
- REV = nil
32
- # UNCOMMENT IF REQUIRED:
33
- # REV = `svn info`.each {|line| if line =~ /^Revision:/ then k,v = line.split(': '); break v.chomp; else next; end} rescue nil
34
- VERS = RubyPlsql::VERSION::STRING + (REV ? ".#{REV}" : "")
35
- RDOC_OPTS = ['--quiet', '--title', 'ruby_plsql documentation',
36
- "--opname", "index.html",
37
- "--line-numbers",
38
- "--main", "README",
39
- "--inline-source"]
40
-
41
- class Hoe
42
- def extra_deps
43
- @extra_deps.reject! { |x| Array(x).first == 'hoe' }
44
- @extra_deps
45
- end
46
- end
47
-
48
- # Generate all the Rake tasks
49
- # Run 'rake -T' to see list of generated tasks (from gem root directory)
50
- hoe = Hoe.new(GEM_NAME, VERS) do |p|
51
- p.developer(AUTHOR, EMAIL)
52
- p.description = DESCRIPTION
53
- p.summary = DESCRIPTION
54
- p.url = HOMEPATH
55
- p.rubyforge_name = RUBYFORGE_PROJECT if RUBYFORGE_PROJECT
56
- p.test_globs = ["test/**/test_*.rb"]
57
- p.clean_globs |= ['**/.*.sw?', '*.gem', '.config', '**/.DS_Store'] #An array of file patterns to delete on clean.
58
-
59
- # == Optional
60
- p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
61
- #p.extra_deps = [] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
62
-
63
- #p.spec_extras = {} # A hash of extra values to set in the gemspec.
64
-
65
- end
66
-
67
- CHANGES = hoe.paragraphs_of('History.txt', 0..1).join("\\n\\n")
68
- PATH = (RUBYFORGE_PROJECT == GEM_NAME) ? RUBYFORGE_PROJECT : "#{RUBYFORGE_PROJECT}/#{GEM_NAME}"
69
- hoe.remote_rdoc_dir = File.join(PATH.gsub(/^#{RUBYFORGE_PROJECT}\/?/,''), 'rdoc')
70
- hoe.rsync_args = '-av --delete --ignore-errors'
@@ -1,17 +0,0 @@
1
- require 'fileutils'
2
- include FileUtils
3
-
4
- require 'rubygems'
5
- %w[rake hoe newgem rubigen].each do |req_gem|
6
- begin
7
- require req_gem
8
- rescue LoadError
9
- puts "This Rakefile requires the '#{req_gem}' RubyGem."
10
- puts "Installation: gem install #{req_gem} -y"
11
- exit
12
- end
13
- end
14
-
15
- $:.unshift(File.join(File.dirname(__FILE__), %w[.. lib]))
16
-
17
- require 'ruby_plsql'
data/log/debug.log DELETED
File without changes
data/script/destroy DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/destroy'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate DELETED
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
- APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
-
4
- begin
5
- require 'rubigen'
6
- rescue LoadError
7
- require 'rubygems'
8
- require 'rubigen'
9
- end
10
- require 'rubigen/scripts/generate'
11
-
12
- ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
- RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
- RubiGen::Scripts::Generate.new.run(ARGV)
data/script/txt2html DELETED
@@ -1,74 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'rubygems'
4
- begin
5
- require 'newgem'
6
- rescue LoadError
7
- puts "\n\nGenerating the website requires the newgem RubyGem"
8
- puts "Install: gem install newgem\n\n"
9
- exit(1)
10
- end
11
- require 'redcloth'
12
- require 'syntax/convertors/html'
13
- require 'erb'
14
- require File.dirname(__FILE__) + '/../lib/ruby_plsql/version.rb'
15
-
16
- version = RubyPlsql::VERSION::STRING
17
- download = 'http://rubyforge.org/projects/ruby-plsql'
18
-
19
- class Fixnum
20
- def ordinal
21
- # teens
22
- return 'th' if (10..19).include?(self % 100)
23
- # others
24
- case self % 10
25
- when 1: return 'st'
26
- when 2: return 'nd'
27
- when 3: return 'rd'
28
- else return 'th'
29
- end
30
- end
31
- end
32
-
33
- class Time
34
- def pretty
35
- return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
36
- end
37
- end
38
-
39
- def convert_syntax(syntax, source)
40
- return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
41
- end
42
-
43
- if ARGV.length >= 1
44
- src, template = ARGV
45
- template ||= File.join(File.dirname(__FILE__), '/../website/template.rhtml')
46
-
47
- else
48
- puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
49
- exit!
50
- end
51
-
52
- template = ERB.new(File.open(template).read)
53
-
54
- title = nil
55
- body = nil
56
- File.open(src) do |fsrc|
57
- title_text = fsrc.readline
58
- body_text = fsrc.read
59
- syntax_items = []
60
- body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</\1>!m){
61
- ident = syntax_items.length
62
- element, syntax, source = $1, $2, $3
63
- syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
64
- "syntax-temp-#{ident}"
65
- }
66
- title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
67
- body = RedCloth.new(body_text).to_html
68
- body.gsub!(%r!(?:<pre><code>)?syntax-temp-(\d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
69
- end
70
- stat = File.stat(src)
71
- created = stat.ctime
72
- modified = stat.mtime
73
-
74
- $stdout << template.result(binding)