ruby-plsql 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,9 @@
1
+ # encoding: utf-8
2
+
1
3
  require File.dirname(__FILE__) + '/../spec_helper'
2
4
 
3
5
  require "rubygems"
4
- require "activerecord"
6
+ # require "activerecord"
5
7
 
6
8
  describe "Function with string parameters" do
7
9
 
@@ -83,12 +85,12 @@ describe "Function with numeric parameters" do
83
85
  plsql.test_sum(123123123123,456456456456).should == 579579579579
84
86
  end
85
87
 
86
- it "should process float parameters" do
87
- plsql.test_sum(123.123,456.456).should == 579.579
88
+ it "should process float parameters and return BigDecimal" do
89
+ plsql.test_sum(123.123,456.456).should == BigDecimal("579.579")
88
90
  end
89
91
 
90
- it "should process BigDecimal parameters" do
91
- plsql.test_sum(:p_num1 => BigDecimal.new("123.123"), :p_num2 => BigDecimal.new("456.456")).should == 579.579
92
+ it "should process BigDecimal parameters and return BigDecimal" do
93
+ plsql.test_sum(:p_num1 => BigDecimal("123.123"), :p_num2 => BigDecimal("456.456")).should == BigDecimal("579.579")
92
94
  end
93
95
 
94
96
  it "should process nil parameter as NULL" do
@@ -112,6 +114,10 @@ describe "Function with date parameters" do
112
114
  EOS
113
115
  end
114
116
 
117
+ before(:each) do
118
+ plsql.default_timezone = :local
119
+ end
120
+
115
121
  after(:all) do
116
122
  plsql.logoff
117
123
  end
@@ -121,6 +127,12 @@ describe "Function with date parameters" do
121
127
  plsql.test_date(now).should == now + 60*60*24
122
128
  end
123
129
 
130
+ it "should process UTC Time parameters" do
131
+ plsql.default_timezone = :utc
132
+ now = Time.utc(2008,8,12,14,28,0)
133
+ plsql.test_date(now).should == now + 60*60*24
134
+ end
135
+
124
136
  it "should process DateTime parameters" do
125
137
  now = DateTime.parse(Time.local(2008,8,12,14,28,0).iso8601)
126
138
  result = plsql.test_date(now)
@@ -129,7 +141,7 @@ describe "Function with date parameters" do
129
141
  end
130
142
 
131
143
  it "should process old DateTime parameters" do
132
- now = DateTime.new(1901,1,1,12,0,0)
144
+ now = DateTime.civil(1901,1,1,12,0,0,plsql.local_timezone_offset)
133
145
  result = plsql.test_date(now)
134
146
  unless defined?(JRUBY_VERSION)
135
147
  result.class.should == DateTime
@@ -151,8 +163,8 @@ describe "Function with date parameters" do
151
163
  now = Date.new(1901,1,1)
152
164
  result = plsql.test_date(now)
153
165
  unless defined?(JRUBY_VERSION)
154
- # result.class.should == DateTime
155
- result.should == now + 1
166
+ result.class.should == DateTime
167
+ result.strftime("%c").should == (now + 1).strftime("%c")
156
168
  else
157
169
  result.class.should == Time
158
170
  result.should == Time.parse((now + 1).strftime("%c"))
@@ -475,3 +487,101 @@ describe "Procedrue with CLOB parameter and return value" do
475
487
  plsql.test_clob_proc(large_text)[:p_return].should == large_text
476
488
  end
477
489
  end
490
+
491
+ describe "Procedrue with BLOB parameter and return value" do
492
+
493
+ before(:all) do
494
+ plsql.connection = get_connection
495
+ plsql.connection.exec <<-EOS
496
+ CREATE OR REPLACE PROCEDURE test_blob_proc
497
+ ( p_blob BLOB,
498
+ p_return OUT BLOB)
499
+ IS
500
+ BEGIN
501
+ p_return := p_blob;
502
+ END test_blob_proc;
503
+ EOS
504
+ end
505
+
506
+ after(:all) do
507
+ plsql.logoff
508
+ end
509
+
510
+ it "should find existing procedure" do
511
+ PLSQL::Procedure.find(plsql, :test_blob_proc).should_not be_nil
512
+ end
513
+
514
+ it "should execute function and return correct value" do
515
+ large_binary = '\000\001\002\003\004\005\006\007\010\011' * 10_000
516
+ plsql.test_blob_proc(large_binary)[:p_return].should == large_binary
517
+ end
518
+ end
519
+
520
+ describe "Synonym to function" do
521
+
522
+ before(:all) do
523
+ plsql.connection = get_connection
524
+ plsql.connection.exec <<-EOS
525
+ CREATE OR REPLACE FUNCTION hr.test_uppercase
526
+ ( p_string VARCHAR2 )
527
+ RETURN VARCHAR2
528
+ IS
529
+ BEGIN
530
+ RETURN UPPER(p_string);
531
+ END test_uppercase;
532
+ EOS
533
+ plsql.connection.exec "CREATE SYNONYM test_synonym FOR hr.test_uppercase"
534
+ end
535
+
536
+ after(:all) do
537
+ plsql.connection.exec "DROP SYNONYM test_synonym" rescue nil
538
+ plsql.logoff
539
+ end
540
+
541
+ it "should find synonym to function" do
542
+ PLSQL::Procedure.find(plsql, :test_synonym).should_not be_nil
543
+ end
544
+
545
+ it "should execute function using synonym and return correct value" do
546
+ plsql.test_synonym('xxx').should == 'XXX'
547
+ end
548
+
549
+ end
550
+
551
+ describe "Public synonym to function" do
552
+
553
+ before(:all) do
554
+ plsql.connection = get_connection
555
+ plsql.connection.exec <<-EOS
556
+ CREATE OR REPLACE FUNCTION hr.test_ora_login_user
557
+ RETURN VARCHAR2
558
+ IS
559
+ BEGIN
560
+ RETURN 'XXX';
561
+ END test_ora_login_user;
562
+ EOS
563
+ end
564
+
565
+ after(:all) do
566
+ plsql.logoff
567
+ end
568
+
569
+ it "should find public synonym to function" do
570
+ PLSQL::Procedure.find(plsql, :ora_login_user).should_not be_nil
571
+ end
572
+
573
+ it "should execute function using public synonym and return correct value" do
574
+ plsql.ora_login_user.should == 'HR'
575
+ end
576
+
577
+ it "should find private synonym before public synonym" do
578
+ # should reconnect to force clearing of procedure cache
579
+ plsql.connection = get_connection
580
+ plsql.connection.exec "CREATE SYNONYM ora_login_user FOR hr.test_ora_login_user"
581
+ plsql.ora_login_user.should == 'XXX'
582
+ plsql.connection.exec "DROP SYNONYM ora_login_user"
583
+ plsql.connection = get_connection
584
+ plsql.ora_login_user.should == 'HR'
585
+ end
586
+
587
+ end
@@ -86,4 +86,32 @@ describe "Schema commit and rollback" do
86
86
  it "should do rollback" do
87
87
  plsql.rollback
88
88
  end
89
+ end
90
+
91
+ describe "ActiveRecord connection" do
92
+ before(:all) do
93
+ ActiveRecord::Base.establish_connection(CONNECTION_PARAMS)
94
+ end
95
+
96
+ before(:each) do
97
+ plsql.activerecord_class = ActiveRecord::Base
98
+ end
99
+
100
+ it "should connect to test database" do
101
+ unless defined?(JRUBY_VERSION)
102
+ plsql.connection.is_a?(PLSQL::OCIConnection).should be_true
103
+ else
104
+ plsql.connection.is_a?(PLSQL::JDBCConnection).should be_true
105
+ end
106
+ end
107
+
108
+ it "should return schema name" do
109
+ plsql.schema_name.should == 'HR'
110
+ end
111
+
112
+ it "should user ActiveRecord::Base.default_timezone as default" do
113
+ ActiveRecord::Base.default_timezone = :utc
114
+ plsql.default_timezone.should == :utc
115
+ end
116
+
89
117
  end
@@ -1,29 +1,46 @@
1
- begin
2
- require 'spec'
3
- rescue LoadError
4
- require 'rubygems'
5
- gem 'rspec'
6
- require 'spec'
7
- end
1
+ require "rubygems"
2
+ gem "rspec"
3
+ require "spec"
4
+
5
+ gem "activerecord"
6
+ require "activerecord"
7
+ gem "activerecord-oracle_enhanced-adapter"
8
8
 
9
9
  require File.expand_path(File.dirname(__FILE__) + "/../lib/ruby_plsql")
10
10
 
11
+ DATABASE_NAME = ENV['DATABASE_NAME'] || 'orcl'
12
+ DATABASE_HOST = ENV['DATABASE_HOST'] || 'localhost'
13
+ DATABASE_PORT = ENV['DATABASE_PORT'] || 1521
14
+ DATABASE_USER = ENV['DATABASE_USER'] || 'hr'
15
+ DATABASE_PASSWORD = ENV['DATABASE_PASSWORD'] || 'hr'
16
+
11
17
  def get_connection
12
18
  unless defined?(JRUBY_VERSION)
13
19
  begin
14
- OCI8.new("hr","hr","xe")
20
+ OCI8.new(DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME)
15
21
  # if connection fails then sleep 5 seconds and retry
16
22
  rescue OCIError
17
23
  sleep 5
18
- OCI8.new("hr","hr","xe")
24
+ OCI8.new(DATABASE_USER,DATABASE_PASSWORD,DATABASE_NAME)
19
25
  end
20
26
  else
21
27
  begin
22
- DriverManager.getConnection("jdbc:oracle:thin:@ubuntu810:1521:XE","hr","hr")
28
+ java.sql.DriverManager.getConnection("jdbc:oracle:thin:@#{DATABASE_HOST}:#{DATABASE_PORT}:#{DATABASE_NAME}",
29
+ DATABASE_USER,DATABASE_PASSWORD)
23
30
  # if connection fails then sleep 5 seconds and retry
24
31
  rescue NativeException
25
32
  sleep 5
26
- DriverManager.getConnection("jdbc:oracle:thin:@ubuntu810:1521:XE","hr","hr")
33
+ java.sql.DriverManager.getConnection("jdbc:oracle:thin:@#{DATABASE_HOST}:#{DATABASE_PORT}:#{DATABASE_NAME}",
34
+ DATABASE_USER,DATABASE_PASSWORD)
27
35
  end
28
36
  end
29
- end
37
+ end
38
+
39
+ CONNECTION_PARAMS = {
40
+ :adapter => "oracle_enhanced",
41
+ :database => DATABASE_NAME,
42
+ :host => DATABASE_HOST,
43
+ :port => DATABASE_PORT,
44
+ :username => DATABASE_USER,
45
+ :password => DATABASE_PASSWORD
46
+ }
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.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raimonds Simanovskis
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-06 00:00:00 +02:00
12
+ date: 2009-04-21 00:00:00 +03:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: newgem
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.3.0
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: hoe
17
27
  type: :development
@@ -20,11 +30,11 @@ dependencies:
20
30
  requirements:
21
31
  - - ">="
22
32
  - !ruby/object:Gem::Version
23
- version: 1.8.2
33
+ version: 1.8.0
24
34
  version:
25
- description: ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures.
35
+ description: ruby-plsql gem provides simple Ruby API for calling Oracle PL/SQL procedures. ruby-plsql support both Ruby 1.8 MRI, Ruby 1.9.1 YARV and JRuby runtime environments. This gem requires ruby-oci8 library version 1.x (if MRI is used) or 2.x (if Ruby 1.9.1 is used) or Oracle JDBC driver (ojdbc14.jar) (if JRuby is used) for connection to Oracle database. See http://blog.rayapps.com for more information. Look ar RSpec tests under spec directory for usage examples.
26
36
  email:
27
- - raymonds72@gmail.com
37
+ - raimonds.simanovskis@gmail.com
28
38
  executables: []
29
39
 
30
40
  extensions: []
@@ -37,7 +47,6 @@ files:
37
47
  - History.txt
38
48
  - License.txt
39
49
  - README.txt
40
- - lib/oradate_patch.rb
41
50
  - lib/plsql/connection.rb
42
51
  - lib/plsql/jdbc_connection.rb
43
52
  - lib/plsql/oci_connection.rb
@@ -46,13 +55,14 @@ files:
46
55
  - lib/plsql/schema.rb
47
56
  - lib/ruby_plsql.rb
48
57
  - lib/ruby_plsql/version.rb
58
+ - spec/plsql/connection_spec.rb
49
59
  - spec/plsql/package_spec.rb
50
60
  - spec/plsql/procedure_spec.rb
51
61
  - spec/plsql/schema_spec.rb
52
62
  - spec/spec.opts
53
63
  - spec/spec_helper.rb
54
64
  has_rdoc: true
55
- homepage: http://ruby-plsql.rubyforge.org
65
+ homepage: http://rubyforge.org/projects/ruby-plsql/
56
66
  post_install_message:
57
67
  rdoc_options:
58
68
  - --main
@@ -1,10 +0,0 @@
1
- class OraDate
2
- if defined? DateTime # ruby 1.8.0 or upper
3
- # RSI: create DateTime in local timezone
4
- def to_datetime
5
- DateTime.parse(Time.local(year, month, day, hour, minute, second).iso8601)
6
- rescue
7
- DateTime.new(year, month, day, hour, minute, second)
8
- end
9
- end
10
- end