Class: ODPI::Dpi::DataType

Inherits:
Object
  • Object
show all
Defined in:
ext/odpi_ext/rbdpi-data-type.c,
ext/odpi_ext/rbdpi-data-type.c

Overview

This class represents Oracle data type information.

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

#client_size_in_bytesInteger

Gets the size in bytes (from the client's perspective) of the data. This value is only for strings and binary data. For all other data the value is zero.


329
330
331
332
333
334
# File 'ext/odpi_ext/rbdpi-data-type.c', line 329

static VALUE data_type_get_client_size_in_bytes(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return UINT2NUM(dt->info->clientSizeInBytes);
}

#db_size_in_bytesInteger

Get the size in bytes (from the database's perspective) of the data. This value is only for strings and binary data. For all other data the value is zero.


315
316
317
318
319
320
# File 'ext/odpi_ext/rbdpi-data-type.c', line 315

static VALUE data_type_get_db_size_in_bytes(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return UINT2NUM(dt->info->dbSizeInBytes);
}

#default_native_typeSymbol

Gets the default native type for the data. +nil+ if the type is not supported by ODPI-C.


287
288
289
290
291
292
# File 'ext/odpi_ext/rbdpi-data-type.c', line 287

static VALUE data_type_get_default_native_type(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return rbdpi_from_dpiNativeTypeNum(dt->info->defaultNativeTypeNum);
}

#fs_precisionInteger

Gets the fractional seconds precision of the data. This value is only for timestamp and interval day to second data. For all other data the value is zero.


382
383
384
385
386
387
# File 'ext/odpi_ext/rbdpi-data-type.c', line 382

static VALUE data_type_get_fs_precision(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return INT2FIX(dt->info->fsPrecision);
}

#object_typeObjectType

Gets the type of the object. This value is only for named type data. For all other data the value is +nil+. This


395
396
397
398
399
400
# File 'ext/odpi_ext/rbdpi-data-type.c', line 395

static VALUE data_type_get_object_type(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return dt->objtype;
}

#oci_type_codeInteger

Get the OCI type code for the data, which can be useful if the type is not supported by ODPI-C.


300
301
302
303
304
305
306
# File 'ext/odpi_ext/rbdpi-data-type.c', line 300

static VALUE data_type_get_oci_type_code(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return INT2FIX(dt->info->ociTypeCode);

}

#oracle_typeSymbol

Gets the type of the data. +nil+ if the type is not supported by ODPI-C.


274
275
276
277
278
279
# File 'ext/odpi_ext/rbdpi-data-type.c', line 274

static VALUE data_type_get_oracle_type(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return rbdpi_from_dpiOracleTypeNum(dt->info->oracleTypeNum);
}

#precisionInteger

Gets the precision of the data. This value is only for numeric and interval data. For all other data the value is zero.


355
356
357
358
359
360
# File 'ext/odpi_ext/rbdpi-data-type.c', line 355

static VALUE data_type_get_precision(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return INT2FIX(dt->info->precision);
}

#scaleInteger

Gets the scale of the data. This value is only for numeric data. For all other data the value is zero.


368
369
370
371
372
373
# File 'ext/odpi_ext/rbdpi-data-type.c', line 368

static VALUE data_type_get_scale(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return INT2FIX(dt->info->scale);
}

#size_in_charsInteger

Gets the size in characters of the data. This value is only for string data. For all other data the value is zero.


342
343
344
345
346
347
# File 'ext/odpi_ext/rbdpi-data-type.c', line 342

static VALUE data_type_get_size_in_chars(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);

    return UINT2NUM(dt->info->sizeInChars);
}

#to_sString

Gets the string representation of the Oracle data type, which could be put in DDL statements.


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
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
194
195
196
197
198
199
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
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'ext/odpi_ext/rbdpi-data-type.c', line 123

static VALUE data_type_to_s(VALUE self)
{
    data_type_t *dt = TO_DATA_TYPE(self);
    const dpiDataTypeInfo *info = dt->info;
    VALUE str;

    switch (info->oracleTypeNum) {
    case DPI_ORACLE_TYPE_VARCHAR:
        str = rb_sprintf("VARCHAR2(%d)", info->dbSizeInBytes);
        break;
    case DPI_ORACLE_TYPE_NVARCHAR:
        str = rb_sprintf("NVARCHAR(%d)", info->sizeInChars);
        break;
    case DPI_ORACLE_TYPE_CHAR:
        str = rb_sprintf("CHAR(%d)", info->dbSizeInBytes);
        break;
    case DPI_ORACLE_TYPE_NCHAR:
        str = rb_sprintf("NCHAR(%d)", info->sizeInChars);
        break;
    case DPI_ORACLE_TYPE_ROWID:
        str = rb_usascii_str_new_cstr("ROWID");
        break;
    case DPI_ORACLE_TYPE_RAW:
        str = rb_usascii_str_new_cstr("RAW");
        break;
    case DPI_ORACLE_TYPE_NATIVE_FLOAT:
        str = rb_usascii_str_new_cstr("BINARY_FLOAT");
        break;
    case DPI_ORACLE_TYPE_NATIVE_DOUBLE:
        str = rb_usascii_str_new_cstr("BINARY_DOUBLE");
        break;
    case DPI_ORACLE_TYPE_NATIVE_INT:
        str = rb_usascii_str_new_cstr("native int?");
        break;
    case DPI_ORACLE_TYPE_NUMBER:
        switch (info->scale) {
        case -127:
            switch (info->precision) {
            case 0:
                str = rb_usascii_str_new_cstr("NUMBER");
                break;
            case 126:
                str = rb_usascii_str_new_cstr("FLOAT");
                break;
            default:
                str = rb_sprintf("FLOAT(%d)", info->precision);
            }
            break;
        case 0:
            if (info->precision == 0) {
                str = rb_usascii_str_new_cstr("NUMBER");
            } else {
                str = rb_sprintf("NUMBER(%d)", info->precision);
            }
            break;
        default:
            str = rb_sprintf("NUMBER(%d,%d)", info->precision, info->scale);
        }
        break;
    case DPI_ORACLE_TYPE_DATE:
        str = rb_usascii_str_new_cstr("DATE");
        break;
    case DPI_ORACLE_TYPE_TIMESTAMP:
        if (info->fsPrecision == 6) {
            str = rb_usascii_str_new_cstr("TIMESTAMP");
        } else {
            str = rb_sprintf("TIMESTAMP(%d)", info->fsPrecision);
        }
        break;
    case DPI_ORACLE_TYPE_TIMESTAMP_TZ:
        if (info->fsPrecision == 6) {
            str = rb_usascii_str_new_cstr("TIMESTAMP WITH TIME ZONE");
        } else {
            str = rb_sprintf("TIMESTAMP(%d) WITH TIME ZONE", info->fsPrecision);
        }
        break;
    case DPI_ORACLE_TYPE_TIMESTAMP_LTZ:
        if (info->fsPrecision == 6) {
            str = rb_usascii_str_new_cstr("TIMESTAMP WITH LOCAL TIME ZONE");
        } else {
            str = rb_sprintf("TIMESTAMP(%d) WITH LOCAL TIME ZONE", info->fsPrecision);
        }
        break;
    case DPI_ORACLE_TYPE_INTERVAL_DS:
        if (info->precision == 2) {
            str = rb_usascii_str_new_cstr("INTERVAL YEAR TO MONTH");
        } else {
            str = rb_sprintf("INTERVAL YEAR(%d) TO MONTH", info->precision);
        }
        break;
    case DPI_ORACLE_TYPE_INTERVAL_YM:
        if (info->precision == 2 && info->fsPrecision == 6) {
            str = rb_usascii_str_new_cstr("INTERVAL DAY TO SECOND");
        } else {
            str = rb_sprintf("INTERVAL DAY(%d) TO SECOND(%d)",
                              info->precision, info->fsPrecision);
        }
        break;
    case DPI_ORACLE_TYPE_CLOB:
        str = rb_usascii_str_new_cstr("CLOB");
        break;
    case DPI_ORACLE_TYPE_NCLOB:
        str = rb_usascii_str_new_cstr("NCLOB");
        break;
    case DPI_ORACLE_TYPE_BLOB:
        str = rb_usascii_str_new_cstr("BLOB");
        break;
    case DPI_ORACLE_TYPE_BFILE:
        str = rb_usascii_str_new_cstr("BFILE");
        break;
    case DPI_ORACLE_TYPE_STMT:
        str = rb_usascii_str_new_cstr("CURSOR");
        break;
    case DPI_ORACLE_TYPE_BOOLEAN:
        str = rb_usascii_str_new_cstr("BOOLEAN");
        break;
    case DPI_ORACLE_TYPE_OBJECT:
        if (!NIL_P(dt->objtype) && dt->enc.enc != NULL) {
            object_type_t *objtype = rbdpi_to_object_type(dt->objtype);
            str = rb_enc_sprintf(dt->enc.enc, "%.*s.%.*s",
                                 objtype->info.schemaLength, objtype->info.schema,
                                 objtype->info.nameLength, objtype->info.name);
        } else {
            str = rb_usascii_str_new_cstr("OBJECT");
        }
        break;
    case DPI_ORACLE_TYPE_LONG_VARCHAR:
        str = rb_usascii_str_new_cstr("LONG");
        break;
    case DPI_ORACLE_TYPE_LONG_RAW:
        str = rb_usascii_str_new_cstr("LONG RAW");
        break;
    case DPI_ORACLE_TYPE_NATIVE_UINT:
        str = rb_usascii_str_new_cstr("native uint?");
        break;
    default:
        str = rb_sprintf("Unknown oracle type number %d",
                         info->oracleTypeNum);
    }
    if (RB_OBJ_TAINTED(self)) {
        RB_OBJ_TAINT(str);
    }
    return str;
}