Class: OracleDB::Object

Inherits:
Object
  • Object
show all
Defined in:
ext/oracledb/rboradb_object.c

Instance Method Summary collapse

Constructor Details

#initialize(objtype_obj) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'ext/oracledb/rboradb_object.c', line 119

static VALUE object_initialize(VALUE self, VALUE objtype_obj)
{
    Object_t *obj = To_Object(self);
    ObjectType_t *objtype = To_ObjectType(objtype_obj);

    RBORADB_INIT(obj, objtype->dconn);
    if (dpiObjectType_createObject(objtype->handle, &obj->handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(objtype);
    }
    obj->objtype = objtype->handle;
    dpiObjectType_addRef(obj->objtype);
    return Qnil;
}

Instance Method Details

#append_element(value) ⇒ Object



147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'ext/oracledb/rboradb_object.c', line 147

static VALUE object_append_element(VALUE self, VALUE value)
{
    Object_t *obj = To_Object(self);
    dpiData data = {1,};
    dpiNativeTypeNum native_type;
    VALUE gc_guard = set_element_value(&data, &native_type, obj->objtype, obj->dconn, value, true);

    if (dpiObject_appendElement(obj->handle, native_type, &data) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    RB_GC_GUARD(gc_guard);
    return Qnil;
}

#attribute_value(attr_type) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'ext/oracledb/rboradb_object.c', line 161

static VALUE object_attribute_value(VALUE self, VALUE attr_type)
{
    Object_t *obj = To_Object(self);
    ObjectAttr_t *attr = To_ObjectAttr(attr_type);
    dpiObjectAttrInfo info;
    dpiOracleTypeNum oracle_type;
    dpiNativeTypeNum native_type;
    dpiObjectType *objtype;
    dpiData value;

    if (dpiObjectAttr_getInfo(attr->handle, &info) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    oracle_type = info.typeInfo.oracleTypeNum;
    native_type = info.typeInfo.defaultNativeTypeNum;
    objtype = info.typeInfo.objectType;

    if (oracle_type == DPI_ORACLE_TYPE_NUMBER) {
        native_type = DPI_NATIVE_TYPE_BYTES;
    }
    if (dpiObject_getAttributeValue(obj->handle, attr->handle, native_type, &value) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return rboradb_from_data(&value, native_type, oracle_type, objtype, Qnil, obj->dconn);
}

#delete_element_by_index(index) ⇒ Object



187
188
189
190
191
192
193
194
195
# File 'ext/oracledb/rboradb_object.c', line 187

static VALUE object_delete_element_by_index(VALUE self, VALUE index)
{
    Object_t *obj = To_Object(self);

    if (dpiObject_deleteElementByIndex(obj->handle, NUM2INT(index)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return Qnil;
}

#element_exists_by_index(index) ⇒ Object



197
198
199
200
201
202
203
204
205
206
# File 'ext/oracledb/rboradb_object.c', line 197

static VALUE object_element_exists_by_index(VALUE self, VALUE index)
{
    Object_t *obj = To_Object(self);
    int exists;

    if (dpiObject_getElementExistsByIndex(obj->handle, NUM2INT(index), &exists) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return exists ? Qtrue : Qfalse;
}

#element_value_by_index(index) ⇒ Object



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/oracledb/rboradb_object.c', line 208

static VALUE object_element_value_by_index(VALUE self, VALUE index)
{
    Object_t *obj = To_Object(self);
    dpiObjectTypeInfo info;
    dpiOracleTypeNum oracle_type;
    dpiNativeTypeNum native_type;
    dpiObjectType *objtype;
    dpiData value;

    if (dpiObjectType_getInfo(obj->objtype, &info) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    if (!info.isCollection) {
        rb_raise(rb_eArgError, "self isn't a collection.");
    }
    oracle_type = info.elementTypeInfo.oracleTypeNum;
    native_type = info.elementTypeInfo.defaultNativeTypeNum;
    objtype = info.elementTypeInfo.objectType;
    if (oracle_type == DPI_ORACLE_TYPE_NUMBER) {
        native_type = DPI_NATIVE_TYPE_BYTES;
    }
    if (dpiObject_getElementValueByIndex(obj->handle, NUM2INT(index), native_type, &value) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return rboradb_from_data(&value, native_type, oracle_type, objtype, Qnil, obj->dconn);
}

#first_indexObject



235
236
237
238
239
240
241
242
243
244
245
# File 'ext/oracledb/rboradb_object.c', line 235

static VALUE object_first_index(VALUE self)
{
    Object_t *obj = To_Object(self);
    int32_t index;
    int exists;

    if (dpiObject_getFirstIndex(obj->handle, &index, &exists) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return exists ? INT2NUM(index) : Qnil;
}

#last_indexObject



247
248
249
250
251
252
253
254
255
256
257
# File 'ext/oracledb/rboradb_object.c', line 247

static VALUE object_last_index(VALUE self)
{
    Object_t *obj = To_Object(self);
    int32_t index;
    int exists;

    if (dpiObject_getLastIndex(obj->handle, &index, &exists) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return exists ? INT2NUM(index) : Qnil;
}

#next_index(index) ⇒ Object



259
260
261
262
263
264
265
266
267
268
269
# File 'ext/oracledb/rboradb_object.c', line 259

static VALUE object_next_index(VALUE self, VALUE index)
{
    Object_t *obj = To_Object(self);
    int32_t next_index;
    int exists;

    if (dpiObject_getNextIndex(obj->handle, NUM2INT(index), &next_index, &exists) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return exists ? INT2NUM(next_index) : Qnil;
}

#prev_index(index) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
# File 'ext/oracledb/rboradb_object.c', line 271

static VALUE object_prev_index(VALUE self, VALUE index)
{
    Object_t *obj = To_Object(self);
    int32_t prev_index;
    int exists;

    if (dpiObject_getPrevIndex(obj->handle, NUM2INT(index), &prev_index, &exists) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return exists ? INT2NUM(prev_index) : Qnil;
}

#set_attribute_value(attr_type, value) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'ext/oracledb/rboradb_object.c', line 283

static VALUE object_set_attribute_value(VALUE self, VALUE attr_type, VALUE value)
{
    Object_t *obj = To_Object(self);
    ObjectAttr_t *attr = To_ObjectAttr(attr_type);
    dpiObjectAttrInfo info;
    dpiData data = {1,};
    dpiNativeTypeNum native_type;
    VALUE gc_guard;

    if (dpiObjectAttr_getInfo(attr->handle, &info) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(attr);
    }
    gc_guard = set_element_value(&data, &native_type, info.typeInfo.objectType, obj->dconn, value, false);
    if (dpiObject_setAttributeValue(obj->handle, attr->handle, native_type, &data) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    RB_GC_GUARD(gc_guard);
    return Qnil;
}

#set_element_value_by_index(index, value) ⇒ Object



303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'ext/oracledb/rboradb_object.c', line 303

static VALUE object_set_element_value_by_index(VALUE self, VALUE index, VALUE value)
{
    Object_t *obj = To_Object(self);
    int32_t idx = NUM2INT(index);
    dpiData data = {1,};
    dpiNativeTypeNum native_type;
    VALUE gc_guard = set_element_value(&data, &native_type, obj->objtype, obj->dconn, value, true);

    if (dpiObject_setElementValueByIndex(obj->handle, idx, native_type, &data) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    RB_GC_GUARD(gc_guard);
    return Qnil;
}

#sizeObject



318
319
320
321
# File 'ext/oracledb/rboradb_object.c', line 318

static VALUE object_size(VALUE self)
{
    GET_INT32(Object, Size);
}

#trim(num_to_trim) ⇒ Object



323
324
325
326
327
328
329
330
331
# File 'ext/oracledb/rboradb_object.c', line 323

static VALUE object_trim(VALUE self, VALUE num_to_trim)
{
    Object_t *obj = To_Object(self);

    if (dpiObject_trim(obj->handle, NUM2UINT(num_to_trim)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(obj);
    }
    return Qnil;
}