ruby-oci8 2.0.1-x86-mswin32-60 → 2.0.2-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog CHANGED
@@ -1,3 +1,92 @@
1
+ 2009-05-17 KUBO Takehiro <kubo@jiubao.org>
2
+ * NEWS: add changes between 2.0.1 and 2.0.2.
3
+ * VERSION: change version to 2.0.2.
4
+ * dist-files: append newly added files.
5
+ * ext/oci8/oci8.c: fix OCI8#ping not to raise an exception
6
+ when OCIPing() failed. It should returns true or false.
7
+ * ext/oci8/oci8lib.c: Memory allocated by xmalloc() should be
8
+ freed by xfree().
9
+
10
+ 2009-05-17 KUBO Takehiro <kubo@jiubao.org>
11
+ * ext/oci8/error.c, ext/oci8/extconf.rb, ext/oci8/oci8.h:
12
+ fix the native library name in error messages from oci8lib.so
13
+ to oci8lib_18.so or oci8lib_191.so.
14
+ * ext/oci8/ocinumber.c, test/test_oranumber.rb: fix OraNumber.new
15
+ to accept BigDecimal and Rational.
16
+ * ext/oci8/bind.c, test/test_oci8.rb: implicitly convert the
17
+ specified number to Float when the bind handle is for Float.
18
+ * ext/oci8/attr.c: fix for Oracle client which doesn't have
19
+ OCIRowidToChar().
20
+ * ext/oci8/oci8.c, test/test_appinfo.rb, test/test_all.rb, dist-files:
21
+ add new methods OCI8#ping and OCI8#client_identifier=.
22
+ add test cases.
23
+ * ext/oci8/oci8lib.c: fix a bug for Oracle 8.0.
24
+ * lib/oci8/oci8.rb: add a convenient method OCI8#select_one
25
+ to fetch one row.
26
+
27
+ 2009-04-18 KUBO Takehiro <kubo@jiubao.org>
28
+ * lib/oci8/oci8.rb: move OCI8::BindType module to bindtype.rb.
29
+ * lib/oci8/bindtype.rb: added. This defines OCI8::BindType.
30
+ * lib/oci8.rb.in: require 'oci8/bindtype.rb'
31
+
32
+ 2009-04-17 KUBO Takehiro <kubo@jiubao.org>
33
+ * ext/oci8/encoding.c, ext/oci8/lob.c, ext/oci8/metadata.c,
34
+ ext/oci8/oci8.c: suppress "warning C4761: integral size mismatch
35
+ in argument; conversion supplied" when compiled by Visual C++.
36
+
37
+ 2009-04-17 KUBO Takehiro <kubo@jiubao.org>
38
+ * ext/oci8/apiwrap.yml, ext/oci8/env.c, ext/oci8/extconf.rb,
39
+ ext/oci8/oci8.h, ext/oci8/oci8lib.c: OCIEnv is initialized
40
+ when it is needed. This makes a basis to enable an event
41
+ notification after "require 'oci8'."
42
+ * test/test_all.rb: fix a bug added four days ago.
43
+
44
+ 2009-04-14 KUBO Takehiro <kubo@jiubao.org>
45
+ * ext/oci8/oci8.h, ext/oci8/oci8lib.c, ext/oci8/ocinumber.c,
46
+ ext/oci8/metadata.c, ext/oci8/object.c: pass an OCIError to
47
+ OraNumber functions if it can. (This is the first step to
48
+ delay OCIEnv initialization.)
49
+
50
+ 2009-04-14 KUBO Takehiro <kubo@jiubao.org>
51
+ * ext/oci8/oraconf.rb: Gets ORACLE_HOME from the Windows regitry
52
+ by enumerating subkeys of \\HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE.
53
+
54
+ 2009-04-12 KUBO Takehiro <kubo@jiubao.org>
55
+ * lib/oci8/oci8.rb, test/test_encoding.rb: The string bind length should
56
+ be got from the string bytesize converted to OCI8.encoding.
57
+
58
+ 2009-04-12 KUBO Takehiro <kubo@jiubao.org>
59
+ * ext/oci8/lob.c: OCI8::BLOB#read should return ASCII-8BIT.
60
+ OCI8::BLOB#write should not convert the specified string
61
+ to OCI8.encoding.
62
+ * test/test_dbi.rb: suppress warning: "shadowing outer local
63
+ variable - i"
64
+ * test/test_all.rb, test/test_encoding.rb: add string encoding
65
+ tests.
66
+
67
+ 2009-04-12 KUBO Takehiro <kubo@jiubao.org>
68
+ * lib/dbd/OCI8.rb: fix DBI::DBD::OCI8::BindType::DBIStatementHandle
69
+ to pass a newly added sanity check in dbi 0.4.1.
70
+ (reported by Dirk Herzhauser)
71
+ * test/test_all.rb: fix to use dbi installed as a rubygem.
72
+
73
+ 2009-04-04 KUBO Takehiro <kubo@jiubao.org>
74
+ * ext/oci8/bind.c: fix an error when executing "select NULL from dual".
75
+ http://rubyforge.org/forum/forum.php?thread_id=32468&forum_id=1078
76
+ (contributed by Raimonds Simanovskis)
77
+
78
+ 2009-03-24 KUBO Takehiro <kubo@jiubao.org>
79
+ * ext/oci8/extconf.rb, ext/oci8/oci8.h, ext/oci8/oraconf.rb:
80
+ fix a problem when compiling with Oracle 8.0.
81
+ (reported by Axel Reinhold)
82
+
83
+ 2009-03-24 KUBO Takehiro <kubo@jiubao.org>
84
+ * ext/oci8/extconf.rb, ext/oci8/oci8.h: fix a problem when
85
+ compiling with Oracle 9.2.
86
+ (reported by Axel Reinhold)
87
+ * ext/oci8/apiwrap.yml: suppres warnings 'discards qualifiers
88
+ from pointer target type' when compiling with Oracle 8i.
89
+
1
90
  2009-03-17 KUBO Takehiro <kubo@jiubao.org>
2
91
  * NEWS: add a new file.
3
92
  * VERSION: change version to 2.0.1.
data/Makefile CHANGED
@@ -50,38 +50,40 @@ dist-check: dist
50
50
  #
51
51
  # for Windows
52
52
  #
53
- GEMPKG = ruby-oci8-unstable-2.0.1-x86-mswin32-60.gem
53
+ RUBY_18 = c:\ruby
54
+ RUBY_191 = c:\ruby-1.9.1
55
+ GEMPKG = ruby-oci8-2.0.2-x86-mswin32-60.gem
54
56
 
55
57
  ext\oci8\oci8lib_18.so:
56
- c:\ruby\bin\ruby -r fileutils -e "FileUtils.rm_rf('ruby18')"
58
+ $(RUBY_18)\bin\ruby -r fileutils -e "FileUtils.rm_rf('ruby18')"
57
59
  md ruby18
58
60
  cd ruby18
59
- c:\ruby\bin\ruby ..\setup.rb config -- --with-runtime-check
60
- c:\ruby\bin\ruby ..\setup.rb setup
61
- rem c:\ruby\bin\ruby ..\setup.rb test
61
+ $(RUBY_18)\bin\ruby ..\setup.rb config -- --with-runtime-check
62
+ $(RUBY_18)\bin\ruby ..\setup.rb setup
63
+ rem $(RUBY_18)\bin\ruby ..\setup.rb test
62
64
  cd ..
63
65
  copy ruby18\ext\oci8\oci8lib_18.so ext\oci8\oci8lib_18.so
64
66
 
65
67
  ext\oci8\oci8lib_191.so:
66
- c:\ruby\bin\ruby -r fileutils -e "FileUtils.rm_rf('ruby191')"
68
+ $(RUBY_191)\bin\ruby -r fileutils -e "FileUtils.rm_rf('ruby191')"
67
69
  md ruby191
68
70
  cd ruby191
69
- c:\ruby-1.9.1\bin\ruby ..\setup.rb config -- --with-runtime-check
70
- c:\ruby-1.9.1\bin\ruby ..\setup.rb setup
71
- rem c:\ruby-1.9.1\bin\ruby ..\setup.rb test
71
+ $(RUBY_191)\bin\ruby ..\setup.rb config -- --with-runtime-check
72
+ $(RUBY_191)\bin\ruby ..\setup.rb setup
73
+ rem $(RUBY_191)\bin\ruby ..\setup.rb test
72
74
  cd ..
73
75
  copy ruby191\ext\oci8\oci8lib_191.so ext\oci8\oci8lib_191.so
74
76
  copy ruby191\lib\oci8.rb lib\oci8.rb
75
77
 
76
78
  $(GEMPKG): ext\oci8\oci8lib_18.so ext\oci8\oci8lib_191.so ruby-oci8.gemspec
77
- c:\ruby-1.9.1\bin\gem build ruby-oci8.gemspec -- current
79
+ $(RUBY_191)\bin\gem build ruby-oci8.gemspec -- current
78
80
 
79
81
  test-win32-ruby18: $(GEMPKG)
80
- c:\ruby\bin\gem install $(GEMPKG) --no-rdoc --no-ri
81
- c:\ruby\bin\ruby -rubygems test\test_all.rb
82
+ $(RUBY_18)\bin\gem install $(GEMPKG) --no-rdoc --no-ri --local
83
+ $(RUBY_18)\bin\ruby -rubygems test\test_all.rb
82
84
 
83
85
  test-win32-ruby191: $(GEMPKG)
84
- c:\ruby-1.9.1\bin\gem install $(GEMPKG) --no-rdoc --no-ri
85
- c:\ruby-1.9.1\bin\ruby test\test_all.rb
86
+ $(RUBY_191)\bin\gem install $(GEMPKG) --no-rdoc --no-ri --local
87
+ $(RUBY_191)\bin\ruby test\test_all.rb
86
88
 
87
89
  test-win32: test-win32-ruby18 test-win32-ruby191
data/NEWS CHANGED
@@ -1,3 +1,39 @@
1
+ 2.0.2:
2
+
3
+ * add new methods
4
+ - OCI8#select_one(sql, *bindvars) -> first_row
5
+
6
+ - OCI8#ping -> true or false
7
+
8
+ Verifies that the Oracle connection is alive.
9
+ OCI8#ping also can be used to flush all the pending OCI
10
+ client-side calls to the server if any exist.
11
+
12
+ - OCI8#client_identifier = client_id
13
+
14
+ Look at the following link to know what is the client identifier.
15
+ http://it.toolbox.com/blogs/database-solutions/oracle-session-tracing-part-i-16356
16
+
17
+ Note that the specified identifier doesn't change the v$session
18
+ immediately. It is done by the next network round trip
19
+ such as OCI8#exec or OCI8#ping.
20
+
21
+ * fix problems when compiling with Oracle 9.2 and 8.0.
22
+ (reported by Axel Reinhold)
23
+
24
+ * [dbi] fix to pass a newly added sanity check in dbi 0.4.1.
25
+ (reported by Dirk Herzhauser)
26
+
27
+ * fix an error when executing "select NULL from dual".
28
+ http://rubyforge.org/forum/forum.php?thread_id=32468&forum_id=1078
29
+ (contributed by Raimonds Simanovskis)
30
+
31
+ * [ruby 1.9] fix OCI8::BLOB to read/write binary. Prior to 2.0.1,
32
+ it was treated as text tagged with NLS_LANG encoding.
33
+
34
+ * [ruby 1.9] fix to bind string data by the length got from String#bytesize
35
+ converted to OCI8.encoding, not by String#size.
36
+
1
37
  2.0.1:
2
38
 
3
39
  * release a binary gem for Windows, which contains libraries for both
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.0.1
1
+ 2.0.2
data/dist-files CHANGED
@@ -43,6 +43,7 @@ lib/.document
43
43
  lib/oci8.rb.in
44
44
  lib/dbd/OCI8.rb
45
45
  lib/oci8/.document
46
+ lib/oci8/bindtype.rb
46
47
  lib/oci8/compat.rb
47
48
  lib/oci8/datetime.rb
48
49
  lib/oci8/encoding-init.rb
@@ -54,12 +55,14 @@ lib/oci8/oracle_version.rb
54
55
  test/README
55
56
  test/config.rb
56
57
  test/test_all.rb
58
+ test/test_appinfo.rb
57
59
  test/test_array_dml.rb
58
60
  test/test_bind_raw.rb
59
61
  test/test_bind_time.rb
60
62
  test/test_break.rb
61
63
  test/test_clob.rb
62
64
  test/test_connstr.rb
65
+ test/test_encoding.rb
63
66
  test/test_datetime.rb
64
67
  test/test_dbi.rb
65
68
  test/test_dbi_clob.rb
@@ -402,6 +402,21 @@ class Statement < DBI::BaseStatement
402
402
  end
403
403
  end
404
404
 
405
+ # DBI_STMT_NEW_ARGS is DBI::StatementHandle.new's arguments except +handle+.
406
+ #
407
+ # FYI: DBI::StatementHandle.new method signatures are follows:
408
+ # 0.2.2: handle, fetchable=false, prepared=true
409
+ # 0.4.0: handle, fetchable=false, prepared=true, convert_types=true
410
+ # 0.4.1: handle, fetchable=false, prepared=true, convert_types=true, executed=false
411
+ begin
412
+ DBI::StatementHandle.new(nil, false, true, true, true)
413
+ # dbi 0.4.1
414
+ DBI_STMT_NEW_ARGS = [true, true, true, true] # :nodoc:
415
+ rescue ArgumentError
416
+ # dbi 0.4.0 or lower
417
+ DBI_STMT_NEW_ARGS = [true] # :nodoc:
418
+ end
419
+
405
420
  if defined? ::OCI8::BindType::Base
406
421
  ##
407
422
  ## ruby-oci8 2.0 bind classes.
@@ -491,7 +506,7 @@ if defined? ::OCI8::BindType::Base
491
506
  val = super
492
507
  return nil if val.nil?
493
508
  stmt = DBI::DBD::OCI8::Statement.new(val)
494
- DBI::StatementHandle.new(stmt, true, false)
509
+ DBI::StatementHandle.new(stmt, *DBI_STMT_NEW_ARGS)
495
510
  end
496
511
  end
497
512
  end # BindType
@@ -560,7 +575,7 @@ else
560
575
  return val if val.nil?
561
576
  cur = ::OCI8::Cursor.new(@env, @svc, @ctx, val)
562
577
  stmt = DBI::DBD::OCI8::Statement.new(cur)
563
- DBI::StatementHandle.new(stmt, true, false)
578
+ DBI::StatementHandle.new(stmt, *DBI_STMT_NEW_ARGS)
564
579
  end
565
580
  end
566
581
  end
@@ -71,11 +71,12 @@ end
71
71
 
72
72
  require 'oci8/datetime.rb'
73
73
  require 'oci8/oci8.rb'
74
+ require 'oci8/bindtype.rb'
74
75
  require 'oci8/metadata.rb'
75
76
  require 'oci8/compat.rb'
76
77
  require 'oci8/object.rb'
77
78
 
78
79
  class OCI8
79
- VERSION = '2.0.1'
80
+ VERSION = '2.0.2'
80
81
  CLIENT_VERSION = '1020'
81
82
  end
@@ -71,6 +71,7 @@ end
71
71
 
72
72
  require 'oci8/datetime.rb'
73
73
  require 'oci8/oci8.rb'
74
+ require 'oci8/bindtype.rb'
74
75
  require 'oci8/metadata.rb'
75
76
  require 'oci8/compat.rb'
76
77
  require 'oci8/object.rb'
@@ -0,0 +1,295 @@
1
+ #--
2
+ # bindtype.rb -- OCI8::BindType
3
+ #
4
+ # Copyright (C) 2009 KUBO Takehiro <kubo@jiubao.org>
5
+ #++
6
+
7
+ class OCI8
8
+ module BindType
9
+ Mapping = {}
10
+
11
+ class Base
12
+ def self.create(con, val, param, max_array_size)
13
+ self.new(con, val, param, max_array_size)
14
+ end
15
+ end
16
+
17
+ # get/set Date
18
+ class Date < OCI8::BindType::OraDate
19
+ def set(val)
20
+ super(val && ::OraDate.new(val.year, val.mon, val.mday))
21
+ end
22
+ def get()
23
+ (val = super()) && val.to_date
24
+ end
25
+ end
26
+
27
+ # get/set Number (for OCI8::SQLT_NUM)
28
+ class Number
29
+ def self.create(con, val, param, max_array_size)
30
+ if param.is_a? OCI8::Metadata::Base
31
+ precision = param.precision
32
+ scale = param.scale
33
+ end
34
+ if scale == -127
35
+ if precision == 0
36
+ # NUMBER declared without its scale and precision. (Oracle 9.2.0.3 or above)
37
+ klass = OCI8::BindType::Mapping[:number_no_prec_setting]
38
+ else
39
+ # FLOAT or FLOAT(p)
40
+ klass = OCI8::BindType::Float
41
+ end
42
+ elsif scale == 0
43
+ if precision == 0
44
+ # NUMBER whose scale and precision is unknown
45
+ # or
46
+ # NUMBER declared without its scale and precision. (Oracle 9.2.0.2 or below)
47
+ klass = OCI8::BindType::Mapping[:number_unknown_prec]
48
+ else
49
+ # NUMBER(p, 0)
50
+ klass = OCI8::BindType::Integer
51
+ end
52
+ else
53
+ # NUMBER(p, s)
54
+ if precision < 15 # the precision of double.
55
+ klass = OCI8::BindType::Float
56
+ else
57
+ # use BigDecimal instead?
58
+ klass = OCI8::BindType::OraNumber
59
+ end
60
+ end
61
+ klass.new(con, val, nil, max_array_size)
62
+ end
63
+ end
64
+
65
+ class String
66
+ # 1333 <= ceil(4000 / 3). 4000 is max size of char. 3 is NLS ratio of UTF-8.
67
+ @@minimum_bind_length = 1333
68
+
69
+ def self.minimum_bind_length
70
+ @@minimum_bind_length
71
+ end
72
+
73
+ def self.minimum_bind_length=(val)
74
+ @@minimum_bind_length = val
75
+ end
76
+
77
+ def self.create(con, val, param, max_array_size)
78
+ case param
79
+ when Hash
80
+ if param[:length]
81
+ # If length is passed explicitly, use it.
82
+ length = param[:length]
83
+ elsif val.is_a? String or (val.respond_to? :to_str and val = val.to_str)
84
+ if OCI8.respond_to? :encoding and OCI8.encoding != val.encoding
85
+ # If the string encoding is different with NLS_LANG character set,
86
+ # convert it to get the length.
87
+ val = val.encode(OCI8.encoding)
88
+ end
89
+ if val.respond_to? :bytesize
90
+ # ruby 1.8.7 or upper
91
+ length = val.bytesize
92
+ else
93
+ # ruby 1.8.6 or lower
94
+ length = val.size
95
+ end
96
+ end
97
+ when OCI8::Metadata::Base
98
+ case param.data_type
99
+ when :char, :varchar2
100
+ length = param.data_size
101
+ # character size may become large on character set conversion.
102
+ # The length of a Japanese half-width kana is one in Shift_JIS,
103
+ # two in EUC-JP, three in UTF-8.
104
+ length *= 3 unless param.char_used?
105
+ when :raw
106
+ # HEX needs twice space.
107
+ length = param.data_size * 2
108
+ end
109
+ end
110
+ length = @@minimum_bind_length if length.nil? or length < @@minimum_bind_length
111
+ self.new(con, val, length, max_array_size)
112
+ end
113
+ end
114
+
115
+ class RAW
116
+ def self.create(con, val, param, max_array_size)
117
+ case param
118
+ when Hash
119
+ length = 400 # default length
120
+ if param[:length]
121
+ length = param[:length]
122
+ elsif val.respond_to? :to_str and val.to_str.size > length
123
+ length = val.to_str.size
124
+ end
125
+ when OCI8::Metadata::Base
126
+ length = param.data_size
127
+ end
128
+ self.new(con, val, length, max_array_size)
129
+ end
130
+ end
131
+
132
+ class Long < OCI8::BindType::String
133
+ def self.create(con, val, param, max_array_size)
134
+ self.new(con, val, con.long_read_len, max_array_size)
135
+ end
136
+ end
137
+
138
+ class LongRaw < OCI8::BindType::RAW
139
+ def self.create(con, val, param, max_array_size)
140
+ self.new(con, val, con.long_read_len, max_array_size)
141
+ end
142
+ end
143
+
144
+ class CLOB
145
+ def self.create(con, val, param, max_array_size)
146
+ if param.is_a? OCI8::Metadata::Base and param.charset_form == :nchar
147
+ OCI8::BindType::NCLOB.new(con, val, nil, max_array_size)
148
+ else
149
+ OCI8::BindType::CLOB.new(con, val, nil, max_array_size)
150
+ end
151
+ end
152
+ end
153
+ end # BindType
154
+ end
155
+
156
+ # bind or explicitly define
157
+ OCI8::BindType::Mapping[String] = OCI8::BindType::String
158
+ OCI8::BindType::Mapping[OraNumber] = OCI8::BindType::OraNumber
159
+ OCI8::BindType::Mapping[Fixnum] = OCI8::BindType::Integer
160
+ OCI8::BindType::Mapping[Float] = OCI8::BindType::Float
161
+ OCI8::BindType::Mapping[Integer] = OCI8::BindType::Integer
162
+ OCI8::BindType::Mapping[Bignum] = OCI8::BindType::Integer
163
+ OCI8::BindType::Mapping[OraDate] = OCI8::BindType::OraDate
164
+ OCI8::BindType::Mapping[Time] = OCI8::BindType::Time
165
+ OCI8::BindType::Mapping[Date] = OCI8::BindType::Date
166
+ OCI8::BindType::Mapping[DateTime] = OCI8::BindType::DateTime
167
+ OCI8::BindType::Mapping[OCI8::CLOB] = OCI8::BindType::CLOB
168
+ OCI8::BindType::Mapping[OCI8::NCLOB] = OCI8::BindType::NCLOB
169
+ OCI8::BindType::Mapping[OCI8::BLOB] = OCI8::BindType::BLOB
170
+ OCI8::BindType::Mapping[OCI8::BFILE] = OCI8::BindType::BFILE
171
+ OCI8::BindType::Mapping[OCI8::Cursor] = OCI8::BindType::Cursor
172
+
173
+ # implicitly define
174
+
175
+ # datatype type size prec scale
176
+ # -------------------------------------------------
177
+ # CHAR(1) SQLT_AFC 1 0 0
178
+ # CHAR(10) SQLT_AFC 10 0 0
179
+ OCI8::BindType::Mapping[:char] = OCI8::BindType::String
180
+
181
+ # datatype type size prec scale
182
+ # -------------------------------------------------
183
+ # VARCHAR(1) SQLT_CHR 1 0 0
184
+ # VARCHAR(10) SQLT_CHR 10 0 0
185
+ # VARCHAR2(1) SQLT_CHR 1 0 0
186
+ # VARCHAR2(10) SQLT_CHR 10 0 0
187
+ OCI8::BindType::Mapping[:varchar2] = OCI8::BindType::String
188
+
189
+ # datatype type size prec scale
190
+ # -------------------------------------------------
191
+ # RAW(1) SQLT_BIN 1 0 0
192
+ # RAW(10) SQLT_BIN 10 0 0
193
+ OCI8::BindType::Mapping[:raw] = OCI8::BindType::RAW
194
+
195
+ # datatype type size prec scale
196
+ # -------------------------------------------------
197
+ # LONG SQLT_LNG 0 0 0
198
+ OCI8::BindType::Mapping[:long] = OCI8::BindType::Long
199
+
200
+ # datatype type size prec scale
201
+ # -------------------------------------------------
202
+ # LONG RAW SQLT_LBI 0 0 0
203
+ OCI8::BindType::Mapping[:long_raw] = OCI8::BindType::LongRaw
204
+
205
+ # datatype type size prec scale
206
+ # -------------------------------------------------
207
+ # CLOB SQLT_CLOB 4000 0 0
208
+ OCI8::BindType::Mapping[:clob] = OCI8::BindType::CLOB
209
+ OCI8::BindType::Mapping[:nclob] = OCI8::BindType::NCLOB
210
+
211
+ # datatype type size prec scale
212
+ # -------------------------------------------------
213
+ # BLOB SQLT_BLOB 4000 0 0
214
+ OCI8::BindType::Mapping[:blob] = OCI8::BindType::BLOB
215
+
216
+ # datatype type size prec scale
217
+ # -------------------------------------------------
218
+ # BFILE SQLT_BFILE 4000 0 0
219
+ OCI8::BindType::Mapping[:bfile] = OCI8::BindType::BFILE
220
+
221
+ # datatype type size prec scale
222
+ # -------------------------------------------------
223
+ # DATE SQLT_DAT 7 0 0
224
+ OCI8::BindType::Mapping[:date] = OCI8::BindType::Time
225
+
226
+ if OCI8.oracle_client_version >= OCI8::ORAVER_9_0
227
+ OCI8::BindType::Mapping[:timestamp] = OCI8::BindType::Time
228
+ OCI8::BindType::Mapping[:timestamp_tz] = OCI8::BindType::Time
229
+ OCI8::BindType::Mapping[:timestamp_ltz] = OCI8::BindType::Time
230
+ OCI8::BindType::Mapping[:interval_ym] = OCI8::BindType::IntervalYM
231
+ OCI8::BindType::Mapping[:interval_ds] = OCI8::BindType::IntervalDS
232
+ end
233
+
234
+ # datatype type size prec scale
235
+ # -------------------------------------------------
236
+ # ROWID SQLT_RDD 4 0 0
237
+ OCI8::BindType::Mapping[:rowid] = OCI8::BindType::String
238
+
239
+ # datatype type size prec scale
240
+ # -----------------------------------------------------
241
+ # FLOAT SQLT_NUM 22 126 -127
242
+ # FLOAT(1) SQLT_NUM 22 1 -127
243
+ # FLOAT(126) SQLT_NUM 22 126 -127
244
+ # DOUBLE PRECISION SQLT_NUM 22 126 -127
245
+ # REAL SQLT_NUM 22 63 -127
246
+ # NUMBER SQLT_NUM 22 0 0
247
+ # NUMBER(1) SQLT_NUM 22 1 0
248
+ # NUMBER(38) SQLT_NUM 22 38 0
249
+ # NUMBER(1, 0) SQLT_NUM 22 1 0
250
+ # NUMBER(38, 0) SQLT_NUM 22 38 0
251
+ # NUMERIC SQLT_NUM 22 38 0
252
+ # INT SQLT_NUM 22 38 0
253
+ # INTEGER SQLT_NUM 22 38 0
254
+ # SMALLINT SQLT_NUM 22 38 0
255
+ OCI8::BindType::Mapping[:number] = OCI8::BindType::Number
256
+
257
+ # mapping for calculated number values.
258
+ #
259
+ # for example:
260
+ # select col1 * 1.1 from tab1;
261
+ #
262
+ # For Oracle 9.2.0.2 or below, this is also used for NUMBER
263
+ # datatypes that have no explicit setting of their precision
264
+ # and scale.
265
+ #
266
+ # The default mapping is Float for ruby-oci8 1.0. It is OraNumber
267
+ # for ruby-oci8 2.0.
268
+ OCI8::BindType::Mapping[:number_unknown_prec] = OCI8::BindType::OraNumber
269
+
270
+ # mapping for number without precision and scale.
271
+ #
272
+ # for example:
273
+ # create table tab1 (col1 number);
274
+ # select col1 from tab1;
275
+ #
276
+ # note: This is available only on Oracle 9.2.0.3 or above.
277
+ # see: Oracle 9.2.0.x Patch Set Notes.
278
+ #
279
+ # The default mapping is Float for ruby-oci8 1.0. It is OraNumber
280
+ # for ruby-oci8 2.0.
281
+ OCI8::BindType::Mapping[:number_no_prec_setting] = OCI8::BindType::OraNumber
282
+
283
+ if defined? OCI8::BindType::BinaryDouble
284
+ OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::BinaryDouble
285
+ OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::BinaryDouble
286
+ else
287
+ OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::Float
288
+ OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::Float
289
+ end
290
+
291
+ # Cursor
292
+ OCI8::BindType::Mapping[:cursor] = OCI8::BindType::Cursor
293
+
294
+ # XMLType (This mapping will be changed before release.)
295
+ OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::Long
@@ -1,5 +1,12 @@
1
- # --*- ruby -*--
2
- # This is based on yoshidam's oracle.rb.
1
+ #--
2
+ # oci8.rb -- OCI8 and OCI8::Cursor
3
+ #
4
+ # Copyright (C) 2002-2009 KUBO Takehiro <kubo@jiubao.org>
5
+ #
6
+ # Original Copyright is:
7
+ # Oracle module for Ruby
8
+ # 1998-2000 by yoshidam
9
+ #++
3
10
 
4
11
  require 'date'
5
12
 
@@ -122,6 +129,20 @@ class OCI8
122
129
  end
123
130
  end # exec
124
131
 
132
+ # :call-seq:
133
+ # select_one(sql, *bindvars) -> first_one_row
134
+ #
135
+ def select_one(sql, *bindvars)
136
+ cursor = self.parse(sql)
137
+ begin
138
+ cursor.exec(*bindvars)
139
+ row = cursor.fetch
140
+ ensure
141
+ cursor.close
142
+ end
143
+ return row
144
+ end
145
+
125
146
  def username
126
147
  @username || begin
127
148
  exec('select user from dual') do |row|
@@ -160,133 +181,6 @@ class OCI8
160
181
  @oracle_server_version
161
182
  end
162
183
 
163
- module BindType
164
- Mapping = {}
165
-
166
- class Base
167
- def self.create(con, val, param, max_array_size)
168
- self.new(con, val, param, max_array_size)
169
- end
170
- end
171
-
172
- # get/set Date
173
- class Date < OCI8::BindType::OraDate
174
- def set(val)
175
- super(val && ::OraDate.new(val.year, val.mon, val.mday))
176
- end
177
- def get()
178
- (val = super()) && val.to_date
179
- end
180
- end
181
-
182
- # get/set Number (for OCI8::SQLT_NUM)
183
- class Number
184
- def self.create(con, val, param, max_array_size)
185
- if param.is_a? OCI8::Metadata::Base
186
- precision = param.precision
187
- scale = param.scale
188
- end
189
- if scale == -127
190
- if precision == 0
191
- # NUMBER declared without its scale and precision. (Oracle 9.2.0.3 or above)
192
- klass = OCI8::BindType::Mapping[:number_no_prec_setting]
193
- else
194
- # FLOAT or FLOAT(p)
195
- klass = OCI8::BindType::Float
196
- end
197
- elsif scale == 0
198
- if precision == 0
199
- # NUMBER whose scale and precision is unknown
200
- # or
201
- # NUMBER declared without its scale and precision. (Oracle 9.2.0.2 or below)
202
- klass = OCI8::BindType::Mapping[:number_unknown_prec]
203
- else
204
- # NUMBER(p, 0)
205
- klass = OCI8::BindType::Integer
206
- end
207
- else
208
- # NUMBER(p, s)
209
- if precision < 15 # the precision of double.
210
- klass = OCI8::BindType::Float
211
- else
212
- # use BigDecimal instead?
213
- klass = OCI8::BindType::OraNumber
214
- end
215
- end
216
- klass.new(con, val, nil, max_array_size)
217
- end
218
- end
219
-
220
- class String
221
- def self.create(con, val, param, max_array_size)
222
- case param
223
- when Hash
224
- # 1333 = ceil(4000 (max size of char) / 3 (NLS ratio of UTF8))
225
- length = 1333 # default length
226
- if param[:length]
227
- length = param[:length]
228
- elsif val.respond_to? :to_str and val.to_str.size > length
229
- length = val.to_str.size
230
- end
231
- when OCI8::Metadata::Base
232
- case param.data_type
233
- when :char, :varchar2
234
- length = param.data_size
235
- # character size may become large on character set conversion.
236
- # The length of a Japanese half-width kana is one in Shift_JIS,
237
- # two in EUC-JP, three in UTF-8.
238
- length *= 3 unless param.char_used?
239
- when :raw
240
- # HEX needs twice space.
241
- length = param.data_size * 2
242
- else
243
- length = 100
244
- end
245
- end
246
- self.new(con, val, length, max_array_size)
247
- end
248
- end
249
-
250
- class RAW
251
- def self.create(con, val, param, max_array_size)
252
- case param
253
- when Hash
254
- length = 400 # default length
255
- if param[:length]
256
- length = param[:length]
257
- elsif val.respond_to? :to_str and val.to_str.size > length
258
- length = val.to_str.size
259
- end
260
- when OCI8::Metadata::Base
261
- length = param.data_size
262
- end
263
- self.new(con, val, length, max_array_size)
264
- end
265
- end
266
-
267
- class Long < OCI8::BindType::String
268
- def self.create(con, val, param, max_array_size)
269
- self.new(con, val, con.long_read_len, max_array_size)
270
- end
271
- end
272
-
273
- class LongRaw < OCI8::BindType::RAW
274
- def self.create(con, val, param, max_array_size)
275
- self.new(con, val, con.long_read_len, max_array_size)
276
- end
277
- end
278
-
279
- class CLOB
280
- def self.create(con, val, param, max_array_size)
281
- if param.is_a? OCI8::Metadata::Base and param.charset_form == :nchar
282
- OCI8::BindType::NCLOB.new(con, val, nil, max_array_size)
283
- else
284
- OCI8::BindType::CLOB.new(con, val, nil, max_array_size)
285
- end
286
- end
287
- end
288
- end # BindType
289
-
290
184
  # The instance of this class corresponds to cursor in the term of
291
185
  # Oracle, which corresponds to java.sql.Statement of JDBC and statement
292
186
  # handle $sth of Perl/DBI.
@@ -655,144 +549,3 @@ class String
655
549
  OraNumber.new(self, format, nls_params)
656
550
  end
657
551
  end
658
-
659
- # bind or explicitly define
660
- OCI8::BindType::Mapping[String] = OCI8::BindType::String
661
- OCI8::BindType::Mapping[OraNumber] = OCI8::BindType::OraNumber
662
- OCI8::BindType::Mapping[Fixnum] = OCI8::BindType::Integer
663
- OCI8::BindType::Mapping[Float] = OCI8::BindType::Float
664
- OCI8::BindType::Mapping[Integer] = OCI8::BindType::Integer
665
- OCI8::BindType::Mapping[Bignum] = OCI8::BindType::Integer
666
- OCI8::BindType::Mapping[OraDate] = OCI8::BindType::OraDate
667
- OCI8::BindType::Mapping[Time] = OCI8::BindType::Time
668
- OCI8::BindType::Mapping[Date] = OCI8::BindType::Date
669
- OCI8::BindType::Mapping[DateTime] = OCI8::BindType::DateTime
670
- OCI8::BindType::Mapping[OCI8::CLOB] = OCI8::BindType::CLOB
671
- OCI8::BindType::Mapping[OCI8::NCLOB] = OCI8::BindType::NCLOB
672
- OCI8::BindType::Mapping[OCI8::BLOB] = OCI8::BindType::BLOB
673
- OCI8::BindType::Mapping[OCI8::BFILE] = OCI8::BindType::BFILE
674
- OCI8::BindType::Mapping[OCI8::Cursor] = OCI8::BindType::Cursor
675
-
676
- # implicitly define
677
-
678
- # datatype type size prec scale
679
- # -------------------------------------------------
680
- # CHAR(1) SQLT_AFC 1 0 0
681
- # CHAR(10) SQLT_AFC 10 0 0
682
- OCI8::BindType::Mapping[:char] = OCI8::BindType::String
683
-
684
- # datatype type size prec scale
685
- # -------------------------------------------------
686
- # VARCHAR(1) SQLT_CHR 1 0 0
687
- # VARCHAR(10) SQLT_CHR 10 0 0
688
- # VARCHAR2(1) SQLT_CHR 1 0 0
689
- # VARCHAR2(10) SQLT_CHR 10 0 0
690
- OCI8::BindType::Mapping[:varchar2] = OCI8::BindType::String
691
-
692
- # datatype type size prec scale
693
- # -------------------------------------------------
694
- # RAW(1) SQLT_BIN 1 0 0
695
- # RAW(10) SQLT_BIN 10 0 0
696
- OCI8::BindType::Mapping[:raw] = OCI8::BindType::RAW
697
-
698
- # datatype type size prec scale
699
- # -------------------------------------------------
700
- # LONG SQLT_LNG 0 0 0
701
- OCI8::BindType::Mapping[:long] = OCI8::BindType::Long
702
-
703
- # datatype type size prec scale
704
- # -------------------------------------------------
705
- # LONG RAW SQLT_LBI 0 0 0
706
- OCI8::BindType::Mapping[:long_raw] = OCI8::BindType::LongRaw
707
-
708
- # datatype type size prec scale
709
- # -------------------------------------------------
710
- # CLOB SQLT_CLOB 4000 0 0
711
- OCI8::BindType::Mapping[:clob] = OCI8::BindType::CLOB
712
- OCI8::BindType::Mapping[:nclob] = OCI8::BindType::NCLOB
713
-
714
- # datatype type size prec scale
715
- # -------------------------------------------------
716
- # BLOB SQLT_BLOB 4000 0 0
717
- OCI8::BindType::Mapping[:blob] = OCI8::BindType::BLOB
718
-
719
- # datatype type size prec scale
720
- # -------------------------------------------------
721
- # BFILE SQLT_BFILE 4000 0 0
722
- OCI8::BindType::Mapping[:bfile] = OCI8::BindType::BFILE
723
-
724
- # datatype type size prec scale
725
- # -------------------------------------------------
726
- # DATE SQLT_DAT 7 0 0
727
- OCI8::BindType::Mapping[:date] = OCI8::BindType::Time
728
-
729
- if OCI8.oracle_client_version >= OCI8::ORAVER_9_0
730
- OCI8::BindType::Mapping[:timestamp] = OCI8::BindType::Time
731
- OCI8::BindType::Mapping[:timestamp_tz] = OCI8::BindType::Time
732
- OCI8::BindType::Mapping[:timestamp_ltz] = OCI8::BindType::Time
733
- OCI8::BindType::Mapping[:interval_ym] = OCI8::BindType::IntervalYM
734
- OCI8::BindType::Mapping[:interval_ds] = OCI8::BindType::IntervalDS
735
- end
736
-
737
- # datatype type size prec scale
738
- # -------------------------------------------------
739
- # ROWID SQLT_RDD 4 0 0
740
- OCI8::BindType::Mapping[:rowid] = OCI8::BindType::String
741
-
742
- # datatype type size prec scale
743
- # -----------------------------------------------------
744
- # FLOAT SQLT_NUM 22 126 -127
745
- # FLOAT(1) SQLT_NUM 22 1 -127
746
- # FLOAT(126) SQLT_NUM 22 126 -127
747
- # DOUBLE PRECISION SQLT_NUM 22 126 -127
748
- # REAL SQLT_NUM 22 63 -127
749
- # NUMBER SQLT_NUM 22 0 0
750
- # NUMBER(1) SQLT_NUM 22 1 0
751
- # NUMBER(38) SQLT_NUM 22 38 0
752
- # NUMBER(1, 0) SQLT_NUM 22 1 0
753
- # NUMBER(38, 0) SQLT_NUM 22 38 0
754
- # NUMERIC SQLT_NUM 22 38 0
755
- # INT SQLT_NUM 22 38 0
756
- # INTEGER SQLT_NUM 22 38 0
757
- # SMALLINT SQLT_NUM 22 38 0
758
- OCI8::BindType::Mapping[:number] = OCI8::BindType::Number
759
-
760
- # mapping for calculated number values.
761
- #
762
- # for example:
763
- # select col1 * 1.1 from tab1;
764
- #
765
- # For Oracle 9.2.0.2 or below, this is also used for NUMBER
766
- # datatypes that have no explicit setting of their precision
767
- # and scale.
768
- #
769
- # The default mapping is Float for ruby-oci8 1.0. It is OraNumber
770
- # for ruby-oci8 2.0.
771
- OCI8::BindType::Mapping[:number_unknown_prec] = OCI8::BindType::OraNumber
772
-
773
- # mapping for number without precision and scale.
774
- #
775
- # for example:
776
- # create table tab1 (col1 number);
777
- # select col1 from tab1;
778
- #
779
- # note: This is available only on Oracle 9.2.0.3 or above.
780
- # see: Oracle 9.2.0.x Patch Set Notes.
781
- #
782
- # The default mapping is Float for ruby-oci8 1.0. It is OraNumber
783
- # for ruby-oci8 2.0.
784
- OCI8::BindType::Mapping[:number_no_prec_setting] = OCI8::BindType::OraNumber
785
-
786
- if defined? OCI8::BindType::BinaryDouble
787
- OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::BinaryDouble
788
- OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::BinaryDouble
789
- else
790
- OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::Float
791
- OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::Float
792
- end
793
-
794
- # Cursor
795
- OCI8::BindType::Mapping[:cursor] = OCI8::BindType::Cursor
796
-
797
- # XMLType (This mapping will be changed before release.)
798
- OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::Long
Binary file
Binary file
@@ -19,16 +19,25 @@ require "#{srcdir}/test_connstr"
19
19
  require "#{srcdir}/test_metadata"
20
20
  require "#{srcdir}/test_array_dml"
21
21
  require "#{srcdir}/test_rowid"
22
+ require "#{srcdir}/test_appinfo"
22
23
  require "#{srcdir}/test_oracle_version"
23
24
 
25
+ if OCI8.respond_to? :encoding
26
+ require "#{srcdir}/test_encoding"
27
+ end
28
+
24
29
  # Ruby/DBI
25
30
  begin
26
31
  require 'dbi'
27
- is_dbi_loaded = true
28
32
  rescue LoadError
29
- is_dbi_loaded = false
33
+ begin
34
+ require 'rubygems'
35
+ require 'dbi'
36
+ rescue LoadError
37
+ dbi_not_found = true
38
+ end
30
39
  end
31
- if is_dbi_loaded
40
+ unless dbi_not_found
32
41
  require "#{srcdir}/test_dbi"
33
42
  if $test_clob
34
43
  require "#{srcdir}/test_dbi_clob"
@@ -0,0 +1,29 @@
1
+ require 'oci8'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/config'
4
+
5
+ class TestAppInfo < Test::Unit::TestCase
6
+
7
+ def setup
8
+ @conn = get_oci8_connection
9
+ end
10
+
11
+ def test_set_client_identifier
12
+ # set client_id
13
+ client_id = "ruby-oci8:#{Process.pid()}"
14
+ @conn.client_identifier = client_id
15
+ assert_equal(client_id, @conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL")[0]);
16
+ # check the first character
17
+ assert_raise ArgumentError do
18
+ @conn.client_identifier = ':bad_identifier'
19
+ end
20
+
21
+ # clear client_id
22
+ @conn.client_identifier = nil
23
+ assert_nil(@conn.select_one("SELECT SYS_CONTEXT('USERENV', 'CLIENT_IDENTIFIER') FROM DUAL")[0]);
24
+ end
25
+
26
+ def teardown
27
+ @conn.logoff
28
+ end
29
+ end
@@ -252,7 +252,7 @@ EOS
252
252
 
253
253
  drop_table('test_table')
254
254
  @dbh.execute(<<-EOS)
255
- CREATE TABLE test_table (#{i = 0; coldef.collect do |c| i += 1; "C#{i} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')})
255
+ CREATE TABLE test_table (#{n = 0; coldef.collect do |c| n += 1; "C#{n} " + c[1] + (c[8] ? ' PRIMARY KEY' : ''); end.join(',')})
256
256
  STORAGE (
257
257
  INITIAL 100k
258
258
  NEXT 100k
@@ -0,0 +1,100 @@
1
+ require 'oci8'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/config'
4
+
5
+ class TestEncoding < Test::Unit::TestCase
6
+ def setup
7
+ @conn = get_oci8_connection
8
+ end
9
+
10
+ def test_select
11
+ drop_table('test_table')
12
+ @conn.exec(<<EOS)
13
+ CREATE TABLE test_table
14
+ (C CHAR(10),
15
+ V VARCHAR2(10),
16
+ R RAW(10),
17
+ LR LONG RAW,
18
+ CL CLOB,
19
+ NCL NCLOB,
20
+ BL BLOB)
21
+ STORAGE (
22
+ INITIAL 4k
23
+ NEXT 4k
24
+ MINEXTENTS 1
25
+ MAXEXTENTS UNLIMITED
26
+ PCTINCREASE 0)
27
+ EOS
28
+ ascii_8bit = Encoding.find('ASCII-8BIT')
29
+ @conn.exec(<<EOS)
30
+ INSERT INTO test_table VALUES ('abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd', 'abcd')
31
+ EOS
32
+ @conn.exec("SELECT * FROM test_table") do |row|
33
+ assert_equal('abcd ', row[0], 'CHAR(10)')
34
+ assert_equal(OCI8.encoding, row[0].encoding);
35
+ assert_equal('abcd', row[1], 'VARCHAR2(10)')
36
+ assert_equal(OCI8.encoding, row[1].encoding);
37
+ assert_equal("\xab\xcd", row[2], 'RAW(10)')
38
+ assert_equal(ascii_8bit, row[2].encoding);
39
+ assert_equal("\xab\xcd", row[3], 'LONG RAW')
40
+ assert_equal(ascii_8bit, row[3].encoding);
41
+ assert_equal('abcd', (data = row[4].read), 'CLOB')
42
+ assert_equal(OCI8.encoding, data.encoding);
43
+ assert_equal('abcd', (data = row[5].read), 'NCLOB')
44
+ assert_equal(OCI8.encoding, data.encoding);
45
+ assert_equal("\xab\xcd", (data = row[6].read), 'BLOB')
46
+ assert_equal(ascii_8bit, data.encoding);
47
+
48
+ if OCI8.encoding.name == "UTF-8"
49
+ utf_8 = "\u00A1\u00A2\u00A3\u00A4\u00A5\u00A6\u00A7\u00A8\u00A9"
50
+ iso_8859_1 = utf_8.encode("ISO-8859-1")
51
+ # CLOB
52
+ lob = row[4]
53
+ lob.rewind
54
+ lob.write(iso_8859_1) # converted to OCI8.encoding(UTF-8)
55
+ lob.rewind
56
+ assert_equal(utf_8, lob.read)
57
+ # NCLOB
58
+ lob = row[5]
59
+ lob.rewind
60
+ lob.write(iso_8859_1) # converted to OCI8.encoding(UTF-8)
61
+ lob.rewind
62
+ assert_equal(utf_8, lob.read)
63
+ # BLOB
64
+ lob = row[6]
65
+ lob.rewind
66
+ lob.write(iso_8859_1) # written without encoding conversion
67
+ lob.rewind
68
+ assert_equal(iso_8859_1.force_encoding('ASCII-8BIT'), lob.read)
69
+ end
70
+ end
71
+ drop_table('test_table')
72
+ end
73
+
74
+ if OCI8.encoding.name == "UTF-8"
75
+ def test_bind_string_with_code_conversion
76
+ drop_table('test_table')
77
+ @conn.exec(<<EOS)
78
+ CREATE TABLE test_table
79
+ (V VARCHAR2(3000))
80
+ STORAGE (
81
+ INITIAL 4k
82
+ NEXT 4k
83
+ MINEXTENTS 1
84
+ MAXEXTENTS UNLIMITED
85
+ PCTINCREASE 0)
86
+ EOS
87
+ utf_8 = "\u00A1" * 1500 # 3000 byte
88
+ iso_8859_1 = utf_8.encode("ISO-8859-1") # 1500 byte
89
+ @conn.exec("INSERT INTO test_table VALUES (:1)", iso_8859_1)
90
+ @conn.exec("SELECT * FROM test_table") do |row|
91
+ assert_equal(utf_8, row[0])
92
+ end
93
+ drop_table('test_table')
94
+ end
95
+ end
96
+
97
+ def teardown
98
+ @conn.logoff
99
+ end
100
+ end
@@ -1,6 +1,8 @@
1
1
  require 'oci8'
2
2
  require 'test/unit'
3
3
  require File.dirname(__FILE__) + '/config'
4
+ require 'bigdecimal'
5
+ require 'rational'
4
6
 
5
7
  class TestOCI8 < Test::Unit::TestCase
6
8
 
@@ -366,4 +368,39 @@ EOS
366
368
  drop_table('test_table')
367
369
  end
368
370
 
371
+ def test_bind_number_with_implicit_conversions
372
+ src = [1, 1.2, BigDecimal("1.2"), Rational(12, 10)]
373
+ int = [1, 1, 1, 1]
374
+ flt = [1, 1.2, 1.2, 1.2]
375
+
376
+ cursor = @conn.parse("begin :1 := :2; end;")
377
+
378
+ # Float
379
+ cursor.bind_param(1, nil, Float)
380
+ cursor.bind_param(2, nil, Float)
381
+ src.each_with_index do |s, idx|
382
+ cursor[2] = s
383
+ cursor.exec
384
+ assert_equal(cursor[1], flt[idx])
385
+ end
386
+
387
+ # Fixnum
388
+ cursor.bind_param(1, nil, Fixnum)
389
+ cursor.bind_param(2, nil, Fixnum)
390
+ src.each_with_index do |s, idx|
391
+ cursor[2] = s
392
+ cursor.exec
393
+ assert_equal(cursor[1], int[idx])
394
+ end
395
+
396
+ # Integer
397
+ cursor.bind_param(1, nil, Integer)
398
+ cursor.bind_param(2, nil, Integer)
399
+ src.each_with_index do |s, idx|
400
+ cursor[2] = s
401
+ cursor.exec
402
+ assert_equal(cursor[1], int[idx])
403
+ end
404
+ end
405
+
369
406
  end # TestOCI8
@@ -3,6 +3,8 @@ require 'oci8'
3
3
  require 'test/unit'
4
4
  require File.dirname(__FILE__) + '/config'
5
5
  require 'yaml'
6
+ require 'bigdecimal'
7
+ require 'rational'
6
8
 
7
9
  class TestOraNumber < Test::Unit::TestCase
8
10
 
@@ -480,4 +482,26 @@ class TestOraNumber < Test::Unit::TestCase
480
482
  assert_equal(expected_val, actual_val, x)
481
483
  end
482
484
  end
485
+
486
+ def test_new_from_bigdecimal
487
+ ["+Infinity", "-Infinity", "NaN"].each do |n|
488
+ assert_raise TypeError do
489
+ OraNumber.new(BigDecimal.new(n))
490
+ end
491
+ end
492
+
493
+ LARGE_RANGE_VALUES.each do |val|
494
+ assert_equal(val, OraNumber.new(BigDecimal.new(val)).to_s)
495
+ end
496
+ end
497
+
498
+ def test_new_from_rational
499
+ [
500
+ [Rational(1, 2), "0.5"],
501
+ [Rational(3, 5), "0.6"],
502
+ [Rational(10, 3), "3.3333333333333333333333333333333333333"],
503
+ ].each do |ary|
504
+ assert_equal(ary[1], OraNumber.new(ary[0]).to_s)
505
+ end
506
+ end
483
507
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-oci8
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: x86-mswin32-60
6
6
  authors:
7
7
  - KUBO Takehiro
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-03-18 00:00:00 +09:00
12
+ date: 2009-05-17 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -41,6 +41,7 @@ files:
41
41
  - lib/oci8.rb.in
42
42
  - lib/dbd/OCI8.rb
43
43
  - lib/oci8/.document
44
+ - lib/oci8/bindtype.rb
44
45
  - lib/oci8/compat.rb
45
46
  - lib/oci8/datetime.rb
46
47
  - lib/oci8/encoding-init.rb
@@ -52,12 +53,14 @@ files:
52
53
  - test/README
53
54
  - test/config.rb
54
55
  - test/test_all.rb
56
+ - test/test_appinfo.rb
55
57
  - test/test_array_dml.rb
56
58
  - test/test_bind_raw.rb
57
59
  - test/test_bind_time.rb
58
60
  - test/test_break.rb
59
61
  - test/test_clob.rb
60
62
  - test/test_connstr.rb
63
+ - test/test_encoding.rb
61
64
  - test/test_datetime.rb
62
65
  - test/test_dbi.rb
63
66
  - test/test_dbi_clob.rb