ruby-oci8-master 2.0.7

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 (84) hide show
  1. data/ChangeLog +2321 -0
  2. data/Makefile +88 -0
  3. data/NEWS +303 -0
  4. data/README +76 -0
  5. data/VERSION +1 -0
  6. data/dist-files +83 -0
  7. data/doc/api.en.html +527 -0
  8. data/doc/api.en.rd +554 -0
  9. data/doc/api.ja.html +525 -0
  10. data/doc/api.ja.rd +557 -0
  11. data/doc/manual.css +35 -0
  12. data/ext/oci8/.document +18 -0
  13. data/ext/oci8/MANIFEST +18 -0
  14. data/ext/oci8/apiwrap.c.tmpl +182 -0
  15. data/ext/oci8/apiwrap.h.tmpl +61 -0
  16. data/ext/oci8/apiwrap.rb +91 -0
  17. data/ext/oci8/apiwrap.yml +1455 -0
  18. data/ext/oci8/attr.c +105 -0
  19. data/ext/oci8/bind.c +366 -0
  20. data/ext/oci8/connection_pool.c +199 -0
  21. data/ext/oci8/encoding.c +289 -0
  22. data/ext/oci8/env.c +178 -0
  23. data/ext/oci8/error.c +378 -0
  24. data/ext/oci8/extconf.rb +179 -0
  25. data/ext/oci8/lob.c +805 -0
  26. data/ext/oci8/metadata.c +232 -0
  27. data/ext/oci8/object.c +727 -0
  28. data/ext/oci8/oci8.c +1156 -0
  29. data/ext/oci8/oci8.h +574 -0
  30. data/ext/oci8/oci8lib.c +527 -0
  31. data/ext/oci8/ocidatetime.c +484 -0
  32. data/ext/oci8/ocihandle.c +751 -0
  33. data/ext/oci8/ocinumber.c +1612 -0
  34. data/ext/oci8/oraconf.rb +1119 -0
  35. data/ext/oci8/oradate.c +611 -0
  36. data/ext/oci8/oranumber_util.c +352 -0
  37. data/ext/oci8/oranumber_util.h +24 -0
  38. data/ext/oci8/post-config.rb +5 -0
  39. data/ext/oci8/stmt.c +673 -0
  40. data/ext/oci8/thread_util.c +85 -0
  41. data/ext/oci8/thread_util.h +30 -0
  42. data/ext/oci8/win32.c +137 -0
  43. data/lib/.document +1 -0
  44. data/lib/dbd/OCI8.rb +591 -0
  45. data/lib/oci8.rb.in +94 -0
  46. data/lib/oci8/.document +8 -0
  47. data/lib/oci8/bindtype.rb +349 -0
  48. data/lib/oci8/compat.rb +113 -0
  49. data/lib/oci8/connection_pool.rb +99 -0
  50. data/lib/oci8/datetime.rb +611 -0
  51. data/lib/oci8/encoding-init.rb +74 -0
  52. data/lib/oci8/encoding.yml +537 -0
  53. data/lib/oci8/metadata.rb +2132 -0
  54. data/lib/oci8/object.rb +581 -0
  55. data/lib/oci8/oci8.rb +721 -0
  56. data/lib/oci8/ocihandle.rb +425 -0
  57. data/lib/oci8/oracle_version.rb +144 -0
  58. data/lib/oci8/properties.rb +73 -0
  59. data/metaconfig +142 -0
  60. data/pre-distclean.rb +7 -0
  61. data/ruby-oci8.gemspec +63 -0
  62. data/setup.rb +1331 -0
  63. data/test/README +4 -0
  64. data/test/config.rb +122 -0
  65. data/test/test_all.rb +51 -0
  66. data/test/test_appinfo.rb +63 -0
  67. data/test/test_array_dml.rb +333 -0
  68. data/test/test_bind_raw.rb +46 -0
  69. data/test/test_bind_time.rb +178 -0
  70. data/test/test_break.rb +96 -0
  71. data/test/test_clob.rb +82 -0
  72. data/test/test_connstr.rb +81 -0
  73. data/test/test_datetime.rb +582 -0
  74. data/test/test_dbi.rb +366 -0
  75. data/test/test_dbi_clob.rb +53 -0
  76. data/test/test_encoding.rb +100 -0
  77. data/test/test_error.rb +88 -0
  78. data/test/test_metadata.rb +1399 -0
  79. data/test/test_oci8.rb +434 -0
  80. data/test/test_oracle_version.rb +70 -0
  81. data/test/test_oradate.rb +256 -0
  82. data/test/test_oranumber.rb +746 -0
  83. data/test/test_rowid.rb +33 -0
  84. metadata +137 -0
@@ -0,0 +1,94 @@
1
+
2
+ # --*- ruby -*--
3
+ # This is based on yoshidam's oracle.rb.
4
+ #
5
+ # sample one liner:
6
+ # ruby -r oci8 -e 'OCI8.new("scott", "tiger", nil).exec("select * from emp") do |r| puts r.join(","); end'
7
+ # # select all data from emp and print them as CVS format.
8
+
9
+ if RUBY_PLATFORM =~ /cygwin/
10
+ # Cygwin manages environment variables by itself.
11
+ # They don't synchroize with Win32's ones.
12
+ # This set some Oracle's environment variables to win32's enviroment.
13
+ require 'Win32API'
14
+ win32setenv = Win32API.new('Kernel32.dll', 'SetEnvironmentVariableA', 'PP', 'I')
15
+ ['NLS_LANG', 'ORA_NLS10', 'ORA_NLS32', 'ORA_NLS33', 'ORACLE_BASE', 'ORACLE_HOME', 'ORACLE_SID', 'TNS_ADMIN', 'LOCAL'].each do |name|
16
+ val = ENV[name]
17
+ win32setenv.call(name, val && val.dup)
18
+ end
19
+ end
20
+
21
+ so_basename = 'oci8lib_'
22
+ if defined? RUBY_ENGINE and RUBY_ENGINE != 'ruby'
23
+ so_basename += RUBY_ENGINE
24
+ end
25
+
26
+ # The suffix number indicates the ruby API version.
27
+ # 18 - ruby 1.8.x
28
+ # 191 - ruby 1.9.1 and 1.9.2
29
+ # 19x - ruby 1.9.x future version which will break the API compatibility
30
+ case RUBY_VERSION
31
+ when /^1\.9/
32
+ so_basename += '191'
33
+ when /^1\.8/
34
+ so_basename += '18'
35
+ else
36
+ raise 'unsupported ruby version: ' + RUBY_VERSION
37
+ end
38
+ require so_basename
39
+
40
+ if OCI8::VERSION != '@@OCI8_MODULE_VERSION@@'
41
+ require 'rbconfig'
42
+ so_name = so_basename + "." + Config::CONFIG['DLEXT']
43
+ raise "VERSION MISMATCH! #{so_name} version is #{OCI8::VERSION}, but oci8.rb version is @@OCI8_MODULE_VERSION@@."
44
+ end
45
+
46
+ require 'oci8/encoding-init.rb'
47
+ require 'oci8/oracle_version.rb'
48
+
49
+ class OCI8
50
+ ORAVER_8_0 = OCI8::OracleVersion.new(8, 0)
51
+ ORAVER_8_1 = OCI8::OracleVersion.new(8, 1)
52
+ ORAVER_9_0 = OCI8::OracleVersion.new(9, 0)
53
+ ORAVER_9_2 = OCI8::OracleVersion.new(9, 2)
54
+ ORAVER_10_1 = OCI8::OracleVersion.new(10, 1)
55
+ ORAVER_10_2 = OCI8::OracleVersion.new(10, 2)
56
+ ORAVER_11_1 = OCI8::OracleVersion.new(11, 1)
57
+
58
+ @@oracle_client_version = OCI8::OracleVersion.new(self.oracle_client_vernum)
59
+
60
+ # :call-seq:
61
+ # OCI8.oracle_client_version -> oraver
62
+ #
63
+ # Returns an OCI8::OracleVersion of the Oracle client version.
64
+ #
65
+ # If this library is configured without '--with-runtime-check',
66
+ # and compiled for Oracle 10.1 or lower, the major and minor
67
+ # numbers are determined at compile-time. The rests are zeros.
68
+ #
69
+ # If this library is configured with '--with-runtime-check'
70
+ # and the runtime Oracle library is Oracle 10.1 or lower, the
71
+ # major and minor numbers are determined at run-time. The
72
+ # rests are zeros.
73
+ #
74
+ # Otherwise, it is the version retrieved from an OCI function
75
+ # OCIClientVersion().
76
+ def self.oracle_client_version
77
+ @@oracle_client_version
78
+ end
79
+
80
+ # defined for backward compatibility.
81
+ CLIENT_VERSION = @@oracle_client_version.major.to_s +
82
+ @@oracle_client_version.minor.to_s +
83
+ @@oracle_client_version.update.to_s
84
+ end
85
+
86
+ require 'oci8/ocihandle.rb'
87
+ require 'oci8/datetime.rb'
88
+ require 'oci8/oci8.rb'
89
+ require 'oci8/bindtype.rb'
90
+ require 'oci8/metadata.rb'
91
+ require 'oci8/compat.rb'
92
+ require 'oci8/object.rb'
93
+ require 'oci8/connection_pool.rb'
94
+ require 'oci8/properties.rb'
@@ -0,0 +1,8 @@
1
+ datetime.rb
2
+ object.rb
3
+ metadata.rb
4
+ oracle_version.rb
5
+ oci8.rb
6
+ ocihandle.rb
7
+ connection_pool.rb
8
+ properties.rb
@@ -0,0 +1,349 @@
1
+ #--
2
+ # bindtype.rb -- OCI8::BindType
3
+ #
4
+ # Copyright (C) 2009-2011 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
+ class BigDecimal < OCI8::BindType::OraNumber
28
+ @@bigdecimal_is_required = false
29
+ def get()
30
+ unless @@bigdecimal_is_required
31
+ require 'bigdecimal'
32
+ @@bigdecimal_is_required = true
33
+ end
34
+ (val = super()) && val.to_d
35
+ end
36
+ end
37
+
38
+ class Rational < OCI8::BindType::OraNumber
39
+ @@rational_is_required = false
40
+ def get()
41
+ unless @@rational_is_required
42
+ require 'rational'
43
+ @@rational_is_required = true
44
+ end
45
+ (val = super()) && val.to_r
46
+ end
47
+ end
48
+
49
+ class BasicNumberType < OCI8::BindType::OraNumber
50
+ def get()
51
+ (val = super()) && (val.has_decimal_part? ? val.to_f : val.to_i)
52
+ end
53
+ end
54
+
55
+ # get/set Number (for OCI8::SQLT_NUM)
56
+ class Number
57
+ def self.create(con, val, param, max_array_size)
58
+ if param.is_a? OCI8::Metadata::Base
59
+ precision = param.precision
60
+ scale = param.scale
61
+ end
62
+ if scale == -127
63
+ if precision == 0
64
+ # NUMBER declared without its scale and precision. (Oracle 9.2.0.3 or above)
65
+ klass = OCI8::BindType::Mapping[:number_no_prec_setting]
66
+ else
67
+ # FLOAT or FLOAT(p)
68
+ klass = OCI8::BindType::Float
69
+ end
70
+ elsif scale == 0
71
+ if precision == 0
72
+ # NUMBER whose scale and precision is unknown
73
+ # or
74
+ # NUMBER declared without its scale and precision. (Oracle 9.2.0.2 or below)
75
+ klass = OCI8::BindType::Mapping[:number_unknown_prec]
76
+ else
77
+ # NUMBER(p, 0)
78
+ klass = OCI8::BindType::Integer
79
+ end
80
+ else
81
+ # NUMBER(p, s)
82
+ if precision < 15 # the precision of double.
83
+ klass = OCI8::BindType::Float
84
+ else
85
+ # use BigDecimal instead
86
+ klass = OCI8::BindType::BigDecimal
87
+ end
88
+ end
89
+ klass.new(con, val, nil, max_array_size)
90
+ end
91
+ end
92
+
93
+ class String
94
+ # 1333 <= ceil(4000 / 3). 4000 is max size of char. 3 is NLS ratio of UTF-8.
95
+ @@minimum_bind_length = 1333
96
+
97
+ def self.minimum_bind_length
98
+ @@minimum_bind_length
99
+ end
100
+
101
+ def self.minimum_bind_length=(val)
102
+ @@minimum_bind_length = val
103
+ end
104
+
105
+ def self.create(con, val, param, max_array_size)
106
+ case param
107
+ when Hash
108
+ param[:length_semantics] = OCI8::properties[:length_semantics] unless param.has_key? :length_semantics
109
+ unless param[:length]
110
+ if val.respond_to? :to_str
111
+ val = val.to_str
112
+ if param[:length_semantics] == :char
113
+ # character semantics
114
+ param[:length] = val.size
115
+ else
116
+ # byte semantics
117
+ if OCI8.respond_to? :encoding and OCI8.encoding != val.encoding
118
+ # If the string encoding is different with NLS_LANG character set,
119
+ # convert it to get the length.
120
+ val = val.encode(OCI8.encoding)
121
+ end
122
+ if val.respond_to? :bytesize
123
+ # ruby 1.8.7 or upper
124
+ param[:length] = val.bytesize
125
+ else
126
+ # ruby 1.8.6 or lower
127
+ param[:length] = val.size
128
+ end
129
+ end
130
+ else
131
+ param[:length] = @@minimum_bind_length
132
+ end
133
+ end
134
+ # use the default value when :nchar is not set explicitly.
135
+ param[:nchar] = OCI8.properties[:bind_string_as_nchar] unless param.has_key?(:nchar)
136
+ when OCI8::Metadata::Base
137
+ case param.data_type
138
+ when :char, :varchar2
139
+ length_semantics = OCI8.properties[:length_semantics]
140
+ if length_semantics == :char
141
+ length = param.char_size
142
+ else
143
+ length = param.data_size * OCI8.nls_ratio
144
+ end
145
+ param = {
146
+ :length => length,
147
+ :length_semantics => length_semantics,
148
+ :nchar => (param.charset_form == :nchar),
149
+ }
150
+ when :raw
151
+ # HEX needs twice space.
152
+ param = {:length => param.data_size * 2}
153
+ else
154
+ param = {:length => @@minimum_bind_length}
155
+ end
156
+ end
157
+ self.new(con, val, param, max_array_size)
158
+ end
159
+ end
160
+
161
+ class RAW
162
+ def self.create(con, val, param, max_array_size)
163
+ case param
164
+ when Hash
165
+ unless param[:length]
166
+ if val.respond_to? :to_str
167
+ val = val.to_str
168
+ if val.respond_to? :bytesize
169
+ param[:length] = val.bytesize
170
+ else
171
+ param[:length] = val.size
172
+ end
173
+ else
174
+ param[:length] = 400
175
+ end
176
+ end
177
+ when OCI8::Metadata::Base
178
+ param = {:length => param.data_size}
179
+ end
180
+ self.new(con, val, param, max_array_size)
181
+ end
182
+ end
183
+
184
+ class Long < OCI8::BindType::String
185
+ def self.create(con, val, param, max_array_size)
186
+ param = {:length => con.long_read_len, :char_semantics => true}
187
+ super(con, val, param, max_array_size)
188
+ end
189
+ end
190
+
191
+ class LongRaw < OCI8::BindType::RAW
192
+ def self.create(con, val, param, max_array_size)
193
+ param = {:length => con.long_read_len, :char_semantics => false}
194
+ self.new(con, val, param, max_array_size)
195
+ end
196
+ end
197
+
198
+ class CLOB
199
+ def self.create(con, val, param, max_array_size)
200
+ if param.is_a? OCI8::Metadata::Base and param.charset_form == :nchar
201
+ OCI8::BindType::NCLOB.new(con, val, nil, max_array_size)
202
+ else
203
+ OCI8::BindType::CLOB.new(con, val, nil, max_array_size)
204
+ end
205
+ end
206
+ end
207
+ end # BindType
208
+ end
209
+
210
+ # bind or explicitly define
211
+ OCI8::BindType::Mapping[String] = OCI8::BindType::String
212
+ OCI8::BindType::Mapping[OraNumber] = OCI8::BindType::OraNumber
213
+ OCI8::BindType::Mapping['BigDecimal'] = OCI8::BindType::BigDecimal
214
+ OCI8::BindType::Mapping['Rational'] = OCI8::BindType::Rational
215
+ OCI8::BindType::Mapping[Fixnum] = OCI8::BindType::Integer
216
+ OCI8::BindType::Mapping[Float] = OCI8::BindType::Float
217
+ OCI8::BindType::Mapping[Integer] = OCI8::BindType::Integer
218
+ OCI8::BindType::Mapping[Bignum] = OCI8::BindType::Integer
219
+ OCI8::BindType::Mapping[OraDate] = OCI8::BindType::OraDate
220
+ OCI8::BindType::Mapping[Time] = OCI8::BindType::Time
221
+ OCI8::BindType::Mapping[Date] = OCI8::BindType::Date
222
+ OCI8::BindType::Mapping[DateTime] = OCI8::BindType::DateTime
223
+ OCI8::BindType::Mapping[OCI8::CLOB] = OCI8::BindType::CLOB
224
+ OCI8::BindType::Mapping[OCI8::NCLOB] = OCI8::BindType::NCLOB
225
+ OCI8::BindType::Mapping[OCI8::BLOB] = OCI8::BindType::BLOB
226
+ OCI8::BindType::Mapping[OCI8::BFILE] = OCI8::BindType::BFILE
227
+ OCI8::BindType::Mapping[OCI8::Cursor] = OCI8::BindType::Cursor
228
+
229
+ # implicitly define
230
+
231
+ # datatype type size prec scale
232
+ # -------------------------------------------------
233
+ # CHAR(1) SQLT_AFC 1 0 0
234
+ # CHAR(10) SQLT_AFC 10 0 0
235
+ OCI8::BindType::Mapping[:char] = OCI8::BindType::String
236
+
237
+ # datatype type size prec scale
238
+ # -------------------------------------------------
239
+ # VARCHAR(1) SQLT_CHR 1 0 0
240
+ # VARCHAR(10) SQLT_CHR 10 0 0
241
+ # VARCHAR2(1) SQLT_CHR 1 0 0
242
+ # VARCHAR2(10) SQLT_CHR 10 0 0
243
+ OCI8::BindType::Mapping[:varchar2] = OCI8::BindType::String
244
+
245
+ # datatype type size prec scale
246
+ # -------------------------------------------------
247
+ # RAW(1) SQLT_BIN 1 0 0
248
+ # RAW(10) SQLT_BIN 10 0 0
249
+ OCI8::BindType::Mapping[:raw] = OCI8::BindType::RAW
250
+
251
+ # datatype type size prec scale
252
+ # -------------------------------------------------
253
+ # LONG SQLT_LNG 0 0 0
254
+ OCI8::BindType::Mapping[:long] = OCI8::BindType::Long
255
+
256
+ # datatype type size prec scale
257
+ # -------------------------------------------------
258
+ # LONG RAW SQLT_LBI 0 0 0
259
+ OCI8::BindType::Mapping[:long_raw] = OCI8::BindType::LongRaw
260
+
261
+ # datatype type size prec scale
262
+ # -------------------------------------------------
263
+ # CLOB SQLT_CLOB 4000 0 0
264
+ OCI8::BindType::Mapping[:clob] = OCI8::BindType::CLOB
265
+ OCI8::BindType::Mapping[:nclob] = OCI8::BindType::NCLOB
266
+
267
+ # datatype type size prec scale
268
+ # -------------------------------------------------
269
+ # BLOB SQLT_BLOB 4000 0 0
270
+ OCI8::BindType::Mapping[:blob] = OCI8::BindType::BLOB
271
+
272
+ # datatype type size prec scale
273
+ # -------------------------------------------------
274
+ # BFILE SQLT_BFILE 4000 0 0
275
+ OCI8::BindType::Mapping[:bfile] = OCI8::BindType::BFILE
276
+
277
+ # datatype type size prec scale
278
+ # -------------------------------------------------
279
+ # DATE SQLT_DAT 7 0 0
280
+ OCI8::BindType::Mapping[:date] = OCI8::BindType::Time
281
+
282
+ OCI8::BindType::Mapping[:timestamp] = OCI8::BindType::Time
283
+ OCI8::BindType::Mapping[:timestamp_tz] = OCI8::BindType::Time
284
+ OCI8::BindType::Mapping[:timestamp_ltz] = OCI8::BindType::Time
285
+ OCI8::BindType::Mapping[:interval_ym] = OCI8::BindType::IntervalYM
286
+ OCI8::BindType::Mapping[:interval_ds] = OCI8::BindType::IntervalDS
287
+
288
+ # datatype type size prec scale
289
+ # -------------------------------------------------
290
+ # ROWID SQLT_RDD 4 0 0
291
+ OCI8::BindType::Mapping[:rowid] = OCI8::BindType::String
292
+
293
+ # datatype type size prec scale
294
+ # -----------------------------------------------------
295
+ # FLOAT SQLT_NUM 22 126 -127
296
+ # FLOAT(1) SQLT_NUM 22 1 -127
297
+ # FLOAT(126) SQLT_NUM 22 126 -127
298
+ # DOUBLE PRECISION SQLT_NUM 22 126 -127
299
+ # REAL SQLT_NUM 22 63 -127
300
+ # NUMBER SQLT_NUM 22 0 0
301
+ # NUMBER(1) SQLT_NUM 22 1 0
302
+ # NUMBER(38) SQLT_NUM 22 38 0
303
+ # NUMBER(1, 0) SQLT_NUM 22 1 0
304
+ # NUMBER(38, 0) SQLT_NUM 22 38 0
305
+ # NUMERIC SQLT_NUM 22 38 0
306
+ # INT SQLT_NUM 22 38 0
307
+ # INTEGER SQLT_NUM 22 38 0
308
+ # SMALLINT SQLT_NUM 22 38 0
309
+ OCI8::BindType::Mapping[:number] = OCI8::BindType::Number
310
+
311
+ # mapping for calculated number values.
312
+ #
313
+ # for example:
314
+ # select col1 * 1.1 from tab1;
315
+ #
316
+ # For Oracle 9.2.0.2 or below, this is also used for NUMBER
317
+ # datatypes that have no explicit setting of their precision
318
+ # and scale.
319
+ #
320
+ # The default mapping is Float for ruby-oci8 1.0, OraNumber for 2.0.0 ~ 2.0.2,
321
+ # BigDecimal for 2.0.3 ~.
322
+ OCI8::BindType::Mapping[:number_unknown_prec] = OCI8::BindType::BigDecimal
323
+
324
+ # mapping for number without precision and scale.
325
+ #
326
+ # for example:
327
+ # create table tab1 (col1 number);
328
+ # select col1 from tab1;
329
+ #
330
+ # note: This is available only on Oracle 9.2.0.3 or above.
331
+ # see: Oracle 9.2.0.x Patch Set Notes.
332
+ #
333
+ # The default mapping is Float for ruby-oci8 1.0, OraNumber for 2.0.0 ~ 2.0.2,
334
+ # BigDecimal for 2.0.3 ~.
335
+ OCI8::BindType::Mapping[:number_no_prec_setting] = OCI8::BindType::BigDecimal
336
+
337
+ if defined? OCI8::BindType::BinaryDouble
338
+ OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::BinaryDouble
339
+ OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::BinaryDouble
340
+ else
341
+ OCI8::BindType::Mapping[:binary_float] = OCI8::BindType::Float
342
+ OCI8::BindType::Mapping[:binary_double] = OCI8::BindType::Float
343
+ end
344
+
345
+ # Cursor
346
+ OCI8::BindType::Mapping[:cursor] = OCI8::BindType::Cursor
347
+
348
+ # XMLType (This mapping will be changed before release.)
349
+ OCI8::BindType::Mapping[:xmltype] = OCI8::BindType::Long