Class: ODPI::Dpi::Lob

Inherits:
Object
  • Object
show all
Defined in:
ext/odpi_ext/rbdpi-lob.c

Instance Method Summary collapse

Constructor Details

#initializeObject


41
42
43
44
45
# File 'ext/odpi_ext/rbdpi.c', line 41

VALUE rbdpi_initialize_error(VALUE self)
{
    rb_raise(rb_eRuntimeError, "could not initialize by %s::new", rb_obj_classname(self));
    return Qnil;
}

Instance Method Details

#buffer_size(size_in_chars) ⇒ Object


88
89
90
91
92
93
94
95
# File 'ext/odpi_ext/rbdpi-lob.c', line 88

static VALUE lob_get_buffer_size(VALUE self, VALUE size_in_chars)
{
    lob_t *lob = rbdpi_to_lob(self);
    uint64_t size_in_bytes;

    CHK(dpiLob_getBufferSize(lob->handle, NUM2ULL(size_in_chars), &size_in_bytes));
    return ULL2NUM(size_in_bytes);
}

#chunk_sizeObject


97
98
99
100
101
102
103
104
# File 'ext/odpi_ext/rbdpi-lob.c', line 97

static VALUE lob_get_chunk_size(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);
    uint32_t size;

    CHK(dpiLob_getChunkSize(lob->handle, &size));
    return UINT2NUM(size);
}

#closeObject


72
73
74
75
76
77
78
# File 'ext/odpi_ext/rbdpi-lob.c', line 72

static VALUE lob_close(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);

    CHK(dpiLob_close(lob->handle));
    return self;
}

#close_resourceObject


80
81
82
83
84
85
86
# File 'ext/odpi_ext/rbdpi-lob.c', line 80

static VALUE lob_close_resource(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);

    CHK(dpiLob_closeResource(lob->handle));
    return self;
}

#directory_and_file_nameObject


106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'ext/odpi_ext/rbdpi-lob.c', line 106

static VALUE lob_get_directory_and_file_name(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);
    const char *dir;
    uint32_t dirlen;
    const char *fname;
    uint32_t fnamelen;

    CHK(dpiLob_getDirectoryAndFileName(lob->handle, &dir, &dirlen, &fname, &fnamelen));
    return rb_ary_new_from_args(2,
                                rb_external_str_new_with_enc(dir, dirlen, lob->enc.enc),
                                rb_external_str_new_with_enc(fname, fnamelen, lob->enc.enc));
}

#file_exists?Boolean

Returns:

  • (Boolean)

120
121
122
123
124
125
126
127
# File 'ext/odpi_ext/rbdpi-lob.c', line 120

static VALUE lob_file_exists_p(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);
    int exists;

    CHK(dpiLob_getFileExists(lob->handle, &exists));
    return exists ? Qtrue : Qfalse;
}

#initialize_copy(other) ⇒ Object


58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'ext/odpi_ext/rbdpi-lob.c', line 58

static VALUE lob_initialize_copy(VALUE self, VALUE other)
{
    lob_t *lob = rbdpi_to_lob(self);

    *lob = *rbdpi_to_lob(other);
    if (lob->handle != NULL) {
        dpiLob *oldlob = lob->handle;

        lob->handle = NULL;
        CHK(dpiLob_copy(oldlob, &lob->handle));
    }
    return self;
}

#is_resource_open?Boolean

Returns:

  • (Boolean)

129
130
131
132
133
134
135
136
# File 'ext/odpi_ext/rbdpi-lob.c', line 129

static VALUE lob_is_resource_open_p(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);
    int is_open;

    CHK(dpiLob_getIsResourceOpen(lob->handle, &is_open));
    return is_open ? Qtrue : Qfalse;
}

#open_resourceObject


147
148
149
150
151
152
153
# File 'ext/odpi_ext/rbdpi-lob.c', line 147

static VALUE lob_open_resource(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);

    CHK(dpiLob_openResource(lob->handle));
    return self;
}

#read(offset, amount) ⇒ Object


155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'ext/odpi_ext/rbdpi-lob.c', line 155

static VALUE lob_read(VALUE self, VALUE offset, VALUE amount)
{
    lob_t *lob = rbdpi_to_lob(self);
    uint64_t off = NUM2ULL(offset);
    uint64_t amt = NUM2ULL(amount);
    VALUE str;
    uint64_t len;

    CHK(dpiLob_getBufferSize(lob->handle, amt, &len));
    str = rb_str_buf_new(len);

    CHK(dpiLob_readBytes(lob->handle, off, amt, RSTRING_PTR(str), &len));
    rb_str_set_len(str, len);
    switch (lob->oracle_type) {
    case DPI_ORACLE_TYPE_CLOB:
        rb_enc_associate(str, lob->enc.enc);
        break;
    case DPI_ORACLE_TYPE_NCLOB:
        rb_enc_associate(str, lob->enc.nenc);
        break;
    default:
        break;
    }
    OBJ_TAINT(str);
    return str;
}

#set(val) ⇒ Object


197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'ext/odpi_ext/rbdpi-lob.c', line 197

static VALUE lob_set(VALUE self, VALUE val)
{
    lob_t *lob = rbdpi_to_lob(self);

    switch (lob->oracle_type) {
    case DPI_ORACLE_TYPE_CLOB:
        CHK_STR_ENC(val, lob->enc.enc);
        break;
    case DPI_ORACLE_TYPE_NCLOB:
        CHK_STR_ENC(val, lob->enc.nenc);
        break;
    default:
        SafeStringValue(val);
    }

    CHK(dpiLob_setFromBytes(lob->handle, RSTRING_PTR(val), RSTRING_LEN(val)));
    RB_GC_GUARD(val);
    return self;
}

#set_directory_and_file_name(dir, fname) ⇒ Object


182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'ext/odpi_ext/rbdpi-lob.c', line 182

static VALUE lob_set_directory_and_file_name(VALUE self, VALUE dir, VALUE fname)
{
    lob_t *lob = rbdpi_to_lob(self);

    CHK_STR_ENC(dir, lob->enc.enc);
    CHK_STR_ENC(fname, lob->enc.enc);

    CHK(dpiLob_setDirectoryAndFileName(lob->handle,
                                       RSTRING_PTR(dir), RSTRING_LEN(dir),
                                       RSTRING_PTR(fname), RSTRING_LEN(fname)));
    RB_GC_GUARD(dir);
    RB_GC_GUARD(fname);
    return self;
}

#sizeObject


138
139
140
141
142
143
144
145
# File 'ext/odpi_ext/rbdpi-lob.c', line 138

static VALUE lob_get_size(VALUE self)
{
    lob_t *lob = rbdpi_to_lob(self);
    uint64_t size;

    CHK(dpiLob_getSize(lob->handle, &size));
    return ULL2NUM(size);
}

#trim(new_size) ⇒ Object


217
218
219
220
221
222
223
# File 'ext/odpi_ext/rbdpi-lob.c', line 217

static VALUE lob_trim(VALUE self, VALUE new_size)
{
    lob_t *lob = rbdpi_to_lob(self);

    CHK(dpiLob_trim(lob->handle, NUM2ULL(new_size)));
    return self;
}

#write(offset, val) ⇒ Object


225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'ext/odpi_ext/rbdpi-lob.c', line 225

static VALUE lob_write(VALUE self, VALUE offset, VALUE val)
{
    lob_t *lob = rbdpi_to_lob(self);

    switch (lob->oracle_type) {
    case DPI_ORACLE_TYPE_CLOB:
        CHK_STR_ENC(val, lob->enc.enc);
        break;
    case DPI_ORACLE_TYPE_NCLOB:
        CHK_STR_ENC(val, lob->enc.nenc);
        break;
    default:
        SafeStringValue(val);
    }

    CHK(dpiLob_writeBytes(lob->handle, NUM2ULL(offset), RSTRING_PTR(val), RSTRING_LEN(val)));
    RB_GC_GUARD(val);
    return self;
}