Class: ODPI::Dpi::Var

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

Instance Method Summary collapse

Constructor Details

#initialize(rb_conn, oracle_type, native_type, max_array_size, size, size_is_bytes, is_array, objtype) ⇒ Object


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'ext/odpi_ext/rbdpi-var.c', line 64

static VALUE var_initialize(VALUE self, VALUE rb_conn, VALUE oracle_type, VALUE native_type,
                          VALUE max_array_size, VALUE size, VALUE size_is_bytes,
                          VALUE is_array, VALUE objtype)
{
    var_t *var = (var_t *)rb_check_typeddata(self, &var_data_type);
    conn_t *conn = rbdpi_to_conn(rb_conn);
    dpiOracleTypeNum oracle_type_num = rbdpi_to_dpiOracleTypeNum(oracle_type);
    dpiNativeTypeNum native_type_num = rbdpi_to_dpiNativeTypeNum(native_type);
    dpiVar *handle;
    dpiData *data;

    if (var->handle != NULL) {
        rb_raise(rb_eRuntimeError, "Try to initialize an initialized connection");
    }

    CHK(dpiConn_newVar(conn->handle, oracle_type_num, native_type_num,
                       NUM2UINT(max_array_size), NUM2UINT(size), RTEST(size_is_bytes),
                       RTEST(is_array), NIL_P(objtype) ? NULL : rbdpi_to_object_type(objtype)->handle,
                       &handle, &data));
    var->handle = handle;
    var->enc = conn->enc;
    var->oracle_type = oracle_type_num;
    var->native_type = native_type_num;
    var->objtype = objtype;
    return Qnil;
}

Instance Method Details

#[](pos) ⇒ Object


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'ext/odpi_ext/rbdpi-var.c', line 127

static VALUE cvar_aref(VALUE self, VALUE pos)
{
    var_t *var = rbdpi_to_var(self);
    uint32_t idx, num;
    dpiData *data;
    VALUE val;

    idx = NUM2UINT(pos);
    CHK(dpiVar_getData(var->handle, &num, &data));
    if (idx >= num) {
        rb_raise(rb_eRuntimeError, "out of array index %u for %u", idx, num);
    }
    if (data[idx].isNull) {
        return Qnil;
    }
    val = rbdpi_from_dpiData2(data + idx, var->native_type, &var->enc, var->oracle_type, var->objtype);
    return val;
}

#[]=(pos, val) ⇒ Object


146
147
148
149
150
151
152
153
154
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
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'ext/odpi_ext/rbdpi-var.c', line 146

static VALUE cvar_aset(VALUE self, VALUE pos, VALUE val)
{
    var_t *var = rbdpi_to_var(self);
    uint32_t idx, num;
    dpiData *data;

    idx = NUM2UINT(pos);
    CHK(dpiVar_getData(var->handle, &num, &data));
    if (idx >= num) {
        rb_raise(rb_eRuntimeError, "out of array index %u for %u", idx, num);
    }
    if (NIL_P(val)) {
        data[idx].isNull = 1;
        return self;
    }
    switch (var->native_type) {
    case DPI_NATIVE_TYPE_BYTES:
        switch (rbdpi_ora2enc_type(var->oracle_type)) {
        case ENC_TYPE_CHAR:
            CHK_STR_ENC(val, var->enc.enc);
            break;
        case ENC_TYPE_NCHAR:
            CHK_STR_ENC(val, var->enc.nenc);
            break;
        case ENC_TYPE_OTHER:
            SafeStringValue(val);
            break;
        }
        CHK(dpiVar_setFromBytes(var->handle, idx, RSTRING_PTR(val), RSTRING_LEN(val)));
        RB_GC_GUARD(val);
        break;
    case DPI_NATIVE_TYPE_LOB:
        CHK(dpiVar_setFromLob(var->handle, idx, rbdpi_to_lob(val)->handle));
        break;
    case DPI_NATIVE_TYPE_OBJECT:
        CHK(dpiVar_setFromObject(var->handle, idx, rbdpi_to_object(val)->handle));
        break;
    case DPI_NATIVE_TYPE_ROWID:
        CHK(dpiVar_setFromRowid(var->handle, idx, rbdpi_to_rowid(val)->handle));
        break;
    case DPI_NATIVE_TYPE_STMT:
        CHK(dpiVar_setFromStmt(var->handle, idx, rbdpi_to_stmt(val)->handle));
        break;
    default:
        rbdpi_to_dpiData2(data + idx, val, var->native_type, &var->enc, var->oracle_type, var->objtype);
    }
    return self;
}

#copy_data(pos, src, srcpos) ⇒ Object


101
102
103
104
105
106
107
108
# File 'ext/odpi_ext/rbdpi-var.c', line 101

static VALUE cvar_copy_data(VALUE self, VALUE pos, VALUE src, VALUE srcpos)
{
    var_t *dvar = rbdpi_to_var(self);
    var_t *svar = rbdpi_to_var(self);

    CHK(dpiVar_copyData(dvar->handle, NUM2UINT(pos), svar->handle, NUM2UINT(srcpos)));
    return self;
}

#initialize_copy(other) ⇒ Object


91
92
93
94
95
96
97
98
99
# File 'ext/odpi_ext/rbdpi-var.c', line 91

static VALUE var_initialize_copy(VALUE self, VALUE other)
{
    var_t *var = rbdpi_to_var(self);
    *var = *rbdpi_to_var(other);
    if (var->handle != NULL) {
        CHK(dpiVar_addRef(var->handle));
    }
    return self;
}

#num_elements_in_arrayObject


110
111
112
113
114
115
116
117
# File 'ext/odpi_ext/rbdpi-var.c', line 110

static VALUE cvar_get_num_elements_in_array(VALUE self)
{
    var_t *var = rbdpi_to_var(self);
    uint32_t num;

    CHK(dpiVar_getNumElementsInArray(var->handle, &num));
    return UINT2NUM(num);
}

#num_elements_in_array=(num) ⇒ Object


119
120
121
122
123
124
125
# File 'ext/odpi_ext/rbdpi-var.c', line 119

static VALUE cvar_set_num_elements_in_array(VALUE self, VALUE num)
{
    var_t *var = rbdpi_to_var(self);

    CHK(dpiVar_setNumElementsInArray(var->handle, NUM2UINT(num)));
    return num;
}