ruby-oci8 2.1.0-x86-mingw32 → 2.1.1-x86-mingw32
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.
- data/.yardopts +13 -0
- data/ChangeLog +104 -0
- data/NEWS +337 -235
- data/README.md +38 -0
- data/VERSION +1 -1
- data/dist-files +7 -6
- data/docs/install-binary-package.md +40 -0
- data/docs/install-full-client.md +116 -0
- data/docs/install-instant-client.md +167 -0
- data/docs/platform-specific-issues.md +209 -0
- data/docs/report-installation-issue.md +50 -0
- data/lib/oci8.rb +2 -2
- data/lib/oci8/bindtype.rb +1 -0
- data/lib/oci8/connection_pool.rb +1 -0
- data/lib/oci8/encoding-init.rb +1 -0
- data/lib/oci8/object.rb +29 -4
- data/lib/oci8/oci8.rb +75 -17
- data/lib/oci8/ocihandle.rb +192 -12
- data/lib/oci8/oracle_version.rb +47 -41
- data/lib/oci8/properties.rb +19 -0
- data/lib/oci8lib_18.map +1134 -0
- data/lib/oci8lib_18.so +0 -0
- data/lib/oci8lib_191.map +1201 -0
- data/lib/oci8lib_191.so +0 -0
- data/pre-distclean.rb +2 -2
- data/ruby-oci8.gemspec +7 -3
- data/test/config.rb +1 -6
- data/test/test_datetime.rb +70 -32
- data/test/test_oci8.rb +8 -2
- metadata +17 -14
- data/README +0 -5
- data/doc/api.en.html +0 -527
- data/doc/api.en.rd +0 -554
- data/doc/api.ja.html +0 -525
- data/doc/api.ja.rd +0 -557
- data/doc/manual.css +0 -35
data/lib/oci8lib_191.so
CHANGED
Binary file
|
data/pre-distclean.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
rm_f "#{curr_objdir}/lib/oci8.rb"
|
2
|
+
rm_f "#{curr_objdir}/ext/oci8/oci8lib_18.map"
|
3
|
+
rm_f "#{curr_objdir}/ext/oci8/oci8lib_191.map"
|
2
4
|
if RUBY_PLATFORM =~ /cygwin/
|
3
5
|
rm_f "#{curr_objdir}/ext/oci8/OCI.def"
|
4
6
|
rm_f "#{curr_objdir}/ext/oci8/libOCI.a"
|
5
|
-
else
|
6
|
-
rm_f "#{curr_objdir}/ext/oci8/oracle_objs.a"
|
7
7
|
end
|
data/ruby-oci8.gemspec
CHANGED
@@ -31,7 +31,7 @@ spec = Gem::Specification.new do |s|
|
|
31
31
|
s.description = <<EOS
|
32
32
|
ruby-oci8 is a ruby interface for Oracle using OCI8 API. It is available with Oracle8, Oracle8i, Oracle9i, Oracle10g and Oracle Instant Client.
|
33
33
|
EOS
|
34
|
-
s.has_rdoc =
|
34
|
+
s.has_rdoc = 'yard'
|
35
35
|
s.authors = ['KUBO Takehiro']
|
36
36
|
s.platform = gem_platform
|
37
37
|
files = File.read('dist-files').split("\n")
|
@@ -54,6 +54,10 @@ EOS
|
|
54
54
|
else
|
55
55
|
raise "No compiled binary are found. Run make in advance."
|
56
56
|
end
|
57
|
+
# add map files to analyze a core (minidump) file.
|
58
|
+
so_files << 'ext/oci8/oci8lib_18.map' if has_1_8 and File.exists? 'ext/oci8/oci8lib_18.map'
|
59
|
+
so_files << 'ext/oci8/oci8lib_191.map' if has_1_9_1 and File.exists? 'ext/oci8/oci8lib_191.map'
|
60
|
+
|
57
61
|
FileUtils.copy so_files, 'lib', :preserve => true
|
58
62
|
files.reject! do |fname|
|
59
63
|
fname =~ /^ext/
|
@@ -63,8 +67,8 @@ EOS
|
|
63
67
|
end
|
64
68
|
files << 'lib/oci8.rb'
|
65
69
|
end
|
70
|
+
s.require_paths = ['lib', 'ext/oci8']
|
66
71
|
s.files = files
|
67
72
|
s.test_files = 'test/test_all.rb'
|
68
|
-
s.
|
69
|
-
s.extra_rdoc_files = ['README']
|
73
|
+
s.extra_rdoc_files = ['README.md']
|
70
74
|
end
|
data/test/config.rb
CHANGED
@@ -13,12 +13,7 @@ ENV['ORA_NCHAR_LITERAL_REPLACE'] = 'TRUE' if OCI8.client_charset_name.include? '
|
|
13
13
|
nls_lang = ENV['NLS_LANG']
|
14
14
|
nls_lang = nls_lang.split('.')[1] unless nls_lang.nil?
|
15
15
|
nls_lang = nls_lang.upcase unless nls_lang.nil?
|
16
|
-
|
17
|
-
when 'JA16EUC'
|
18
|
-
$lobfile = File.dirname(__FILE__) + '/../doc/api.ja.rd' # EUC-JP file
|
19
|
-
else
|
20
|
-
$lobfile = File.dirname(__FILE__) + '/../doc/api.en.rd' # ASCII file
|
21
|
-
end
|
16
|
+
$lobfile = File.dirname(__FILE__) + '/../setup.rb'
|
22
17
|
$lobreadnum = 256 # counts in charactors
|
23
18
|
|
24
19
|
# don't modify below.
|
data/test/test_datetime.rb
CHANGED
@@ -13,15 +13,22 @@ class TestDateTime < Test::Unit::TestCase
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
+
@@time_new_accepts_timezone = begin
|
17
|
+
Time.new(2001, 1, 1, 0, 0, 0, '+00:00')
|
18
|
+
true
|
19
|
+
rescue
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
16
23
|
def string_to_time(str)
|
17
|
-
/(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?([+-]\d
|
24
|
+
/(\d+)-(\d+)-(\d+) ?(?:(\d+):(\d+):(\d+))?(?:\.(\d+))? ?(([+-])(\d+):(\d+))?/ =~ str
|
18
25
|
args = []
|
19
26
|
args << $1.to_i # year
|
20
27
|
args << $2.to_i # month
|
21
28
|
args << $3.to_i # day
|
22
29
|
args << $4.to_i if $4 # hour
|
23
30
|
args << $5.to_i if $5 # minute
|
24
|
-
if $8
|
31
|
+
if $8 and @@time_new_accepts_timezone
|
25
32
|
args << $6.to_i + $7.to_i.to_r / ('1' + '0' * ($7.length)).to_i
|
26
33
|
args << $8
|
27
34
|
Time.new(*args)
|
@@ -32,15 +39,37 @@ class TestDateTime < Test::Unit::TestCase
|
|
32
39
|
if $7
|
33
40
|
args << $7.to_i.to_r * 1000000 / ('1' + '0' * ($7.length)).to_i
|
34
41
|
end
|
35
|
-
|
36
|
-
|
42
|
+
if $8
|
43
|
+
# with time zone
|
44
|
+
offset = ($9 + '1').to_i * ($10.to_i * 60 + $11.to_i)
|
45
|
+
if offset == 0
|
46
|
+
Time.utc(*args)
|
47
|
+
else
|
48
|
+
tm = Time.local(*args)
|
49
|
+
raise "Failed to convert #{str} to Time" if tm.utc_offset != offset * 60
|
50
|
+
tm
|
51
|
+
end
|
52
|
+
else
|
53
|
+
# without time zone
|
54
|
+
Time.local(*args)
|
55
|
+
end
|
37
56
|
end
|
38
57
|
#Time.local(*str.split(/[- :\.]/).collect do |n| n.to_i; end)
|
39
58
|
end
|
40
59
|
|
60
|
+
def string_to_datetime(str)
|
61
|
+
/(\d+-\d+-\d+ ?(?:\d+:\d+:\d+)?(?:\.\d+)?) ?([+-]\d+:\d+)?/ =~ str
|
62
|
+
if $2
|
63
|
+
# with time zone
|
64
|
+
DateTime.parse(str)
|
65
|
+
else
|
66
|
+
tm = string_to_time(str)
|
67
|
+
DateTime.parse(str + timezone_string(*((tm.utc_offset / 60).divmod 60)))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
41
71
|
def setup
|
42
72
|
@conn = get_oci8_connection
|
43
|
-
@local_timezone = timezone_string(*((::Time.now.utc_offset / 60).divmod 60))
|
44
73
|
end
|
45
74
|
|
46
75
|
def teardown
|
@@ -48,7 +77,8 @@ class TestDateTime < Test::Unit::TestCase
|
|
48
77
|
end
|
49
78
|
|
50
79
|
def test_date_select
|
51
|
-
['2005-
|
80
|
+
['2005-06-01 00:00:00',
|
81
|
+
'2005-12-31 23:59:59',
|
52
82
|
'2006-01-01 00:00:00'].each do |date|
|
53
83
|
@conn.exec(<<-EOS) do |row|
|
54
84
|
SELECT TO_DATE('#{date}', 'YYYY-MM-DD HH24:MI:SS') FROM dual
|
@@ -66,11 +96,12 @@ END;
|
|
66
96
|
EOS
|
67
97
|
cursor.bind_param(:out, nil, DateTime)
|
68
98
|
cursor.bind_param(:in, nil, String, 36)
|
69
|
-
['2005-
|
99
|
+
['2005-06-01 00:00:00',
|
100
|
+
'2005-12-31 23:59:59',
|
70
101
|
'2006-01-01 00:00:00'].each do |date|
|
71
102
|
cursor[:in] = date
|
72
103
|
cursor.exec
|
73
|
-
assert_equal(
|
104
|
+
assert_equal(string_to_datetime(date), cursor[:out])
|
74
105
|
end
|
75
106
|
cursor.close
|
76
107
|
end
|
@@ -86,9 +117,10 @@ END;
|
|
86
117
|
EOS
|
87
118
|
cursor.bind_param(:out, nil, String, 33)
|
88
119
|
cursor.bind_param(:in, nil, DateTime)
|
89
|
-
['2005-
|
120
|
+
['2005-06-01 00:00:00',
|
121
|
+
'2005-12-31 23:59:59',
|
90
122
|
'2006-01-01 00:00:00'].each do |date|
|
91
|
-
cursor[:in] =
|
123
|
+
cursor[:in] = string_to_datetime(date)
|
92
124
|
cursor.exec
|
93
125
|
assert_equal(date, cursor[:out])
|
94
126
|
end
|
@@ -96,7 +128,8 @@ EOS
|
|
96
128
|
end
|
97
129
|
|
98
130
|
def test_timestamp_select
|
99
|
-
['2005-
|
131
|
+
['2005-06-01 00:00:00.999999000',
|
132
|
+
'2005-12-31 23:59:59.999999000',
|
100
133
|
'2006-01-01 00:00:00.000000000'].each do |date|
|
101
134
|
@conn.exec(<<-EOS) do |row|
|
102
135
|
SELECT TO_TIMESTAMP('#{date}', 'YYYY-MM-DD HH24:MI:SS.FF') FROM dual
|
@@ -114,11 +147,12 @@ END;
|
|
114
147
|
EOS
|
115
148
|
cursor.bind_param(:out, nil, DateTime)
|
116
149
|
cursor.bind_param(:in, nil, String, 36)
|
117
|
-
['2005-
|
150
|
+
['2005-06-01 00:00:00.999999000',
|
151
|
+
'2005-12-31 23:59:59.999999000',
|
118
152
|
'2006-01-01 00:00:00.000000000'].each do |date|
|
119
153
|
cursor[:in] = date
|
120
154
|
cursor.exec
|
121
|
-
assert_equal(
|
155
|
+
assert_equal(string_to_datetime(date), cursor[:out])
|
122
156
|
end
|
123
157
|
cursor.close
|
124
158
|
end
|
@@ -131,9 +165,10 @@ END;
|
|
131
165
|
EOS
|
132
166
|
cursor.bind_param(:out, nil, String, 33)
|
133
167
|
cursor.bind_param(:in, nil, DateTime)
|
134
|
-
['2005-
|
168
|
+
['2005-06-01 00:00:00.999999000',
|
169
|
+
'2005-12-31 23:59:59.999999000',
|
135
170
|
'2006-01-01 00:00:00.000000000'].each do |date|
|
136
|
-
cursor[:in] =
|
171
|
+
cursor[:in] = string_to_datetime(date)
|
137
172
|
cursor.exec
|
138
173
|
assert_equal(date, cursor[:out])
|
139
174
|
end
|
@@ -141,7 +176,8 @@ EOS
|
|
141
176
|
end
|
142
177
|
|
143
178
|
def test_timestamp_tz_select
|
144
|
-
['2005-
|
179
|
+
['2005-06-01 00:00:00.999999000 +00:00',
|
180
|
+
'2005-12-31 23:59:59.999999000 +08:30',
|
145
181
|
'2006-01-01 00:00:00.000000000 -08:30'].each do |date|
|
146
182
|
@conn.exec(<<-EOS) do |row|
|
147
183
|
SELECT TO_TIMESTAMP_TZ('#{date}', 'YYYY-MM-DD HH24:MI:SS.FF TZH:TZM') FROM dual
|
@@ -149,7 +185,7 @@ EOS
|
|
149
185
|
expected_val = begin
|
150
186
|
string_to_time(date)
|
151
187
|
rescue
|
152
|
-
|
188
|
+
string_to_datetime(date)
|
153
189
|
end
|
154
190
|
assert_equal(expected_val, row[0])
|
155
191
|
end
|
@@ -164,11 +200,12 @@ END;
|
|
164
200
|
EOS
|
165
201
|
cursor.bind_param(:out, nil, DateTime)
|
166
202
|
cursor.bind_param(:in, nil, String, 36)
|
167
|
-
['2005-
|
168
|
-
'
|
203
|
+
['2005-06-01 00:00:00.999999000 -08:30',
|
204
|
+
'2005-12-31 23:59:59.999999000 +00:00',
|
205
|
+
'2006-01-01 00:00:00.000000000 +08:30'].each do |date|
|
169
206
|
cursor[:in] = date
|
170
207
|
cursor.exec
|
171
|
-
assert_equal(
|
208
|
+
assert_equal(string_to_datetime(date), cursor[:out])
|
172
209
|
end
|
173
210
|
cursor.close
|
174
211
|
end
|
@@ -181,9 +218,10 @@ END;
|
|
181
218
|
EOS
|
182
219
|
cursor.bind_param(:out, nil, String, 36)
|
183
220
|
cursor.bind_param(:in, nil, DateTime)
|
184
|
-
['2005-
|
185
|
-
'
|
186
|
-
|
221
|
+
['2005-06-01 00:00:00.999999999 +08:30',
|
222
|
+
'2005-12-31 23:59:59.999999000 -08:30',
|
223
|
+
'2006-01-01 00:00:00.000000000 +00:00'].each do |date|
|
224
|
+
cursor[:in] = string_to_datetime(date)
|
187
225
|
cursor.exec
|
188
226
|
assert_equal(date, cursor[:out])
|
189
227
|
end
|
@@ -201,48 +239,48 @@ EOS
|
|
201
239
|
def obj.day; 31; end
|
202
240
|
cursor[:in] = obj
|
203
241
|
cursor.exec
|
204
|
-
assert_equal(
|
242
|
+
assert_equal(string_to_datetime('2006-12-31 00:00:00'), cursor[:out])
|
205
243
|
# test hour
|
206
244
|
def obj.hour; 23; end
|
207
245
|
cursor[:in] = obj
|
208
246
|
cursor.exec
|
209
|
-
assert_equal(
|
247
|
+
assert_equal(string_to_datetime('2006-12-31 23:00:00'), cursor[:out])
|
210
248
|
# test min
|
211
249
|
def obj.min; 59; end
|
212
250
|
cursor[:in] = obj
|
213
251
|
cursor.exec
|
214
|
-
assert_equal(
|
252
|
+
assert_equal(string_to_datetime('2006-12-31 23:59:00'), cursor[:out])
|
215
253
|
# test sec
|
216
254
|
def obj.sec; 59; end
|
217
255
|
cursor[:in] = obj
|
218
256
|
cursor.exec
|
219
|
-
assert_equal(
|
257
|
+
assert_equal(string_to_datetime('2006-12-31 23:59:59'), cursor[:out])
|
220
258
|
|
221
259
|
# test sec_fraction
|
222
260
|
def obj.sec_fraction; DateTime.parse('0001-01-01 00:00:00.000001').sec_fraction * 999999 ; end
|
223
261
|
cursor[:in] = obj
|
224
262
|
cursor.exec
|
225
|
-
assert_equal(
|
263
|
+
assert_equal(string_to_datetime('2006-12-31 23:59:59.999999'), cursor[:out])
|
226
264
|
# test utc_offset (Time)
|
227
265
|
def obj.utc_offset; @utc_offset; end
|
228
266
|
obj.instance_variable_set(:@utc_offset, 9 * 60 * 60)
|
229
267
|
cursor[:in] = obj
|
230
268
|
cursor.exec
|
231
|
-
assert_equal(
|
269
|
+
assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
|
232
270
|
obj.instance_variable_set(:@utc_offset, -5 * 60 * 60)
|
233
271
|
cursor[:in] = obj
|
234
272
|
cursor.exec
|
235
|
-
assert_equal(
|
273
|
+
assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
|
236
274
|
# test offset (DateTime)
|
237
275
|
def obj.offset; @offset; end
|
238
276
|
obj.instance_variable_set(:@offset, 9.to_r / 24)
|
239
277
|
cursor[:in] = obj
|
240
278
|
cursor.exec
|
241
|
-
assert_equal(
|
279
|
+
assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 +09:00'), cursor[:out])
|
242
280
|
obj.instance_variable_set(:@offset, -5.to_r / 24)
|
243
281
|
cursor[:in] = obj
|
244
282
|
cursor.exec
|
245
|
-
assert_equal(
|
283
|
+
assert_equal(string_to_datetime('2006-12-31 23:59:59.999999 -05:00'), cursor[:out])
|
246
284
|
end
|
247
285
|
|
248
286
|
def test_timezone
|
data/test/test_oci8.rb
CHANGED
@@ -322,14 +322,20 @@ EOS
|
|
322
322
|
@conn.exec(sql)
|
323
323
|
cursor = @conn.parse("INSERT INTO test_table VALUES (:1, :2, :3, :4)")
|
324
324
|
0.upto(9) do |i|
|
325
|
-
val =
|
325
|
+
val = case i
|
326
|
+
when 5; '' # empty string
|
327
|
+
else format('%d', i) * 4096
|
328
|
+
end
|
326
329
|
cursor.exec(i, OCI8::CLOB.new(@conn, val), OCI8::NCLOB.new(@conn, val), OCI8::BLOB.new(@conn, val))
|
327
330
|
end
|
328
331
|
cursor.close
|
329
332
|
cursor = @conn.exec("select * from test_table order by id")
|
330
333
|
0.upto(9) do |i|
|
331
334
|
rv = cursor.fetch
|
332
|
-
val =
|
335
|
+
val = case i
|
336
|
+
when 5; '' # empty string
|
337
|
+
else format('%d', i) * 4096
|
338
|
+
end
|
333
339
|
assert_equal(i, rv[0])
|
334
340
|
assert_instance_of(OCI8::CLOB, rv[1])
|
335
341
|
assert_instance_of(OCI8::NCLOB, rv[2])
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-oci8
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 9
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 2.1.
|
9
|
+
- 1
|
10
|
+
version: 2.1.1
|
11
11
|
platform: x86-mingw32
|
12
12
|
authors:
|
13
13
|
- KUBO Takehiro
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-04-22 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -28,23 +28,24 @@ executables: []
|
|
28
28
|
extensions: []
|
29
29
|
|
30
30
|
extra_rdoc_files:
|
31
|
-
- README
|
31
|
+
- README.md
|
32
32
|
files:
|
33
|
+
- .yardopts
|
33
34
|
- ChangeLog
|
34
35
|
- Makefile
|
35
36
|
- NEWS
|
36
|
-
- README
|
37
|
+
- README.md
|
37
38
|
- VERSION
|
38
39
|
- dist-files
|
39
40
|
- metaconfig
|
40
41
|
- pre-distclean.rb
|
41
42
|
- ruby-oci8.gemspec
|
42
43
|
- setup.rb
|
43
|
-
-
|
44
|
-
-
|
45
|
-
-
|
46
|
-
-
|
47
|
-
-
|
44
|
+
- docs/install-binary-package.md
|
45
|
+
- docs/install-full-client.md
|
46
|
+
- docs/install-instant-client.md
|
47
|
+
- docs/platform-specific-issues.md
|
48
|
+
- docs/report-installation-issue.md
|
48
49
|
- lib/.document
|
49
50
|
- lib/oci8.rb.in
|
50
51
|
- lib/dbd/OCI8.rb
|
@@ -86,17 +87,19 @@ files:
|
|
86
87
|
- test/test_rowid.rb
|
87
88
|
- lib/oci8lib_191.so
|
88
89
|
- lib/oci8lib_18.so
|
90
|
+
- lib/oci8lib_18.map
|
91
|
+
- lib/oci8lib_191.map
|
89
92
|
- lib/oci8.rb
|
90
93
|
has_rdoc: true
|
91
94
|
homepage: http://ruby-oci8.rubyforge.org
|
92
95
|
licenses: []
|
93
96
|
|
94
97
|
post_install_message:
|
95
|
-
rdoc_options:
|
96
|
-
|
97
|
-
- README
|
98
|
+
rdoc_options: []
|
99
|
+
|
98
100
|
require_paths:
|
99
101
|
- lib
|
102
|
+
- ext/oci8
|
100
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
104
|
none: false
|
102
105
|
requirements:
|
data/README
DELETED
data/doc/api.en.html
DELETED
@@ -1,527 +0,0 @@
|
|
1
|
-
<?xml version="1.0" ?>
|
2
|
-
<!DOCTYPE html
|
3
|
-
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
-
<html xmlns="http://www.w3.org/1999/xhtml">
|
6
|
-
<head>
|
7
|
-
<title>Ruby/OCI8 High-level API</title>
|
8
|
-
<link href="manual.css" type="text/css" rel="stylesheet" />
|
9
|
-
</head>
|
10
|
-
<body>
|
11
|
-
<h1><a name="label-0" id="label-0">Ruby/OCI8 High-level API</a></h1><!-- RDLabel: "Ruby/OCI8 High-level API" -->
|
12
|
-
<p>[ <a href="index.en.html">Home</a> ] [ English | <a href="api.ja.html">Japanese</a> ]</p>
|
13
|
-
<p>Ruby/OCI8 is divided to two layer APIs. One is "Low-level
|
14
|
-
API". The other is "High-level API". This document describes how to
|
15
|
-
use the latter, but some of the former will be described as long as it
|
16
|
-
is necessary to use the latter.</p>
|
17
|
-
<p>"High-level API" is the library written by ruby, which based on
|
18
|
-
"Low-level API". This API hides complicated structure of OCI and make
|
19
|
-
it easy to issue SQL statements as possible. Please use this for general purpose.</p>
|
20
|
-
<p>"Low-level API" is the library written by C language. OCI <a name="footmark-1" id="footmark-1" href="#foottext-1"><sup><small>*1</small></sup></a> handles and OCI functions become ruby's classes
|
21
|
-
and methods respectively. The handles and functions are converted by
|
22
|
-
straight mapping rule as long as ruby's syntax allows. </p>
|
23
|
-
<p>In the version 0.2 I will rewrite High-level API by C language directly.
|
24
|
-
Low-level API will be obsolete.</p>
|
25
|
-
<h2><a name="label-1" id="label-1">Contents</a></h2><!-- RDLabel: "Contents" -->
|
26
|
-
<ul>
|
27
|
-
<li><a href="#label-2">Classes List</a>
|
28
|
-
<ul>
|
29
|
-
<li><a href="#label-3">OCI8</a></li>
|
30
|
-
<li><a href="#label-4">OCI8::Cursor</a></li>
|
31
|
-
<li><a href="#label-5">OCI8::BLOB</a></li>
|
32
|
-
<li><a href="#label-6">OCI Exception Classes</a></li>
|
33
|
-
</ul></li>
|
34
|
-
<li><a href="#label-7">Methods List</a>
|
35
|
-
<ul>
|
36
|
-
<li>OCI8
|
37
|
-
<ul>
|
38
|
-
<li><a href="#label-9">new</a>(userid, password, dbname = nil, privilege = nil)</li>
|
39
|
-
<li><a href="#label-10">logoff</a>()</li>
|
40
|
-
<li><a href="#label-11">exec</a>(sql, *bindvars)</li>
|
41
|
-
<li><a href="#label-12">parse</a>(sql)</li>
|
42
|
-
<li><a href="#label-13">commit</a>()</li>
|
43
|
-
<li><a href="#label-14">rollback</a>()</li>
|
44
|
-
<li><a href="#label-15">autocommit?</a></li>
|
45
|
-
<li><a href="#label-16">autocommit</a></li>
|
46
|
-
<li><a href="#label-17">autocommit=</a></li>
|
47
|
-
<li><a href="#label-18">non_blocking?</a></li>
|
48
|
-
<li><a href="#label-19">non_blocking=</a></li>
|
49
|
-
<li><a href="#label-20">break</a>()</li>
|
50
|
-
</ul></li>
|
51
|
-
<li>OCI8::Cursor
|
52
|
-
<ul>
|
53
|
-
<li><a href="#label-22">define</a>(pos, type, length = nil)</li>
|
54
|
-
<li><a href="#label-23">bind_param</a>(key, val, type = nil, length = nil)</li>
|
55
|
-
<li><a href="#label-24">[]</a>(key)</li>
|
56
|
-
<li><a href="#label-25">[]=</a>(key, val)</li>
|
57
|
-
<li><a href="#label-26">keys</a>()</li>
|
58
|
-
<li><a href="#label-27">exec</a>(*bindvars)</li>
|
59
|
-
<li><a href="#label-28">type</a></li>
|
60
|
-
<li><a href="#label-29">row_count</a></li>
|
61
|
-
<li><a href="#label-30">get_col_names</a></li>
|
62
|
-
<li><a href="#label-31">getColNames</a></li>
|
63
|
-
<li><a href="#label-32">fetch</a>()</li>
|
64
|
-
<li><a href="#label-33">close</a>()</li>
|
65
|
-
<li><a href="#label-34">rowid</a></li>
|
66
|
-
</ul></li>
|
67
|
-
<li>OCI8::BLOB
|
68
|
-
<ul>
|
69
|
-
<li><a href="#label-36">available?</a></li>
|
70
|
-
<li><a href="#label-37">read</a>(size = nil)</li>
|
71
|
-
<li><a href="#label-38">write</a>(data)</li>
|
72
|
-
<li><a href="#label-39">size</a></li>
|
73
|
-
<li><a href="#label-40">size=</a>(len)</li>
|
74
|
-
<li><a href="#label-41">chunk_size</a></li>
|
75
|
-
<li><a href="#label-42">truncate</a>(len)</li>
|
76
|
-
<li><a href="#label-43">pos</a></li>
|
77
|
-
<li><a href="#label-44">pos=</a>(pos)</li>
|
78
|
-
<li><a href="#label-46">tell</a></li>
|
79
|
-
<li><a href="#label-47">seek</a>(pos)</li>
|
80
|
-
<li><a href="#label-48">rewind</a></li>
|
81
|
-
<li><a href="#label-45">eof?</a></li>
|
82
|
-
</ul></li>
|
83
|
-
</ul></li>
|
84
|
-
<li><a href="#label-49">Appendix</a>
|
85
|
-
<ul>
|
86
|
-
<li><a href="#label-50">Blocking/Non-Blocking Mode</a></li>
|
87
|
-
</ul></li>
|
88
|
-
</ul>
|
89
|
-
<h2><a name="label-2" id="label-2">Classes List</a></h2><!-- RDLabel: "Classes List" -->
|
90
|
-
<p>Indispensable Classes to use high-level API are <a href="#label-3">OCI8</a>,
|
91
|
-
<a href="#label-4">OCI8::Cursor</a>, <a href="#label-5">OCI8::BLOB</a> and <a href="#label-6">OCI Exception Classes</a>.</p>
|
92
|
-
<h3><a name="label-3" id="label-3">OCI8</a></h3><!-- RDLabel: "OCI8" -->
|
93
|
-
<p>The instance of this class corresponds to the connection with
|
94
|
-
database, which corresponds to java.sql.Connection of JDBC and
|
95
|
-
database handle $dbh of Perl/DBI.</p>
|
96
|
-
<p>To execute simple SQL, it can perform by this class only.</p>
|
97
|
-
<h3><a name="label-4" id="label-4">OCI8::Cursor</a></h3><!-- RDLabel: "OCI8::Cursor" -->
|
98
|
-
<p>The instance of this class corresponds to cursor in the term of
|
99
|
-
Oracle, which corresponds to java.sql.Statement of JDBC and statement
|
100
|
-
handle $sth of Perl/DBI.</p>
|
101
|
-
<p>Don't create the instance by calling 'new' method. Please create it by
|
102
|
-
calling <a href="#label-11">OCI8#exec</a> or <a href="#label-12">OCI8#parse</a>.</p>
|
103
|
-
<h3><a name="label-5" id="label-5">OCI8::BLOB</a></h3><!-- RDLabel: "OCI8::BLOB" -->
|
104
|
-
<p>This is a lob locator to read/write binary data to/from BLOB column.
|
105
|
-
This instance is automatically generated by select statement.</p>
|
106
|
-
<h3><a name="label-6" id="label-6">OCI Exception Classes</a></h3><!-- RDLabel: "OCI Exception Classes" -->
|
107
|
-
<p>The class hierarchy of OCI exception class used in high-level API is
|
108
|
-
as follows.</p>
|
109
|
-
<ul>
|
110
|
-
<li><var>OCIException</var>
|
111
|
-
<ul>
|
112
|
-
<li><var>OCIError</var></li>
|
113
|
-
<li><var>OCIInvalidHandle</var></li>
|
114
|
-
<li><var>OCIBreak</var></li>
|
115
|
-
</ul></li>
|
116
|
-
</ul>
|
117
|
-
<p><var>OCIException</var> is the abstract class for all OCI exceptions. To
|
118
|
-
rescue all OCI exceptions, please use this class.</p>
|
119
|
-
<p><var>OCIError</var> is the exception class with Oracle's error code. You
|
120
|
-
get the error message by OCIError#message. The error code by
|
121
|
-
OCIError#code.</p>
|
122
|
-
<p><var>OCIInvalidHandle</var> is raised when OCI call is performed to
|
123
|
-
the invalid handle.</p>
|
124
|
-
<p><var>OCIBreak</var> is raised when the OCI call is canceled by other thread.
|
125
|
-
See also <a href="#label-50">Blocking/Non-Blocking Mode</a>.</p>
|
126
|
-
<h2><a name="label-7" id="label-7">Methods List</a></h2><!-- RDLabel: "Methods List" -->
|
127
|
-
<h3><a name="label-8" id="label-8">OCI8</a></h3><!-- RDLabel: "OCI8" -->
|
128
|
-
<dl>
|
129
|
-
<dt><a name="label-9" id="label-9"><code>OCI8.new(<var>userid</var>, <var>password</var>, <var>dbname</var> = <var>nil</var>, <var>privilege</var> = <var>nil</var>)</code></a></dt><!-- RDLabel: "OCI8.new" -->
|
130
|
-
<dd>
|
131
|
-
<p>Connects to Oracle by userid and password. dbname is the connect
|
132
|
-
string of Net8. If you need DBA privilege, please set privilege
|
133
|
-
as :SYSDBA or :SYSOPER.</p>
|
134
|
-
<p>example:</p>
|
135
|
-
<pre># sqlplus scott/tiger@orcl.world
|
136
|
-
conn = OCI8.new("scott", "tiger", "orcl.world")</pre>
|
137
|
-
<p>example:</p>
|
138
|
-
<pre># sqlplus 'sys/change_on_install as sysdba'
|
139
|
-
conn = OCI8.new("sys", "change_on_install", nil, :SYSDBA)</pre></dd>
|
140
|
-
<dt><a name="label-10" id="label-10"><code>OCI8#logoff()</code></a></dt><!-- RDLabel: "OCI8#logoff" -->
|
141
|
-
<dd>
|
142
|
-
<p>Disconnects from Oracle. Uncommitted transaction will be
|
143
|
-
rollbacked.</p>
|
144
|
-
<p>example:</p>
|
145
|
-
<pre>conn = OCI8.new("scott", "tiger")
|
146
|
-
... do something ...
|
147
|
-
conn.logoff</pre></dd>
|
148
|
-
<dt><a name="label-11" id="label-11"><code>OCI8#exec(<var>sql</var>, *<var>bindvars</var>)</code></a></dt><!-- RDLabel: "OCI8#exec" -->
|
149
|
-
<dd>
|
150
|
-
<p>Executes the sql statement. The type of return value depends on
|
151
|
-
the type of sql statement: select; insert, update and delete;
|
152
|
-
create, alter and drop; and PL/SQL.</p>
|
153
|
-
<p>When bindvars are specified, they are bound as bind variables
|
154
|
-
before execution.</p>
|
155
|
-
<p>In case of select statement with no block, it returns the
|
156
|
-
instance of OCI8::Cursor.</p>
|
157
|
-
<p>example:</p>
|
158
|
-
<pre>conn = OCI8.new('scott', 'tiger')
|
159
|
-
cursor = conn.exec('SELECT * FROM emp')
|
160
|
-
while r = cursor.fetch()
|
161
|
-
puts r.join(',')
|
162
|
-
end
|
163
|
-
cursor.close
|
164
|
-
conn.logoff</pre>
|
165
|
-
<p>In case of select statement with a block, it acts as iterator and
|
166
|
-
returns the processed row counts. Fetched data is passed to the
|
167
|
-
block as array. NULL value becomes nil in ruby.</p>
|
168
|
-
<p>example:</p>
|
169
|
-
<pre>conn = OCI8.new('scott', 'tiger')
|
170
|
-
num_rows = conn.exec('SELECT * FROM emp') do |r|
|
171
|
-
puts r.join(',')
|
172
|
-
end
|
173
|
-
puts num_rows.to_s + ' rows were processed.'
|
174
|
-
conn.logoff</pre>
|
175
|
-
<p>In case of insert, update or delete statement, it returns the
|
176
|
-
number of processed rows.</p>
|
177
|
-
<p>example:</p>
|
178
|
-
<pre>conn = OCI8.new('scott', 'tiger')
|
179
|
-
num_rows = conn.exec('UPDATE emp SET sal = sal * 1.1')
|
180
|
-
puts num_rows.to_s + ' rows were updated.'
|
181
|
-
conn.logoff</pre>
|
182
|
-
<p>In case of create, alter or drop statement, it returns true.</p>
|
183
|
-
<p>example:</p>
|
184
|
-
<pre>conn = OCI8.new('scott', 'tiger')
|
185
|
-
conn.exec('CREATE TABLE test (col1 CHAR(6))')
|
186
|
-
conn.logoff</pre>
|
187
|
-
<p>In case of PL/SQL statement, it returns the array of bind
|
188
|
-
variables.</p>
|
189
|
-
<p>example:</p>
|
190
|
-
<pre>conn = OCI8.new('scott', 'tiger')
|
191
|
-
conn.exec("BEGIN :str := TO_CHAR(:num, 'FM0999'); END;", 'ABCD', 123)
|
192
|
-
# => ["0123", 123]
|
193
|
-
conn.logoff</pre>
|
194
|
-
<p>Above example uses two bind variables which names are <var>:str</var>
|
195
|
-
and <var>:num</var>. These initial values are "the string whose width
|
196
|
-
is 4 and whose value is 'ABCD'" and "the number whose value is
|
197
|
-
123". This method returns the array of these bind variables,
|
198
|
-
which may modified by PL/SQL statement. The order of array is
|
199
|
-
same with that of bind variables.</p></dd>
|
200
|
-
<dt><a name="label-12" id="label-12"><code>OCI8#parse(<var>sql</var>)</code></a></dt><!-- RDLabel: "OCI8#parse" -->
|
201
|
-
<dd>
|
202
|
-
Creates cursor, prepare to execute SQL statement and return the
|
203
|
-
instance of OCI8::Cursor.</dd>
|
204
|
-
<dt><a name="label-13" id="label-13"><code>OCI8#commit()</code></a></dt><!-- RDLabel: "OCI8#commit" -->
|
205
|
-
<dd>
|
206
|
-
<p>Commits the transaction.</p>
|
207
|
-
<p>example:</p>
|
208
|
-
<pre>conn = OCI8.new("scott", "tiger")
|
209
|
-
conn.exec("UPDATE emp SET sal = sal * 1.1") # yahoo
|
210
|
-
conn.commit
|
211
|
-
conn.logoff</pre></dd>
|
212
|
-
<dt><a name="label-14" id="label-14"><code>OCI8#rollback()</code></a></dt><!-- RDLabel: "OCI8#rollback" -->
|
213
|
-
<dd>
|
214
|
-
<p>Rollbacks the transaction.</p>
|
215
|
-
<p>example:</p>
|
216
|
-
<pre>conn = OCI8.new("scott", "tiger")
|
217
|
-
conn.exec("UPDATE emp SET sal = sal * 0.9") # boos
|
218
|
-
conn.rollback
|
219
|
-
conn.logoff</pre></dd>
|
220
|
-
<dt><a name="label-15" id="label-15"><code>OCI8#autocommit?</code></a></dt><!-- RDLabel: "OCI8#autocommit?" -->
|
221
|
-
<dd>
|
222
|
-
Returns the state of the autocommit mode. The default value is
|
223
|
-
false. If true, the transaction is committed automatically
|
224
|
-
whenever executing insert/update/delete statements.</dd>
|
225
|
-
<dt><a name="label-16" id="label-16"><code>OCI8#autocommit</code></a></dt><!-- RDLabel: "OCI8#autocommit" -->
|
226
|
-
<dd>
|
227
|
-
Alias of <a href="#label-15">OCI8#autocommit?</a>.</dd>
|
228
|
-
<dt><a name="label-17" id="label-17"><code>OCI8#autocommit=</code></a></dt><!-- RDLabel: "OCI8#autocommit=" -->
|
229
|
-
<dd>
|
230
|
-
<p>Changes the status of the autocommit mode. Acceptable values are
|
231
|
-
true and false.</p>
|
232
|
-
<p>example:</p>
|
233
|
-
<pre>conn = OCI8.new("scott", "tiger")
|
234
|
-
conn.autocommit = true
|
235
|
-
... do something ...
|
236
|
-
conn.logoff</pre></dd>
|
237
|
-
<dt><a name="label-18" id="label-18"><code>OCI8#non_blocking?</code></a></dt><!-- RDLabel: "OCI8#non_blocking?" -->
|
238
|
-
<dd>
|
239
|
-
Returns the status of blocking/non-blocking mode. The default
|
240
|
-
value is false, that is blocking mode. See
|
241
|
-
<a href="#label-50">Blocking/Non-Blocking Mode</a>.</dd>
|
242
|
-
<dt><a name="label-19" id="label-19"><code>OCI8#non_blocking=</code></a></dt><!-- RDLabel: "OCI8#non_blocking=" -->
|
243
|
-
<dd>
|
244
|
-
Changes the status of blocking/non-blocking mode. Acceptable
|
245
|
-
values are true and false. See
|
246
|
-
<a href="#label-50">Blocking/Non-Blocking Mode</a>.</dd>
|
247
|
-
<dt><a name="label-20" id="label-20"><code>OCI8#break()</code></a></dt><!-- RDLabel: "OCI8#break" -->
|
248
|
-
<dd>
|
249
|
-
Cancels the OCI call performing in other thread. To use this, the
|
250
|
-
connection status must be non-blocking mode. See
|
251
|
-
<a href="#label-50">Blocking/Non-Blocking Mode</a>.</dd>
|
252
|
-
</dl>
|
253
|
-
<h2><a name="label-21" id="label-21">OCI8::Cursor</a></h2><!-- RDLabel: "OCI8::Cursor" -->
|
254
|
-
<dl>
|
255
|
-
<dt><a name="label-22" id="label-22"><code>OCI8::Cursor#define(<var>pos</var>, <var>type</var>, <var>length</var> = <var>nil</var>)</code></a></dt><!-- RDLabel: "OCI8::Cursor#define" -->
|
256
|
-
<dd>
|
257
|
-
<p>explicitly indicate the date type of fetched value. run this
|
258
|
-
method within parse and exec. pos starts from 1. lentgh is used
|
259
|
-
when type is String.</p>
|
260
|
-
<p>example:</p>
|
261
|
-
<pre>cursor = conn.parse("SELECT ename, hiredate FROM emp")
|
262
|
-
cursor.define(1, String, 20) # fetch the first column as String.
|
263
|
-
cursor.define(2, Time) # fetch the second column as Time.
|
264
|
-
cursor.exec()</pre></dd>
|
265
|
-
<dt><a name="label-23" id="label-23"><code>OCI8::Cursor#bind_param(<var>key</var>, <var>val</var>, <var>type</var> = <var>nil</var>, <var>length</var> = <var>nil</var>)</code></a></dt><!-- RDLabel: "OCI8::Cursor#bind_param" -->
|
266
|
-
<dd>
|
267
|
-
<p>Binds variables explicitly.</p>
|
268
|
-
<p>When key is number, it binds by position, which starts from 1.
|
269
|
-
When key is string, it binds by the name of placeholder.</p>
|
270
|
-
<p>example:</p>
|
271
|
-
<pre>cursor = conn.parse("SELECT * FROM emp WHERE ename = :ename")
|
272
|
-
cursor.bind_param(1, 'SMITH') # bind by position
|
273
|
-
...or...
|
274
|
-
cursor.bind_param(':ename', 'SMITH') # bind by name</pre>
|
275
|
-
<p>To bind as number, Fixnum and Float are available, but Bignum is
|
276
|
-
not supported. If its initial value is NULL, please set nil to
|
277
|
-
<var>type</var> and Fixnum or Float to <var>val</var>.</p>
|
278
|
-
<p>example:</p>
|
279
|
-
<pre>cursor.bind_param(1, 1234) # bind as Fixnum, Initial value is 1234.
|
280
|
-
cursor.bind_param(1, 1234.0) # bind as Float, Initial value is 1234.0.
|
281
|
-
cursor.bind_param(1, nil, Fixnum) # bind as Fixnum, Initial value is NULL.
|
282
|
-
cursor.bind_param(1, nil, Float) # bind as Float, Initial value is NULL.</pre>
|
283
|
-
<p>In case of binding a string, set the string itself to
|
284
|
-
<var>val</var>. When the bind variable is used as output, set the
|
285
|
-
string whose length is enough to store or set the length.</p>
|
286
|
-
<p>example:</p>
|
287
|
-
<pre>cursor = conn.parse("BEGIN :out := :in || '_OUT'; END;")
|
288
|
-
cursor.bind_param(':in', 'DATA') # bind as String with width 4.
|
289
|
-
cursor.bind_param(':out', nil, String, 7) # bind as String with width 7.
|
290
|
-
cursor.exec()
|
291
|
-
p cursor[':out'] # => 'DATA_OU'
|
292
|
-
# Though the length of :out is 8 bytes in PL/SQL block, it is
|
293
|
-
# bound as 7 bytes. So result is cut off at 7 byte.</pre>
|
294
|
-
<p>In case of binding a string as RAW, set OCI::RAW to <var>type</var>.</p>
|
295
|
-
<p>example:</p>
|
296
|
-
<pre>cursor = conn.parse("INSERT INTO raw_table(raw_column) VALUE (:1)")
|
297
|
-
cursor.bind_param(1, 'RAW_STRING', OCI8::RAW)
|
298
|
-
cursor.exec()
|
299
|
-
cursor.close()</pre></dd>
|
300
|
-
<dt><a name="label-24" id="label-24"><code>OCI8::Cursor#[<var>key</var>]</code></a></dt><!-- RDLabel: "OCI8::Cursor#[]" -->
|
301
|
-
<dd>
|
302
|
-
<p>Gets the value of the bind variable.</p>
|
303
|
-
<p>In case of binding explicitly, use same key with that of
|
304
|
-
<a href="#label-23">OCI8::Cursor#bind_param</a>. A placeholder can be bound by
|
305
|
-
name or position. If you bind by name, use that name. If you bind
|
306
|
-
by position, use the position.</p>
|
307
|
-
<p>example:</p>
|
308
|
-
<pre>cursor = conn.parse("BEGIN :out := 'BAR'; END;")
|
309
|
-
cursor.bind_param(':out', 'FOO') # bind by name
|
310
|
-
p cursor[':out'] # => 'FOO'
|
311
|
-
p cursor[1] # => nil
|
312
|
-
cursor.exec()
|
313
|
-
p cursor[':out'] # => 'BAR'
|
314
|
-
p cursor[1] # => nil</pre>
|
315
|
-
<p>example:</p>
|
316
|
-
<pre>cursor = conn.parse("BEGIN :out := 'BAR'; END;")
|
317
|
-
cursor.bind_param(1, 'FOO') # bind by position
|
318
|
-
p cursor[':out'] # => nil
|
319
|
-
p cursor[1] # => 'FOO'
|
320
|
-
cursor.exec()
|
321
|
-
p cursor[':out'] # => nil
|
322
|
-
p cursor[1] # => 'BAR'</pre>
|
323
|
-
<p>In case of binding by <a href="#label-11">OCI8#exec</a> or <a href="#label-27">OCI8::Cursor#exec</a>,
|
324
|
-
get the value by position, which starts from 1.</p>
|
325
|
-
<p>example:</p>
|
326
|
-
<pre>cursor = conn.exec("BEGIN :out := 'BAR'; END;", 'FOO')
|
327
|
-
# 1st bind variable is bound as String with width 3. Its initial value is 'FOO'
|
328
|
-
# After execute, the value become 'BAR'.
|
329
|
-
p cursor[1] # => 'BAR'</pre></dd>
|
330
|
-
<dt><a name="label-25" id="label-25"><code>OCI8::Cursor#[<var>key</var>] = <var>val</var></code></a></dt><!-- RDLabel: "OCI8::Cursor#[]=" -->
|
331
|
-
<dd>
|
332
|
-
<p>Sets the value to the bind variable. The way to specify the
|
333
|
-
<var>key</var> is same with <a href="#label-24">OCI8::Cursor#[]</a>. This is available
|
334
|
-
to replace the value and execute many times.</p>
|
335
|
-
<p>example1:</p>
|
336
|
-
<pre>cursor = conn.parse("INSERT INTO test(col1) VALUES(:1)")
|
337
|
-
cursor.bind_params(1, nil, String, 3)
|
338
|
-
['FOO', 'BAR', 'BAZ'].each do |key|
|
339
|
-
cursor[1] = key
|
340
|
-
cursor.exec
|
341
|
-
end
|
342
|
-
cursor.close()</pre>
|
343
|
-
<p>example2:</p>
|
344
|
-
<pre>['FOO', 'BAR', 'BAZ'].each do |key|
|
345
|
-
conn.exec("INSERT INTO test(col1) VALUES(:1)", key)
|
346
|
-
end</pre>
|
347
|
-
<p>Both example's results are same. But the former will use less resources.</p></dd>
|
348
|
-
<dt><a name="label-26" id="label-26"><code>OCI8::Cursor#keys()</code></a></dt><!-- RDLabel: "OCI8::Cursor#keys" -->
|
349
|
-
<dd>
|
350
|
-
Returns the keys of bind variables as array.</dd>
|
351
|
-
<dt><a name="label-27" id="label-27"><code>OCI8::Cursor#exec(*<var>bindvars</var>)</code></a></dt><!-- RDLabel: "OCI8::Cursor#exec" -->
|
352
|
-
<dd>
|
353
|
-
<p>Executes the SQL statement assigned the cursor. The type of
|
354
|
-
return value depends on the type of sql statement: select;
|
355
|
-
insert, update and delete; create, alter, drop and PL/SQL.</p>
|
356
|
-
<p>In case of select statement, it returns the number of the
|
357
|
-
select-list.</p>
|
358
|
-
<p>In case of insert, update or delete statement, it returns the
|
359
|
-
number of processed rows.</p>
|
360
|
-
<p>In case of create, alter, drop and PL/SQL statement, it returns
|
361
|
-
true. In contrast with <a href="#label-11">OCI8#exec</a>, it returns true even
|
362
|
-
though PL/SQL. Use <a href="#label-24">OCI8::Cursor#[]</a> explicitly to get bind
|
363
|
-
variables.</p></dd>
|
364
|
-
<dt><a name="label-28" id="label-28"><code>OCI8::Cursor#type</code></a></dt><!-- RDLabel: "OCI8::Cursor#type" -->
|
365
|
-
<dd>
|
366
|
-
<p>gets the type of SQL statement. Its value is one of the follows.</p>
|
367
|
-
<ul>
|
368
|
-
<li>OCI8::STMT_SELECT</li>
|
369
|
-
<li>OCI8::STMT_UPDATE</li>
|
370
|
-
<li>OCI8::STMT_DELETE</li>
|
371
|
-
<li>OCI8::STMT_INSERT</li>
|
372
|
-
<li>OCI8::STMT_CREATE</li>
|
373
|
-
<li>OCI8::STMT_DROP</li>
|
374
|
-
<li>OCI8::STMT_ALTER</li>
|
375
|
-
<li>OCI8::STMT_BEGIN</li>
|
376
|
-
<li>OCI8::STMT_DECLARE</li>
|
377
|
-
</ul>
|
378
|
-
<p>For PL/SQL statement, it returns OCI8::STMT_BEGIN or
|
379
|
-
OCI8::STMT_DECLARE.</p></dd>
|
380
|
-
<dt><a name="label-29" id="label-29"><code>OCI8::Cursor#row_count</code></a></dt><!-- RDLabel: "OCI8::Cursor#row_count" -->
|
381
|
-
<dd>
|
382
|
-
Returns the number of processed rows.</dd>
|
383
|
-
<dt><a name="label-30" id="label-30"><code>OCI8::Cursor#get_col_names</code></a></dt><!-- RDLabel: "OCI8::Cursor#get_col_names" -->
|
384
|
-
<dd>
|
385
|
-
Gets the names of select-list as array. Please use this
|
386
|
-
method after exec.</dd>
|
387
|
-
<dt><a name="label-31" id="label-31"><code>OCI8::Cursor#getColNames</code></a></dt><!-- RDLabel: "OCI8::Cursor#getColNames" -->
|
388
|
-
<dd>
|
389
|
-
Alias of <a href="#label-30">OCI8::Cursor#get_col_names</a>.</dd>
|
390
|
-
<dt><a name="label-32" id="label-32"><code>OCI8::Cursor#fetch()</code></a></dt><!-- RDLabel: "OCI8::Cursor#fetch" -->
|
391
|
-
<dd>
|
392
|
-
<p>Gets fetched data as array. This is available for select
|
393
|
-
statement only.</p>
|
394
|
-
<p>example:</p>
|
395
|
-
<pre>conn = OCI8.new('scott', 'tiger')
|
396
|
-
cursor = conn.exec('SELECT * FROM emp')
|
397
|
-
while r = cursor.fetch()
|
398
|
-
puts r.join(',')
|
399
|
-
end
|
400
|
-
cursor.close
|
401
|
-
conn.logoff</pre></dd>
|
402
|
-
<dt><a name="label-33" id="label-33"><code>OCI8::Cursor#close()</code></a></dt><!-- RDLabel: "OCI8::Cursor#close" -->
|
403
|
-
<dd>
|
404
|
-
close the cursor.</dd>
|
405
|
-
<dt><a name="label-34" id="label-34"><code>OCI8::Cursor#rowid()</code></a></dt><!-- RDLabel: "OCI8::Cursor#rowid" -->
|
406
|
-
<dd>
|
407
|
-
get the rowid of the last processed row.
|
408
|
-
This value is available as bind data.
|
409
|
-
On the other hand it isn't available for other purpose.</dd>
|
410
|
-
</dl>
|
411
|
-
<h2><a name="label-35" id="label-35">OCI8::BLOB</a></h2><!-- RDLabel: "OCI8::BLOB" -->
|
412
|
-
<dl>
|
413
|
-
<dt><a name="label-36" id="label-36"><code>OCI8::BLOB#available?</code></a></dt><!-- RDLabel: "OCI8::BLOB#available?" -->
|
414
|
-
<dd>
|
415
|
-
<p>check whether BLOB is available or not.
|
416
|
-
To use BLOB you need to insert EMPTY_BLOB() at first.</p>
|
417
|
-
<p>example:</p>
|
418
|
-
<pre>conn.exec("CREATE TABLE photo (name VARCHAR2(50), image BLOB)")
|
419
|
-
conn.exec("INSERT INTO photo VALUES ('null-data', NULL)")
|
420
|
-
conn.exec("INSERT INTO photo VALUES ('empty-data', EMPTY_BLOB())")
|
421
|
-
conn.exec("SELECT name, image FROM photo") do |name, image|
|
422
|
-
case name
|
423
|
-
when 'null-data'
|
424
|
-
puts "#{name} => #{image.available?.to_s}"
|
425
|
-
# => false
|
426
|
-
when 'empty-data'
|
427
|
-
puts "#{name} => #{image.available?.to_s}"
|
428
|
-
# => true
|
429
|
-
end
|
430
|
-
end</pre></dd>
|
431
|
-
<dt><a name="label-37" id="label-37"><code>OCI8::BLOB#read(<var>size</var> = <var>nil</var>)</code></a></dt><!-- RDLabel: "OCI8::BLOB#read" -->
|
432
|
-
<dd>
|
433
|
-
<p>read at most size bytes from BLOB, or to the end of file if size is omitted.</p>
|
434
|
-
<p>example: read chunks of chunk size.</p>
|
435
|
-
<pre>conn.exec("SELECT name, image FROM photo") do |name, image|
|
436
|
-
chunk_size = image.chunk_size
|
437
|
-
File.open(name, 'w') do |f|
|
438
|
-
until image.eof?
|
439
|
-
f.write(image.read(chunk_size))
|
440
|
-
end
|
441
|
-
end
|
442
|
-
end</pre>
|
443
|
-
<p>example: read at once.</p>
|
444
|
-
<pre>conn.exec("SELECT name, image FROM photo") do |name, image|
|
445
|
-
File.open(name, 'w') do |f|
|
446
|
-
f.write(image.read)
|
447
|
-
end
|
448
|
-
end</pre></dd>
|
449
|
-
<dt><a name="label-38" id="label-38"><code>OCI8::BLOB#write(<var>string</var>)</code></a></dt><!-- RDLabel: "OCI8::BLOB#write" -->
|
450
|
-
<dd>
|
451
|
-
<p>write the given string to BLOB.
|
452
|
-
If old data is longer than new data, resize by <a href="#label-40">OCI8::BLOB#size=</a>.</p>
|
453
|
-
<p>example: write chunks of chunk size.</p>
|
454
|
-
<pre>cursor = conn.parse("INSERT INTO photo VALUES(:name, EMPTY_BLOB())")
|
455
|
-
Dir["*.png"].each do |fname|
|
456
|
-
cursor.exec(fname)
|
457
|
-
end
|
458
|
-
conn.exec("SELECT name, image FROM photo") do |name, image|
|
459
|
-
chunk_size = image.chunk_size
|
460
|
-
File.open(name, 'r') do |f|
|
461
|
-
until f.eof?
|
462
|
-
image.write(f.read(chunk_size))
|
463
|
-
end
|
464
|
-
image.size = f.pos
|
465
|
-
end
|
466
|
-
end
|
467
|
-
conn.commit</pre>
|
468
|
-
<p>example: write at once.</p>
|
469
|
-
<pre>conn.exec("SELECT name, image FROM photo") do |name, image|
|
470
|
-
File.open(name, 'r') do |f|
|
471
|
-
image.write(f.read)
|
472
|
-
image.size = f.pos
|
473
|
-
end
|
474
|
-
end</pre></dd>
|
475
|
-
<dt><a name="label-39" id="label-39"><code>OCI8::BLOB#size</code></a></dt><!-- RDLabel: "OCI8::BLOB#size" -->
|
476
|
-
<dd>
|
477
|
-
return the size of BLOB.</dd>
|
478
|
-
<dt><a name="label-40" id="label-40"><code>OCI8::BLOB#size=(<var>len</var>)</code></a></dt><!-- RDLabel: "OCI8::BLOB#size=" -->
|
479
|
-
<dd>
|
480
|
-
set the size of BLOB.</dd>
|
481
|
-
<dt><a name="label-41" id="label-41"><code>OCI8::BLOB#chunk_size</code></a></dt><!-- RDLabel: "OCI8::BLOB#chunk_size" -->
|
482
|
-
<dd>
|
483
|
-
return the chunk size of BLOB.</dd>
|
484
|
-
<dt><a name="label-42" id="label-42"><code>OCI8::BLOB#truncate(<var>len</var>)</code></a></dt><!-- RDLabel: "OCI8::BLOB#truncate" -->
|
485
|
-
<dd>
|
486
|
-
set the size of BLOB.</dd>
|
487
|
-
<dt><a name="label-43" id="label-43"><code>OCI8::BLOB#pos</code></a></dt><!-- RDLabel: "OCI8::BLOB#pos" -->
|
488
|
-
<dd>
|
489
|
-
return the current offset of BLOB.</dd>
|
490
|
-
<dt><a name="label-44" id="label-44"><code>OCI8::BLOB#pos=(<var>pos</var>)</code></a></dt><!-- RDLabel: "OCI8::BLOB#pos=" -->
|
491
|
-
<dd>
|
492
|
-
set the current offset of BLOB.</dd>
|
493
|
-
<dt><a name="label-45" id="label-45"><code>OCI8::BLOB#eof?</code></a></dt><!-- RDLabel: "OCI8::BLOB#eof?" -->
|
494
|
-
<dd>
|
495
|
-
return true if BLOB is at end of file</dd>
|
496
|
-
<dt><a name="label-46" id="label-46"><code>OCI8::BLOB#tell</code></a></dt><!-- RDLabel: "OCI8::BLOB#tell" -->
|
497
|
-
<dd>
|
498
|
-
Synonym for <a href="#label-43">OCI8::BLOB#pos</a>.</dd>
|
499
|
-
<dt><a name="label-47" id="label-47"><code>OCI8::BLOB#seek(<var>pos</var>)</code></a></dt><!-- RDLabel: "OCI8::BLOB#seek" -->
|
500
|
-
<dd>
|
501
|
-
Synonym for <a href="#label-44">OCI8::BLOB#pos=</a>.</dd>
|
502
|
-
<dt><a name="label-48" id="label-48"><code>OCI8::BLOB#rewind</code></a></dt><!-- RDLabel: "OCI8::BLOB#rewind" -->
|
503
|
-
<dd>
|
504
|
-
set the current offset to zero.</dd>
|
505
|
-
</dl>
|
506
|
-
<h2><a name="label-49" id="label-49">Appendix</a></h2><!-- RDLabel: "Appendix" -->
|
507
|
-
<h3><a name="label-50" id="label-50">Blocking/Non-Blocking Mode</a></h3><!-- RDLabel: "Blocking/Non-Blocking Mode" -->
|
508
|
-
<p>The default mode is blocking mode. You can change the mode by
|
509
|
-
<a href="#label-19">OCI8#non_blocking=</a>.</p>
|
510
|
-
<p>When the mode is blocking, heavy OCI calls will block the process
|
511
|
-
itself even though multithread application because ruby's thread is
|
512
|
-
not native one.</p>
|
513
|
-
<p>when the mode is non-blocking, heavy OCI calls will not block the
|
514
|
-
process, but block the thread only. Instead of the merit, each OCI
|
515
|
-
call become a bit slower because it polls many times whether the OCI
|
516
|
-
call is finished or not.</p>
|
517
|
-
<p>You can cancel a OCI call by using <a href="#label-20">OCI8#break</a> from other thread.
|
518
|
-
The canceled OCI call raises <var>OCIBreak</var> exception.</p>
|
519
|
-
<p>Restriction of non-blocking mode: Don't do OCI calls at the same time
|
520
|
-
for a same connection.</p>
|
521
|
-
<hr />
|
522
|
-
<p class="foottext">
|
523
|
-
<a name="foottext-1" id="foottext-1" href="#footmark-1"><sup><small>*1</small></sup></a><small>Oracle
|
524
|
-
Call Interface</small><br />
|
525
|
-
</p>
|
526
|
-
</body>
|
527
|
-
</html>
|