ruby-oci8 2.0.4-x86-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- data/ChangeLog +1912 -0
- data/Makefile +96 -0
- data/NEWS +223 -0
- data/README +86 -0
- data/VERSION +1 -0
- data/dist-files +77 -0
- data/doc/api.en.html +527 -0
- data/doc/api.en.rd +554 -0
- data/doc/api.ja.html +525 -0
- data/doc/api.ja.rd +557 -0
- data/doc/manual.css +35 -0
- data/lib/.document +1 -0
- data/lib/dbd/OCI8.rb +591 -0
- data/lib/oci8.rb +82 -0
- data/lib/oci8.rb.in +82 -0
- data/lib/oci8/.document +5 -0
- data/lib/oci8/bindtype.rb +319 -0
- data/lib/oci8/compat.rb +113 -0
- data/lib/oci8/datetime.rb +619 -0
- data/lib/oci8/encoding-init.rb +40 -0
- data/lib/oci8/encoding.yml +537 -0
- data/lib/oci8/metadata.rb +2077 -0
- data/lib/oci8/object.rb +562 -0
- data/lib/oci8/oci8.rb +571 -0
- data/lib/oci8/oracle_version.rb +144 -0
- data/lib/oci8lib_18.so +0 -0
- data/lib/oci8lib_191.so +0 -0
- data/metaconfig +142 -0
- data/pre-distclean.rb +7 -0
- data/ruby-oci8.gemspec +63 -0
- data/setup.rb +1331 -0
- data/test/README +4 -0
- data/test/config.rb +109 -0
- data/test/test_all.rb +50 -0
- data/test/test_appinfo.rb +63 -0
- data/test/test_array_dml.rb +333 -0
- data/test/test_bind_raw.rb +46 -0
- data/test/test_bind_time.rb +178 -0
- data/test/test_break.rb +83 -0
- data/test/test_clob.rb +79 -0
- data/test/test_connstr.rb +81 -0
- data/test/test_datetime.rb +622 -0
- data/test/test_dbi.rb +366 -0
- data/test/test_dbi_clob.rb +53 -0
- data/test/test_encoding.rb +100 -0
- data/test/test_metadata.rb +257 -0
- data/test/test_oci8.rb +434 -0
- data/test/test_oracle_version.rb +70 -0
- data/test/test_oradate.rb +256 -0
- data/test/test_oranumber.rb +655 -0
- data/test/test_rowid.rb +33 -0
- metadata +108 -0
data/doc/api.ja.rd
ADDED
@@ -0,0 +1,557 @@
|
|
1
|
+
=begin
|
2
|
+
= Ruby/OCI8 ���API
|
3
|
+
[ ((<Home|URL:index.ja.html>)) ] [ ((<English|URL:api.en.html>)) | Japanese ]
|
4
|
+
|
5
|
+
Ruby/OCI8 ��2���ؤ� API ��ʬ����ޤ����ҤȤĤ�"����API"�ǡ��⤦��Ĥ�"
|
6
|
+
���API"�Ǥ��������ǤϾ��API�λ���ˡ����⤷�ޤ�������ϲ���API�˽�°
|
7
|
+
���륯�饹�Ǥ⡢���API ����Ѥ�����ɬ�פʥ��饹�Ϥ����Dz��⤷�ޤ���
|
8
|
+
|
9
|
+
"���API"�� ruby �ǽ줿�饤�֥��ǡ�"����API"�ξ�˹��ۤ���Ƥ���
|
10
|
+
����ʣ���� OCI �ι�¤���ä��ơ��ʤ�٤�ñ��˻Ȥ���褦�ˤ��Ƥ����
|
11
|
+
��������Ū�����ӤǤϤ��� API ����Ѥ��Ƥ���������
|
12
|
+
|
13
|
+
"����API"�� C ����ǽ줿�饤�֥��Ǥ���OCI((-Oracle Call
|
14
|
+
Interface: ���饯��� C���쥤���ե�����-))�Υϥ�ɥ�� ruby �Υ���
|
15
|
+
���ˡ�OCI �δؿ��� ruby �Υ�åɤإޥåԥ��Ƥ���ޤ���ruby �� C
|
16
|
+
����θ�����ͤΰ㤤�ˤ�ꡢñ��ʥޥåԥ��Ǥ��ʤ��Ȥ����⤢��ޤ�
|
17
|
+
������ǽ�ʤ����긵�� API ���Ѥ��ʤ��褦�ˤ��Ƥ���ޤ���
|
18
|
+
|
19
|
+
�С������ 0.2 �Ǥ� C ����Ǥ�äƾ��API��ľ�ܽ�ľ��������API�Ϥʤ�
|
20
|
+
�ʤ�ͽ��Ǥ���
|
21
|
+
|
22
|
+
== �ܼ�
|
23
|
+
* ((<���饹����>))
|
24
|
+
* ((<OCI8>))
|
25
|
+
* ((<OCI8::Cursor>))
|
26
|
+
* ((<OCI8::BLOB>))
|
27
|
+
* ((<OCI�㳰���饹>))
|
28
|
+
* ((<��åɰ���>))
|
29
|
+
* OCI8
|
30
|
+
* ((<new|OCI8.new>))(userid, password, dbname = nil, privilege = nil)
|
31
|
+
* ((<logoff|OCI8#logoff>))()
|
32
|
+
* ((<exec|OCI8#exec>))(sql, *bindvars)
|
33
|
+
* ((<parse|OCI8#parse>))(sql)
|
34
|
+
* ((<commit|OCI8#commit>))()
|
35
|
+
* ((<rollback|OCI8#rollback>))()
|
36
|
+
* ((<autocommit?|OCI8#autocommit?>))
|
37
|
+
* ((<autocommit|OCI8#autocommit>))
|
38
|
+
* ((<autocommit=|OCI8#autocommit=>))
|
39
|
+
* ((<non_blocking?|OCI8#non_blocking?>))
|
40
|
+
* ((<non_blocking=|OCI8#non_blocking=>))
|
41
|
+
* ((<break|OCI8#break>))()
|
42
|
+
* OCI8::Cursor
|
43
|
+
* ((<define|OCI8::Cursor#define>))(pos, type, length = nil)
|
44
|
+
* ((<bind_param|OCI8::Cursor#bind_param>))(key, val, type = nil, length = nil)
|
45
|
+
* ((<[]|OCI8::Cursor#[]>))(key)
|
46
|
+
* ((<[]=|OCI8::Cursor#[]=>))(key, val)
|
47
|
+
* ((<keys|OCI8::Cursor#keys>))()
|
48
|
+
* ((<exec|OCI8::Cursor#exec>))(*bindvars)
|
49
|
+
* ((<type|OCI8::Cursor#type>))
|
50
|
+
* ((<row_count|OCI8::Cursor#row_count>))
|
51
|
+
* ((<get_col_names|OCI8::Cursor#get_col_names>))
|
52
|
+
* ((<getColNames|OCI8::Cursor#getColNames>))
|
53
|
+
* ((<fetch|OCI8::Cursor#fetch>))()
|
54
|
+
* ((<close|OCI8::Cursor#close>))()
|
55
|
+
* ((<rowid|OCI8::Cursor#rowid>))
|
56
|
+
* OCI8::BLOB
|
57
|
+
* ((<available?|OCI8::BLOB#available?>))
|
58
|
+
* ((<read|OCI8::BLOB#read>))(size = nil)
|
59
|
+
* ((<write|OCI8::BLOB#write>))(data)
|
60
|
+
* ((<size|OCI8::BLOB#size>))
|
61
|
+
* ((<size=|OCI8::BLOB#size=>))(len)
|
62
|
+
* ((<chunk_size|OCI8::BLOB#chunk_size>))
|
63
|
+
* ((<truncate|OCI8::BLOB#truncate>))(len)
|
64
|
+
* ((<pos|OCI8::BLOB#pos>))
|
65
|
+
* ((<pos=|OCI8::BLOB#pos=>))(pos)
|
66
|
+
* ((<tell|OCI8::BLOB#tell>))
|
67
|
+
* ((<seek|OCI8::BLOB#seek>))(pos)
|
68
|
+
* ((<rewind|OCI8::BLOB#rewind>))
|
69
|
+
* ((<eof?|OCI8::BLOB#eof?>))
|
70
|
+
* ((<���>))
|
71
|
+
* ((<"�֥��å���/��֥��å��⡼��">))
|
72
|
+
== ���饹����
|
73
|
+
���API��ɬ�ܤʥ��饹�ϡ�((<OCI8>)), ((<OCI8::Cursor>)), ((<OCI8::BLOB>)),
|
74
|
+
�����((<OCI�㳰���饹>))�Ǥ���
|
75
|
+
|
76
|
+
=== OCI8
|
77
|
+
���Υ��饹�Υ����ϥǡ����١����ؤ���³���б����ޤ���JDBC ��
|
78
|
+
java.sql.Connection, Perl/DBI �� database handle: $dbh ���б����ޤ���
|
79
|
+
|
80
|
+
ñ��� SQL �μ¹Ԥʤ�С����Υ��饹�ΤߤǼ¹ԤǤ��ޤ���
|
81
|
+
|
82
|
+
=== OCI8::Cursor
|
83
|
+
���Υ��饹�Υ����ϥ��饯����Ѹ�Ǥϥ���������б����ޤ���JDBC
|
84
|
+
�� java.sql.Statement, Perl/DBI �� statement handle: $sth ���б����ޤ���
|
85
|
+
|
86
|
+
���Υ��饹�Υ����� new �ˤ���������ʤ��Ǥ���������ɬ��
|
87
|
+
((<OCI8#exec>)), ((<OCI8#parse>)) ��ͳ���������Ƥ���������
|
88
|
+
|
89
|
+
=== OCI8::BLOB
|
90
|
+
BLOB �ΥХ��ʥ�ǡ������ɤ߽���Ȥ��˻��Ѥ��륯�饹�Ǥ���
|
91
|
+
select ʸ�� BLOB ���Υ���������Ȥ��Υ��饹�Υ�������ư
|
92
|
+
Ū����������ޤ���
|
93
|
+
|
94
|
+
=== OCI�㳰���饹
|
95
|
+
���API��ɬ�פ��㳰���饹�γ��ؤϰʲ��Τ褦�ˤʤäƤ��ޤ���
|
96
|
+
|
97
|
+
* ((|OCIException|))
|
98
|
+
* ((|OCIError|))
|
99
|
+
* ((|OCIInvalidHandle|))
|
100
|
+
* ((|OCIBreak|))
|
101
|
+
|
102
|
+
((|OCIException|))�� OCI �㳰����ݿƥ��饹�Ǥ���OCI ���㳰�٤���
|
103
|
+
�������Ȥ��Ϥ��Υ��饹�� rescue �˻ȤäƤ���������
|
104
|
+
|
105
|
+
((|OCIError|))�ϥ��饯��Υ��顼�����ɤĤ����㳰���饹�Ǥ���
|
106
|
+
OCIError#message �ǥ�å�������ʸ�����OCIErrror#code �ǥ��顼������
|
107
|
+
������Ǥ��ޤ���
|
108
|
+
|
109
|
+
((|OCIInvalidHandle|))��̵���ʥϥ�ɥ���Ф�������Ԥʤä��Ȥ��˵���
|
110
|
+
���㳰�Ǥ���
|
111
|
+
|
112
|
+
((|OCIBreak|))��((<��֥��å��⡼��|"�֥��å���/��֥��å��⡼��">))
|
113
|
+
���̤Υ���åɤ�� OCI �ƽФ�������뤵�줿�Ȥ��˵������㳰�Ǥ���
|
114
|
+
|
115
|
+
== ��åɰ���
|
116
|
+
=== OCI8
|
117
|
+
--- OCI8.new(userid, password, dbname = nil, privilege = nil)
|
118
|
+
((|userid|)), ((|password|)) �Ǥ�äƥ��饯�����³���ޤ���((|dbname|)) �� Net8 ��
|
119
|
+
��³ʸ����Ǥ���DBA ���¤�ɬ�פʾ��� ((|privilege|)) �� :SYSDBA �ޤ�
|
120
|
+
�� :SYSOPER����ꤷ�ޤ���
|
121
|
+
|
122
|
+
|
123
|
+
��:
|
124
|
+
# sqlplus scott/tiger@orcl.world
|
125
|
+
conn = OCI8.new("scott", "tiger", "orcl.world")
|
126
|
+
|
127
|
+
��:
|
128
|
+
# sqlplus 'sys/change_on_install as sysdba'
|
129
|
+
conn = OCI8.new("sys", "change_on_install", nil, :SYSDBA)
|
130
|
+
|
131
|
+
--- OCI8#logoff()
|
132
|
+
���饯��Ȥ���³���ڤ�ޤ������ߥåȤ���Ƥʤ��ȥ��������
|
133
|
+
������Хå�����ޤ���
|
134
|
+
|
135
|
+
��:
|
136
|
+
conn = OCI8.new("scott", "tiger")
|
137
|
+
... do something ...
|
138
|
+
conn.logoff
|
139
|
+
|
140
|
+
--- OCI8#exec(sql, *bindvars)
|
141
|
+
sql ʸ��¹Ԥ��ޤ���sql ʸ�� SELECTʸ��INSERT/UPDATE/DELETEʸ��
|
142
|
+
CREATE/ALTER/DROPʸ��PL/SQLʸ�����줾���������ͤμ��ब�ۤʤ�
|
143
|
+
�ޤ���
|
144
|
+
|
145
|
+
bindvars �������硢�Х�����ѿ��Ȥ��ƥХ���ɤ��Ƥ���¹Ԥ��ޤ���
|
146
|
+
|
147
|
+
SELECT ʸ�ǥ֥��å����Ĥ��Ƥʤ���硢OCI8::Cursor �Υ�����
|
148
|
+
���֤��ޤ���
|
149
|
+
|
150
|
+
��:
|
151
|
+
conn = OCI8.new('scott', 'tiger')
|
152
|
+
cursor = conn.exec('SELECT * FROM emp')
|
153
|
+
while r = cursor.fetch()
|
154
|
+
puts r.join(',')
|
155
|
+
end
|
156
|
+
cursor.close
|
157
|
+
conn.logoff
|
158
|
+
|
159
|
+
SELECT ʸ�ǥ֥��å����Ĥ��Ƥ����硢���ƥ졼���Ȥ���ư��������
|
160
|
+
�����Կ����֤�ޤ����֥��å��ˤϥե��å������ǡ���������Ǥ錄��
|
161
|
+
�ޤ���NULL�ͤ� ruby ¦�Ǥ� nil �˥ޥåԥ��Ƥ���ޤ���
|
162
|
+
|
163
|
+
|
164
|
+
��:
|
165
|
+
conn = OCI8.new('scott', 'tiger')
|
166
|
+
num_rows = conn.exec('SELECT * FROM emp') do |r|
|
167
|
+
puts r.join(',')
|
168
|
+
end
|
169
|
+
puts num_rows.to_s + ' rows were processed.'
|
170
|
+
conn.logoff
|
171
|
+
|
172
|
+
INSERT/UPDATE/DELETEʸ�ξ�硢���줾����������Կ����֤�ޤ���
|
173
|
+
|
174
|
+
��:
|
175
|
+
conn = OCI8.new('scott', 'tiger')
|
176
|
+
num_rows = conn.exec('UPDATE emp SET sal = sal * 1.1')
|
177
|
+
puts num_rows.to_s + ' rows were updated.'
|
178
|
+
conn.logoff
|
179
|
+
|
180
|
+
CREATE/ALTER/DROPʸ�ξ�硢true ���֤�ޤ���
|
181
|
+
|
182
|
+
��:
|
183
|
+
conn = OCI8.new('scott', 'tiger')
|
184
|
+
conn.exec('CREATE TABLE test (col1 CHAR(6))')
|
185
|
+
conn.logoff
|
186
|
+
|
187
|
+
PL/SQLʸ�ξ�硢�¹Ը�ΥХ�����ѿ����ͤ�����Ȥʤä��֤�ޤ���
|
188
|
+
|
189
|
+
��:
|
190
|
+
conn = OCI8.new('scott', 'tiger')
|
191
|
+
conn.exec("BEGIN :str := TO_CHAR(:num, 'FM0999'); END;", 'ABCD', 123)
|
192
|
+
# => ["0123", 123]
|
193
|
+
conn.logoff
|
194
|
+
|
195
|
+
�嵭����Ǥϡ�((|:str|)) �� ((|:num|)) �Ȥ���2�ĤΥХ�����ѿ���
|
196
|
+
����ޤ�������ͤȤ��Ƥ��줾��"��4���ͤ� ABCD ��ʸ����"��"�� 123
|
197
|
+
�ο���"�����ꤵ��Ƥ��顢PL/SQLʸ���¹Ԥ��졢�¹Ը�ΥХ�����ѿ�
|
198
|
+
���ͤ�����Ȥ����֤äƤ��ޤ�������ν��֤ϥХ�����ѿ��ν��֤�Ʊ
|
199
|
+
���Ǥ���
|
200
|
+
|
201
|
+
--- OCI8#parse(sql)
|
202
|
+
����������������sql ʸ�¹Ԥν����ޤ���OCI8::Cursor �Υ���
|
203
|
+
�����֤�ޤ���
|
204
|
+
|
205
|
+
--- OCI8#commit()
|
206
|
+
�ȥ�������ߥåȤ��ޤ���
|
207
|
+
|
208
|
+
��:
|
209
|
+
conn = OCI8.new("scott", "tiger")
|
210
|
+
conn.exec("UPDATE emp SET sal = sal * 1.1") # yahoo
|
211
|
+
conn.commit
|
212
|
+
conn.logoff
|
213
|
+
|
214
|
+
--- OCI8#rollback()
|
215
|
+
�ȥ�������������Хå����ޤ���
|
216
|
+
|
217
|
+
��:
|
218
|
+
conn = OCI8.new("scott", "tiger")
|
219
|
+
conn.exec("UPDATE emp SET sal = sal * 0.9") # boos
|
220
|
+
conn.rollback
|
221
|
+
conn.logoff
|
222
|
+
|
223
|
+
--- OCI8#autocommit?
|
224
|
+
autocommit �⡼�ɤξ��֤��֤��ޤ����ǥե���Ȥ� false �Ǥ�������
|
225
|
+
�ͤ� true �ΤȤ���INSERT/UPDATE/DELETEʸ���¹Ԥ������˼�ưŪ��
|
226
|
+
���ߥåȤ���ޤ���
|
227
|
+
|
228
|
+
--- OCI8#autocommit
|
229
|
+
((<OCI8#autocommit?>))����̾�Ǥ���
|
230
|
+
|
231
|
+
--- OCI8#autocommit=
|
232
|
+
autocommit �⡼�ɤξ��֤��ѹ����ޤ���true �� flase �����ꤷ�Ƥ���������
|
233
|
+
|
234
|
+
��:
|
235
|
+
conn = OCI8.new("scott", "tiger")
|
236
|
+
conn.autocommit = true
|
237
|
+
... do something ...
|
238
|
+
conn.logoff
|
239
|
+
|
240
|
+
--- OCI8#non_blocking?
|
241
|
+
�֥��å���/��֥��å��⡼�ɤξ��֤��֤��ޤ����ǥե���Ȥ�
|
242
|
+
false���Ĥޤ�֥��å��⡼�ɤǤ���((<"�֥��å���/��֥��å��⡼��">))
|
243
|
+
�Ȥ��Ƥ���������
|
244
|
+
|
245
|
+
|
246
|
+
--- OCI8#non_blocking=
|
247
|
+
�֥��å���/��֥��å��⡼�ɤξ��֤��ѹ����ޤ���true ��
|
248
|
+
flase �����ꤷ�Ƥ���������((<"�֥��å���/��֥��å��⡼��">))
|
249
|
+
�Ȥ��Ƥ���������
|
250
|
+
|
251
|
+
|
252
|
+
--- OCI8#break()
|
253
|
+
�¹����¾����åɤ� OCI �ƽФ���뤷�ޤ������Υ�åɤ�
|
254
|
+
�¹Ԥ���ˤ���֥��å��⡼�ɤǤ���ɬ�פ�����ޤ���
|
255
|
+
((<"�֥��å���/��֥��å��⡼��">))�Ȥ��Ƥ���������
|
256
|
+
|
257
|
+
== OCI8::Cursor
|
258
|
+
--- OCI8::Cursor#define(pos, type, length = nil)
|
259
|
+
|
260
|
+
fetch �Ǽ�������ǡ����η�������Ū�˻��ꤹ�롣parse �� exec �δ�
|
261
|
+
�˼¹Ԥ��Ƥ���������pos �� 1 ��������ޤ���length �� type ��
|
262
|
+
String ����ꤷ���Ȥ���ͭ���Ǥ���
|
263
|
+
|
264
|
+
��:
|
265
|
+
cursor = conn.parse("SELECT ename, hiredate FROM emp")
|
266
|
+
cursor.define(1, String, 20) # 1������ܤ� String �Ȥ��� fetch
|
267
|
+
cursor.define(2, Time) # 2������ܤ� Time �Ȥ��� fetch
|
268
|
+
cursor.exec()
|
269
|
+
|
270
|
+
--- OCI8::Cursor#bind_param(key, val, type = nil, length = nil)
|
271
|
+
����Ū���ѿ���Х���ɤ��ޤ���
|
272
|
+
|
273
|
+
key �����ͤξ��ϡ��Х�����ѿ��ΰ��֤ˤ�äƥХ���ɤ��ޤ�����
|
274
|
+
�֤�1��������ޤ���key ��ʸ����ξ��ϡ��Х�����ѿ���̾���ˤ��
|
275
|
+
�ƥХ���ɤ��ޤ���
|
276
|
+
|
277
|
+
��:
|
278
|
+
cursor = conn.parse("SELECT * FROM emp WHERE ename = :ename")
|
279
|
+
cursor.bind_param(1, 'SMITH') # bind by position
|
280
|
+
...or...
|
281
|
+
cursor.bind_param(':ename', 'SMITH') # bind by name
|
282
|
+
|
283
|
+
���ͤ�Х���ɤ����硢Fixnum �� Float ���ȤäƤ���������Bignum
|
284
|
+
�ϻ��ѤǤ��ޤ�����ͤ� NULL �ˤ�����ϡ�val �� nil �ˤ��ơ�
|
285
|
+
type ��Fixnum �� Float �ˤ��Ƥ���������
|
286
|
+
|
287
|
+
��:
|
288
|
+
cursor.bind_param(1, 1234) # bind as Fixnum, Initial value is 1234.
|
289
|
+
cursor.bind_param(1, 1234.0) # bind as Float, Initial value is 1234.0.
|
290
|
+
cursor.bind_param(1, nil, Fixnum) # bind as Fixnum, Initial value is NULL.
|
291
|
+
cursor.bind_param(1, nil, Float) # bind as Float, Initial value is NULL.
|
292
|
+
|
293
|
+
ʸ�����Х���ɤ����硢val �ˤ��ΤޤޥХ���ɤ���ʸ������ꤷ
|
294
|
+
�Ƥ����������Х���ɤ����ϤȤ��ƻȤ����硢���Ϥ���Τ�ɬ�פ�
|
295
|
+
Ĺ����ʸ������ꤹ�뤫��type �� String ����ꤷ����� length ���
|
296
|
+
�ꤷ�Ƥ���������
|
297
|
+
|
298
|
+
��:
|
299
|
+
cursor = conn.parse("BEGIN :out := :in || '_OUT'; END;")
|
300
|
+
cursor.bind_param(':in', 'DATA') # bind as String with width 4.
|
301
|
+
cursor.bind_param(':out', nil, String, 7) # bind as String with width 7.
|
302
|
+
cursor.exec()
|
303
|
+
p cursor[':out'] # => 'DATA_OU'
|
304
|
+
# PL/SQL�֥��å���Ǥ� :out �� 8�Х��Ȥ�������7��ʸ���Ȥ��ƥХ����
|
305
|
+
# ���Ƥ���Τǡ�7�Х����ܤ��ڤ�Ƥ���
|
306
|
+
|
307
|
+
ʸ����� RAW ���Ȥ��ƥХ���ɤ������ɬ�� type �� OCI8::RAW ��
|
308
|
+
���ꤷ�Ƥ���������
|
309
|
+
|
310
|
+
��:
|
311
|
+
cursor = conn.parse("INSERT INTO raw_table(raw_column) VALUE (:1)")
|
312
|
+
cursor.bind_param(1, 'RAW_STRING', OCI8::RAW)
|
313
|
+
cursor.exec()
|
314
|
+
cursor.close()
|
315
|
+
|
316
|
+
--- OCI8::Cursor#[](key)
|
317
|
+
�Х�����ѿ����ͤ���Ф��ޤ���
|
318
|
+
|
319
|
+
����Ū�˥Х���ɤ�����硢((<OCI8::Cursor#bind_param>))�ǻ��ꤷ��
|
320
|
+
key �Ǥ�äƼ��Ф��ޤ������֤ˤ��Х���ɡ�̾���ˤ��Х����
|
321
|
+
�����ߤ�����硢Ʊ�����Ǥ���ꤷ���Х������ˡ���б����� key ��
|
322
|
+
�Ѥ��Ƥ���������
|
323
|
+
|
324
|
+
��:
|
325
|
+
cursor = conn.parse("BEGIN :out := 'BAR'; END;")
|
326
|
+
cursor.bind_param(':out', 'FOO') # bind by name
|
327
|
+
p cursor[':out'] # => 'FOO'
|
328
|
+
p cursor[1] # => nil
|
329
|
+
cursor.exec()
|
330
|
+
p cursor[':out'] # => 'BAR'
|
331
|
+
p cursor[1] # => nil
|
332
|
+
|
333
|
+
��:
|
334
|
+
cursor = conn.parse("BEGIN :out := 'BAR'; END;")
|
335
|
+
cursor.bind_param(1, 'FOO') # bind by position
|
336
|
+
p cursor[':out'] # => nil
|
337
|
+
p cursor[1] # => 'FOO'
|
338
|
+
cursor.exec()
|
339
|
+
p cursor[':out'] # => nil
|
340
|
+
p cursor[1] # => 'BAR'
|
341
|
+
|
342
|
+
((<OCI8#exec>))��((<OCI8::Cursor#exec>))����Ѥ��ƥХ���ɤ�����
|
343
|
+
�硢�Х�����ѿ��ΰ��֤Ǥ�äƼ������ޤ���
|
344
|
+
|
345
|
+
��:
|
346
|
+
cursor = conn.exec("BEGIN :out := 'BAR'; END;", 'FOO')
|
347
|
+
# 1st bind variable is bound as String with width 3. Its initial value is 'FOO'
|
348
|
+
# After execute, the value become 'BAR'.
|
349
|
+
p cursor[1] # => 'BAR'
|
350
|
+
|
351
|
+
--- OCI8::Cursor#[]=(key, val)
|
352
|
+
�Х�����ѿ����ͤ����ꤷ�ޤ���key �λ�����ˡ��
|
353
|
+
((<OCI8::Cursor#[]>))��Ʊ���Ǥ���((<OCI8::Cursor#bind_param>))�ǻ�
|
354
|
+
�ꤷ�� val �����֤����������Ȥ����ޤ����̤��ͤ��֤������Ʋ��٤�
|
355
|
+
((<OCI8::Cursor#exec>))��¹Ԥ������Ȥ��˻��Ѥ��Ƥ���������
|
356
|
+
|
357
|
+
�㣱:
|
358
|
+
cursor = conn.parse("INSERT INTO test(col1) VALUES(:1)")
|
359
|
+
cursor.bind_params(1, nil, String, 3)
|
360
|
+
['FOO', 'BAR', 'BAZ'].each do |key|
|
361
|
+
cursor[1] = key
|
362
|
+
cursor.exec
|
363
|
+
end
|
364
|
+
cursor.close()
|
365
|
+
|
366
|
+
�㣲:
|
367
|
+
['FOO', 'BAR', 'BAZ'].each do |key|
|
368
|
+
conn.exec("INSERT INTO test(col1) VALUES(:1)", key)
|
369
|
+
end
|
370
|
+
|
371
|
+
�㣱���㣲�Ϸ�̤�Ʊ���Ǥ������㣱�Τۤ�����٤����ʤ��ʤ�ޤ���
|
372
|
+
|
373
|
+
--- OCI8::Cursor#keys()
|
374
|
+
�Х�����ѿ��� key ������ˤ����֤��ޤ���
|
375
|
+
|
376
|
+
--- OCI8::Cursor#exec(*bindvars)
|
377
|
+
��������˳����Ƥ�줿 SQL ��¹Ԥ��ޤ���SQL �� SELECTʸ��
|
378
|
+
INSERT/UPDATE/DELETEʸ��CREATE/ALTER/DROPʸ��PL/SQLʸ�����줾���
|
379
|
+
�������ͤμ��ब�ۤʤ�ޤ���
|
380
|
+
|
381
|
+
|
382
|
+
SELECTʸ�ξ�硢select-list �ο����֤�ޤ���
|
383
|
+
|
384
|
+
INSERT/UPDATE/DELETEʸ�ξ�硢���줾����������Կ����֤�ޤ���
|
385
|
+
|
386
|
+
CREATE/ALTER/DROPʸ��PL/SQLʸ�ξ�硢true ���֤�ޤ���
|
387
|
+
((<OCI8#exec>))�Ǥ� PL/SQLʸ�ξ�硢�Х�����ѿ����ͤ�����Ȥʤä�
|
388
|
+
�֤�ޤ��������Υ�åɤǤ�ñ�� true ���֤�ޤ����Х�����ѿ���
|
389
|
+
�ͤ�((<OCI8::Cursor#[]>))�Ǥ�ä�����Ū�˼������Ƥ���������
|
390
|
+
|
391
|
+
--- OCI8::Cursor#type
|
392
|
+
SQLʸ�μ����������ޤ�������ͤϡ�
|
393
|
+
* OCI8::STMT_SELECT
|
394
|
+
* OCI8::STMT_UPDATE
|
395
|
+
* OCI8::STMT_DELETE
|
396
|
+
* OCI8::STMT_INSERT
|
397
|
+
* OCI8::STMT_CREATE
|
398
|
+
* OCI8::STMT_DROP
|
399
|
+
* OCI8::STMT_ALTER
|
400
|
+
* OCI8::STMT_BEGIN
|
401
|
+
* OCI8::STMT_DECLARE
|
402
|
+
�Τɤ줫�Ǥ���PL/SQLʸ�ξ��ϡ�OCI8::STMT_BEGIN ��
|
403
|
+
OCI8::STMT_DECLARE �Ȥʤ�ޤ���
|
404
|
+
|
405
|
+
--- OCI8::Cursor#row_count
|
406
|
+
���������Կ����֤��ޤ���
|
407
|
+
|
408
|
+
--- OCI8::Cursor#get_col_names
|
409
|
+
����ꥹ�Ȥ�̾��������Ǽ������ޤ���SELECT ʸ�ˤΤ�ͭ���Ǥ���ɬ�� exec ������˻��Ѥ��Ƥ���������
|
410
|
+
|
411
|
+
--- OCI8::Cursor#getColNames
|
412
|
+
((<OCI8::Cursor#get_col_names>)) �ؤΥ����ꥢ���Ǥ���
|
413
|
+
|
414
|
+
--- OCI8::Cursor#fetch()
|
415
|
+
SELECT ʸ�Τߤ�ͭ���Ǥ����ե��å������ǡ���������Ȥ����֤�ޤ���
|
416
|
+
|
417
|
+
��:
|
418
|
+
conn = OCI8.new('scott', 'tiger')
|
419
|
+
cursor = conn.exec('SELECT * FROM emp')
|
420
|
+
while r = cursor.fetch()
|
421
|
+
puts r.join(',')
|
422
|
+
end
|
423
|
+
cursor.close
|
424
|
+
conn.logoff
|
425
|
+
|
426
|
+
--- OCI8::Cursor#close()
|
427
|
+
����������������ޤ���
|
428
|
+
|
429
|
+
--- OCI8::Cursor#rowid
|
430
|
+
���¹Ԥ��Ƥ���Ԥ� ROWID ��������ޤ���
|
431
|
+
����������줿�ͤϥХ�����ͤȤ��ƻ��ѤǤ��ޤ���
|
432
|
+
�դ˸����ȡ��Х���ɤ�����Ū�ˤ������ѤǤ��ޤ���
|
433
|
+
|
434
|
+
== OCI8::BLOB
|
435
|
+
--- OCI8::BLOB#available?
|
436
|
+
BLOB ��ͭ�����ɤ��������å����ޤ���
|
437
|
+
BLOB ����Ѥ��뤿��ˤϺǽ�˶���BLOB����������ɬ�פ�����ޤ���
|
438
|
+
|
439
|
+
��:
|
440
|
+
conn.exec("CREATE TABLE photo (name VARCHAR2(50), image BLOB)")
|
441
|
+
conn.exec("INSERT INTO photo VALUES ('null-data', NULL)")
|
442
|
+
conn.exec("INSERT INTO photo VALUES ('empty-data', EMPTY_BLOB())")
|
443
|
+
conn.exec("SELECT name, image FROM photo") do |name, image|
|
444
|
+
case name
|
445
|
+
when 'null-data'
|
446
|
+
puts "#{name} => #{image.available?.to_s}"
|
447
|
+
# => false
|
448
|
+
when 'empty-data'
|
449
|
+
puts "#{name} => #{image.available?.to_s}"
|
450
|
+
# => true
|
451
|
+
end
|
452
|
+
end
|
453
|
+
|
454
|
+
--- OCI8::BLOB#read(size = nil)
|
455
|
+
BLOB ���ǡ������ɤ߹��ߤޤ���size �λ��꤬�ʤ����ϥǡ����κ�
|
456
|
+
��ޤ��ɤ߹��ߤޤ���
|
457
|
+
|
458
|
+
�㣱: BLOB �Υ������������ɤ߹��ߡ�
|
459
|
+
conn.exec("SELECT name, image FROM photo") do |name, image|
|
460
|
+
chunk_size = image.chunk_size
|
461
|
+
File.open(name, 'w') do |f|
|
462
|
+
until image.eof?
|
463
|
+
f.write(image.read(chunk_size))
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
�㣲: �����ɤ߹��ߡ�
|
469
|
+
conn.exec("SELECT name, image FROM photo") do |name, image|
|
470
|
+
File.open(name, 'w') do |f|
|
471
|
+
f.write(image.read)
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
--- OCI8::BLOB#write(data)
|
476
|
+
BLOB �إǡ�������ߤޤ���
|
477
|
+
BLOB �˸������äƤ����ǡ�����Ĺ����������ǡ������Ĺ������
|
478
|
+
((<OCI8::BLOB#size=>)) ��Ĺ���κ������ԤäƤ���������
|
479
|
+
|
480
|
+
�㣱: BLOB �Υ����������˽���
|
481
|
+
cursor = conn.parse("INSERT INTO photo VALUES(:name, EMPTY_BLOB())")
|
482
|
+
Dir["*.png"].each do |fname|
|
483
|
+
cursor.exec(fname)
|
484
|
+
end
|
485
|
+
conn.exec("SELECT name, image FROM photo") do |name, image|
|
486
|
+
chunk_size = image.chunk_size
|
487
|
+
File.open(name, 'r') do |f|
|
488
|
+
until f.eof?
|
489
|
+
image.write(f.read(chunk_size))
|
490
|
+
end
|
491
|
+
image.size = f.pos
|
492
|
+
end
|
493
|
+
end
|
494
|
+
conn.commit
|
495
|
+
|
496
|
+
�㣲: ���˽���
|
497
|
+
conn.exec("SELECT name, image FROM photo") do |name, image|
|
498
|
+
File.open(name, 'r') do |f|
|
499
|
+
image.write(f.read)
|
500
|
+
image.size = f.pos
|
501
|
+
end
|
502
|
+
end
|
503
|
+
|
504
|
+
--- OCI8::BLOB#size
|
505
|
+
BLOB �Υǡ�����Ĺ�����֤��ޤ���
|
506
|
+
|
507
|
+
--- OCI8::BLOB#size=(len)
|
508
|
+
BLOB �Υǡ�����Ĺ���� len �����ꤷ�ޤ���
|
509
|
+
|
510
|
+
--- OCI8::BLOB#chunk_size
|
511
|
+
BLOB �Υ�����������֤��ޤ���
|
512
|
+
|
513
|
+
--- OCI8::BLOB#truncate(len)
|
514
|
+
BLOB �Υǡ�����Ĺ���� len �����ꤷ�ޤ���
|
515
|
+
|
516
|
+
--- OCI8::BLOB#pos
|
517
|
+
����� read/write �γ��ϰ��֤��֤��ޤ���
|
518
|
+
|
519
|
+
--- OCI8::BLOB#pos=(pos)
|
520
|
+
����� read/write �γ��ϰ��֤����ꤷ�ޤ���
|
521
|
+
|
522
|
+
--- OCI8::BLOB#eof?
|
523
|
+
BLOB �κǸ����ã�������ɤ������֤��ޤ���
|
524
|
+
|
525
|
+
--- OCI8::BLOB#tell
|
526
|
+
((<OCI8::BLOB#pos>)) ��Ʊ���Ǥ���
|
527
|
+
|
528
|
+
--- OCI8::BLOB#seek(pos)
|
529
|
+
((<OCI8::BLOB#pos=>)) ��Ʊ���Ǥ���
|
530
|
+
|
531
|
+
--- OCI8::BLOB#rewind
|
532
|
+
����� read/write �γ��ϰ��֤� 0 �����ꤷ�ޤ���
|
533
|
+
|
534
|
+
== ���
|
535
|
+
=== �֥��å���/��֥��å��⡼��
|
536
|
+
�ǥե���Ȥϥ֥��å��⡼�ɤˤʤäƤ��ޤ���((<OCI8#non_blocking=>))
|
537
|
+
�ǥ⡼�ɤ��ѹ��Ǥ��ޤ���
|
538
|
+
|
539
|
+
�֥��å��⡼�ɤξ�硢�Ť� OCI �θƽФ��Ƥ���ȡ�����åɤ�Ȥ�
|
540
|
+
�Ƥ��Ƥ� ruby ���Τ��֥��å�����ޤ�������ϡ�ruby �Υ���åɤϥͥ��ƥ�
|
541
|
+
�֥���åɤǤϤʤ�����Ǥ���
|
542
|
+
|
543
|
+
��֥��å��⡼�ɤξ�硢�Ť� OCI �θƽФ��Ǥ� ruby ���Τϥ֥��å�
|
544
|
+
����ޤ���OCI ��ƽФ��Ƥ��륹��åɤΤߤ��֥��å����ޤ������Τ���ꡢ
|
545
|
+
OCI �ƽФ�����λ���Ƥ��뤫�ɤ����ݡ���ˤ�äƥ����å����Ƥ���Τǡ�
|
546
|
+
�ġ��� OCI �ƽФ��������٤��ʤ�ޤ���
|
547
|
+
|
548
|
+
((<OCI8#break>)) ���Ѥ���ȡ��̤Υ���åɤ���Ť� OCI �ƽФ����Ǥ�
|
549
|
+
�ޤ�������뤵�줿����åɤǤ� ((|OCIBreak|)) �Ȥ����㳰��ޤ���
|
550
|
+
|
551
|
+
��֥��å��⡼�ɤ����»���: �̡��Υ���åɤ�Ʊ����³���Ф���Ʊ����
|
552
|
+
OCI �ƽФ���Ԥ�ʤ��Ǥ���������OCI �饤�֥��¦����֥��å��⡼��
|
553
|
+
�Ǥθ�ߤθƽФ����б����Ƥ��뤫�ɤ��������Ǥ������ޤ���ruby �Υ⥸�塼
|
554
|
+
��¦�Ǥ⡢((<OCI8#break>)) ��¹Ԥ����Ȥ��˥���뤹��OCI �ƽФ���
|
555
|
+
ʣ�������硢���ߤμ����Ǥ��б��Ǥ��ޤ���
|
556
|
+
|
557
|
+
=end
|