Class: OCILobLocator
- Inherits:
-
OCIDescriptor
- Object
- OCIDescriptor
- OCILobLocator
- Defined in:
- ext/oci8/oci8.c
Direct Known Subclasses
Instance Method Summary collapse
- #char_width=(vsize) ⇒ Object
- #clone(vsvc) ⇒ Object
- #close(vsvc) ⇒ Object
- #create_temporary(vsvc, vcsid, vcsfrm, vlobtype, vcache, vduration) ⇒ Object
- #getChunkSize(vsvc) ⇒ Object
-
#getLength(vsvc) ⇒ Object
begin — OCILobLocator#GetLength() get the length of LOB.
- #is_initialized?(venv) ⇒ Boolean
- #open(*args) ⇒ Object
- #read(*args) ⇒ Object
- #trim(vsvc, len) ⇒ Object
- #write(*args) ⇒ Object
Methods inherited from OCIDescriptor
#attrGet, #attrSet, #free, new
Instance Method Details
#char_width=(vsize) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'ext/oci8/lob.c', line 6
static VALUE oci8_lob_set_char_width(VALUE self, VALUE vsize)
{
oci8_handle_t *h;
int size;
Get_Handle(self, h); /* 0 */
size = NUM2INT(vsize); /* 1 */
if (size <= 0)
rb_raise(rb_eArgError, "size must be more than one.");
h->u.lob_locator.char_width = size;
return vsize;
}
|
#clone(vsvc) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'ext/oci8/lob.c', line 200
static VALUE oci8_lob_clone(VALUE self, VALUE vsvc)
{
oci8_handle_t *h;
oci8_handle_t *svch;
oci8_handle_t *envh;
oci8_handle_t *newh;
OCILobLocator *hp;
sword rv;
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
/* get environment handle */
for (envh = h; envh->type != OCI_HTYPE_ENV; envh = envh->parent);
rv = OCIDescriptorAlloc(envh->hp, (void *)&hp, h->type, 0, NULL);
if (rv != OCI_SUCCESS) {
oci8_env_raise(envh->hp, rv);
}
#ifdef HAVE_OCILOBLOCATORASSIGN
/* Oracle 8.1 or upper */
rv = OCILobLocatorAssign(svch->hp, h->errhp, h->hp, &hp);
#else
/* Oracle 8.0 */
rv = OCILobAssign(envh->hp, h->errhp, h->hp, &hp);
#endif
if (rv != OCI_SUCCESS) {
OCIDescriptorFree(hp, h->type);
oci8_raise(h->errhp, rv, NULL);
}
newh = oci8_make_handle(h->type, hp, h->errhp, h->parent, 0);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return newh->self;
}
|
#close(vsvc) ⇒ Object
262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'ext/oci8/lob.c', line 262
static VALUE oci8_lob_close(VALUE self, VALUE vsvc)
{
oci8_handle_t *h;
oci8_handle_t *svch;
sword rv;
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
rv = OCILobClose(svch->hp, h->errhp, h->hp);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return self;
}
|
#create_temporary(vsvc, vcsid, vcsfrm, vlobtype, vcache, vduration) ⇒ Object
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'ext/oci8/lob.c', line 332
static VALUE oci8_lob_create_temporary(VALUE self, VALUE vsvc, VALUE vcsid, VALUE vcsfrm, VALUE vlobtype, VALUE vcache, VALUE vduration)
{
#ifdef HAVE_OCILOBCREATETEMPORARY
oci8_handle_t *h;
oci8_handle_t *svch;
ub2 csid;
ub1 csfrm;
ub1 lobtype;
boolean cache;
OCIDuration duration;
sword rv;
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
csid = NIL_P(vcsid) ? 0 : NUM2INT(vcsid); /* 2 */
csfrm = NIL_P(vcsfrm) ? SQLCS_IMPLICIT : NUM2INT(vcsfrm); /* 3 */
lobtype = NUM2INT(vlobtype); /* 4 */
cache = RTEST(vcache) ? TRUE : FALSE; /* 5 */
duration = NIL_P(vduration) ? OCI_DURATION_SESSION : NUM2INT(vduration); /* 6 */
rv = OCILobCreateTemporary(svch->hp, h->errhp, h->hp, csid, csfrm, lobtype, cache, duration);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return self;
#else
rb_notimplement();
#endif
}
|
#getChunkSize(vsvc) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'ext/oci8/lob.c', line 62
static VALUE oci8_lob_get_chunk_size(VALUE self, VALUE vsvc)
{
oci8_handle_t *h;
oci8_handle_t *svch;
ub4 len;
sword rv;
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
rv = OCILobGetChunkSize(svch->hp, h->errhp, h->hp, &len);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return INT2FIX(len);
}
|
#getLength(vsvc) ⇒ Object
begin
— OCILobLocator#GetLength()
get the length of LOB.
counts by bytes for BLOB, by charactors for CLOB.
end
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'ext/oci8/lob.c', line 45
static VALUE oci8_lob_get_length(VALUE self, VALUE vsvc)
{
oci8_handle_t *h;
oci8_handle_t *svch;
ub4 len;
sword rv;
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
rv = OCILobGetLength(svch->hp, h->errhp, h->hp, &len);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return INT2FIX(len);
}
|
#is_initialized?(venv) ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'ext/oci8/lob.c', line 21
static VALUE oci8_lob_is_initialized_p(VALUE self, VALUE venv)
{
oci8_handle_t *h;
oci8_handle_t *envh;
boolean is_initialized;
sword rv;
Get_Handle(self, h); /* 0 */
Check_Handle(venv, OCIEnv, envh); /* 1 */
rv = OCILobLocatorIsInit(envh->hp, h->errhp, h->hp, &is_initialized);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return is_initialized ? Qtrue : Qfalse;
}
|
#open(*args) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'ext/oci8/lob.c', line 236
static VALUE oci8_lob_open(int argc, VALUE *argv, VALUE self)
{
VALUE vsvc;
VALUE vmode = Qnil;
oci8_handle_t *h;
oci8_handle_t *svch;
ub1 mode;
sword rv;
rb_scan_args(argc, argv, "11", &vsvc, &vmode);
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
if (vmode == Qnil)
mode = OCI_DEFAULT;
else if (vmode == sym_file_readonly)
mode = OCI_FILE_READONLY;
else
rb_raise(rb_eArgError, "expect nil or :file_readonly");
rv = OCILobOpen(svch->hp, h->errhp, h->hp, mode);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return self;
}
|
#read(*args) ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'ext/oci8/lob.c', line 94
static VALUE oci8_lob_read(int argc, VALUE *argv, VALUE self)
{
VALUE vsvc, voffset, vamt, vcsid, vcsfrm;
oci8_handle_t *h;
oci8_handle_t *svch;
ub4 offset;
ub2 csid;
ub1 csfrm;
ub4 amt;
sword rv;
char buf[4096];
#ifndef OCI8_USE_CALLBACK_LOB_READ
size_t buf_size_in_char;
#endif
VALUE v = Qnil;
rb_scan_args(argc, argv, "32", &vsvc, &voffset, &vamt, &vcsid, &vcsfrm);
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
offset = NUM2INT(voffset); /* 2 */
amt = NUM2INT(vamt); /* 3 */
csid = NIL_P(vcsid) ? 0 : NUM2INT(vcsid); /* 4 */
csfrm = NIL_P(vcsfrm) ? SQLCS_IMPLICIT : NUM2INT(vcsfrm); /* 5 */
#ifdef OCI8_USE_CALLBACK_LOB_READ
/* This raises ORA-24812, when the size of readed data is two or
* three times longer than the size of buf. I couldn't fix it. Thus
* I use polling way instead of callback method.
*/
rv = OCILobRead(svch->hp, h->errhp, h->hp, &amt, offset, buf, sizeof(buf), &v, oci8_callback_lob_read, csid, csfrm);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
#else
/* Disadvantage of polling way in contrast with callback method is
* that it sets 'amt' the number of characters readed, when charset
* is fixed size. For single byte charset or variable size charset,
* it cause no problem because the unit of 'amt' is byte. But for
* fixed size multibyte charset, how can I know the size of a
* character from system? Therefore who want to use fixed size
* multibyte charset must set the size explicitly.
*
* Umm, if I could use callback method, I have no need to care about
* it.
*/
buf_size_in_char = sizeof(buf) / h->u.lob_locator.char_width;
do {
rv = OCILobRead(svch->hp, h->errhp, h->hp, &amt, offset, buf, sizeof(buf), NULL, NULL, csid, csfrm);
if (rv != OCI_SUCCESS && rv != OCI_NEED_DATA)
oci8_raise(h->errhp, rv, NULL);
if (amt == 0)
break;
/* for fixed size charset, amt is the number of characters stored in buf. */
if (amt > buf_size_in_char)
rb_raise(eOCIException, "Too large buffer fetched or you set too large size of a character.");
amt *= h->u.lob_locator.char_width;
if (v == Qnil)
v = rb_str_new(buf, amt);
else
v = rb_str_cat(v, buf, amt);
} while (rv == OCI_NEED_DATA);
#endif
return v;
}
|
#trim(vsvc, len) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'ext/oci8/lob.c', line 185
static VALUE oci8_lob_trim(VALUE self, VALUE vsvc, VALUE len)
{
oci8_handle_t *h;
oci8_handle_t *svch;
sword rv;
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
rv = OCILobTrim(svch->hp, h->errhp, h->hp, NUM2INT(len));
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return self;
}
|
#write(*args) ⇒ Object
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'ext/oci8/lob.c', line 158
static VALUE oci8_lob_write(int argc, VALUE *argv, VALUE self)
{
VALUE vsvc, voffset, vbuf, vcsid, vcsfrm;
oci8_handle_t *h;
oci8_handle_t *svch;
oci8_string_t buf;
ub4 offset;
ub2 csid;
ub1 csfrm;
ub4 amt;
sword rv;
rb_scan_args(argc, argv, "32", &vsvc, &voffset, &vbuf, &vcsid, &vcsfrm);
Get_Handle(self, h); /* 0 */
Check_Handle(vsvc, OCISvcCtx, svch); /* 1 */
offset = NUM2INT(voffset); /* 2 */
Get_String(vbuf, buf); /* 3 */
csid = NIL_P(vcsid) ? 0 : NUM2INT(vcsid); /* 4 */
csfrm = NIL_P(vcsfrm) ? SQLCS_IMPLICIT : NUM2INT(vcsfrm); /* 5 */
amt = buf.len;
rv = OCILobWrite(svch->hp, h->errhp, h->hp, &amt, offset, buf.ptr, buf.len, OCI_ONE_PIECE, NULL, NULL, csid, csfrm);
if (rv != OCI_SUCCESS)
oci8_raise(h->errhp, rv, NULL);
return INT2FIX(amt);
}
|