Class: OracleDB::Conn

Inherits:
Object
  • Object
show all
Defined in:
lib/oracledb.rb,
ext/oracledb/rboradb_conn.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



58
59
60
61
62
63
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
# File 'ext/oracledb/rboradb_conn.c', line 58

static VALUE conn_initialize(int argc, VALUE *argv, VALUE self)
{
    Conn_t *conn = To_Conn(self);
    rbOraDBContext *ctxt;
    dpiCommonCreateParams common_params;
    dpiConnCreateParams conn_params;
    VALUE ctxt_obj, username, password, connstr, params;
    dpiConn *dpi_conn;
    VALUE gc_guard = Qnil;

    rb_scan_args(argc, argv, "41", &ctxt_obj, &username, &password, &connstr, &params);
    ctxt = rboradb_get_rbOraDBContext(ctxt_obj);
    OptExportString(username);
    OptExportString(password);
    OptExportString(connstr);
    dpiContext_initCommonCreateParams(ctxt->handle, &common_params);
    dpiContext_initConnCreateParams(ctxt->handle, &conn_params);
    if (!NIL_P(params)) {
        gc_guard = rboradb_set_common_and_dpiConnCreateParams(&common_params, &conn_params, params);
    }

    if (rbOraDBConn_create(ctxt->handle, OPT_RSTRING_PTR(username), OPT_RSTRING_LEN(username),
                         OPT_RSTRING_PTR(password), OPT_RSTRING_LEN(password),
                         OPT_RSTRING_PTR(connstr), OPT_RSTRING_LEN(connstr),
                         &common_params, &conn_params, &dpi_conn) != DPI_SUCCESS) {
        rboradb_raise_error(ctxt);
    }
    RB_GC_GUARD(gc_guard);
    init_conn(conn, ctxt, dpi_conn, &conn_params);
    return Qnil;
}

Instance Method Details

#action=(action) ⇒ Object



355
356
357
358
# File 'ext/oracledb/rboradb_conn.c', line 355

static VALUE conn_set_action(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setAction);
}

#begin_distrib_trans(format_id, transaction_id, branch_id) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'ext/oracledb/rboradb_conn.c', line 110

static VALUE conn_begin_distrib_trans(VALUE self, VALUE format_id, VALUE transaction_id, VALUE branch_id)
{
    Conn_t *conn = To_Conn(self);

    SafeStringValue(transaction_id);
    SafeStringValue(branch_id);
    if (rbOraDBConn_beginDistribTrans(conn->dconn->handle, NUM2LONG(format_id),
                                    RSTRING_PTR(transaction_id), RSTRING_LEN(transaction_id),
                                    RSTRING_PTR(branch_id), RSTRING_LEN(branch_id)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#break_executionObject



124
125
126
127
128
129
130
131
132
# File 'ext/oracledb/rboradb_conn.c', line 124

static VALUE conn_break_execution(VALUE self)
{
    Conn_t *conn = To_Conn(self);

    if (rbOraDBConn_breakExecution(conn->dconn->handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#call_timeoutObject



175
176
177
178
179
180
181
182
183
184
# File 'ext/oracledb/rboradb_conn.c', line 175

static VALUE conn_call_timeout(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    uint32_t msecs;

    if (dpiConn_getCallTimeout(conn->dconn->handle, &msecs) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return DBL2NUM((double)msecs / 1000.0);
}

#call_timeout=(secs) ⇒ Object



360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'ext/oracledb/rboradb_conn.c', line 360

static VALUE conn_set_call_timeout(VALUE self, VALUE secs)
{
    Conn_t *conn = To_Conn(self);
    double fsecs = NUM2DBL(secs);
    uint32_t msecs = 0;

    if (fsecs > 0) {
        msecs = fsecs * 1000;
        if (msecs == 0) {
            msecs = 1;
        }
    }
    if (dpiConn_setCallTimeout(conn->dconn->handle, msecs) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#change_password(username, old_password, new_password) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'ext/oracledb/rboradb_conn.c', line 134

static VALUE conn_change_password(VALUE self, VALUE username, VALUE old_password, VALUE new_password)
{
    Conn_t *conn = To_Conn(self);

    ExportString(username);
    ExportString(old_password);
    ExportString(new_password);
    if (rbOraDBConn_changePassword(conn->dconn->handle,
                                 RSTRING_PTR(username), RSTRING_LEN(username),
                                 RSTRING_PTR(old_password), RSTRING_LEN(old_password),
                                 RSTRING_PTR(new_password), RSTRING_LEN(new_password)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#client_identifier=(action) ⇒ Object



378
379
380
381
# File 'ext/oracledb/rboradb_conn.c', line 378

static VALUE conn_set_client_identifier(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setClientIdentifier);
}

#client_info=(action) ⇒ Object



383
384
385
386
# File 'ext/oracledb/rboradb_conn.c', line 383

static VALUE conn_set_client_info(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setClientInfo);
}

#close(*args) ⇒ Object



150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'ext/oracledb/rboradb_conn.c', line 150

static VALUE conn_close(int argc, VALUE *argv, VALUE self)
{
    Conn_t *conn = To_Conn(self);
    VALUE mode;
    VALUE tag;

    rb_scan_args(argc, argv, "02", &mode, &tag);
    OptExportString(tag);
    if (rbOraDBConn_close(conn->dconn->handle, rboradb_to_dpiConnCloseMode(mode),
                        OPT_RSTRING_PTR(tag), OPT_RSTRING_LEN(tag)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#commitObject



165
166
167
168
169
170
171
172
173
# File 'ext/oracledb/rboradb_conn.c', line 165

static VALUE conn_commit(VALUE self)
{
    Conn_t *conn = To_Conn(self);

    if (rbOraDBConn_commit(conn->dconn->handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#current_schemaObject



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

static VALUE conn_current_schema(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    const char *ptr;
    uint32_t len;

    if (dpiConn_getCurrentSchema(conn->dconn->handle, &ptr, &len) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return rb_external_str_new_with_enc(ptr, len, rb_utf8_encoding());
}

#current_schema=(action) ⇒ Object



388
389
390
391
# File 'ext/oracledb/rboradb_conn.c', line 388

static VALUE conn_set_current_schema(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setCurrentSchema);
}

#db_op=(action) ⇒ Object



393
394
395
396
# File 'ext/oracledb/rboradb_conn.c', line 393

static VALUE conn_set_db_op(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setDbOp);
}

#editionObject



198
199
200
201
202
203
204
205
206
207
208
# File 'ext/oracledb/rboradb_conn.c', line 198

static VALUE conn_edition(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    const char *ptr;
    uint32_t len;

    if (dpiConn_getEdition(conn->dconn->handle, &ptr, &len) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return rb_external_str_new_with_enc(ptr, len, rb_utf8_encoding());
}

#external_nameObject



210
211
212
213
214
215
216
217
218
219
220
# File 'ext/oracledb/rboradb_conn.c', line 210

static VALUE conn_external_name(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    const char *ptr;
    uint32_t len;

    if (dpiConn_getExternalName(conn->dconn->handle, &ptr, &len) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return rb_external_str_new_with_enc(ptr, len, rb_utf8_encoding());
}

#external_name=(action) ⇒ Object



398
399
400
401
# File 'ext/oracledb/rboradb_conn.c', line 398

static VALUE conn_set_external_name(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setExternalName);
}

#internal_nameObject



222
223
224
225
226
227
228
229
230
231
232
# File 'ext/oracledb/rboradb_conn.c', line 222

static VALUE conn_internal_name(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    const char *ptr;
    uint32_t len;

    if (dpiConn_getInternalName(conn->dconn->handle, &ptr, &len) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return rb_external_str_new_with_enc(ptr, len, rb_utf8_encoding());
}

#internal_name=(action) ⇒ Object



403
404
405
406
# File 'ext/oracledb/rboradb_conn.c', line 403

static VALUE conn_set_internal_name(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setInternalName);
}

#ltxidObject



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

static VALUE conn_ltxid(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    const char *ptr;
    uint32_t len;

    if (dpiConn_getLTXID(conn->dconn->handle, &ptr, &len) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return rb_external_str_new(ptr, len);
}

#module=(action) ⇒ Object



408
409
410
411
# File 'ext/oracledb/rboradb_conn.c', line 408

static VALUE conn_set_module(VALUE self, VALUE action)
{
    return set_char(self, action, dpiConn_setModule);
}

#new_deq_optionsObject



16
17
18
# File 'lib/oracledb.rb', line 16

def new_deq_options
  DeqOptions.new(self)
end

#new_enq_optionsObject



20
21
22
# File 'lib/oracledb.rb', line 20

def new_enq_options
  EnqOptions.new(self)
end

#new_msg_propsObject



24
25
26
# File 'lib/oracledb.rb', line 24

def new_msg_props
  MsgProps.new(self)
end

#new_queue(name, payload = nil) ⇒ Object



28
29
30
# File 'lib/oracledb.rb', line 28

def new_queue(name, payload=nil)
  Queue.new(self, name, payload)
end

#new_tmp_lob(type) ⇒ Object



32
33
34
# File 'lib/oracledb.rb', line 32

def new_tmp_lob(type)
  Lob.new(self, type)
end

#object_type(name) ⇒ Object



12
13
14
# File 'lib/oracledb.rb', line 12

def object_type(name)
  ObjectType.new(self, name)
end

#oci_attr(handle_type, attr, attr_data_type) ⇒ Object



246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# File 'ext/oracledb/rboradb_conn.c', line 246

static VALUE conn_oci_attr(VALUE self, VALUE handle_type, VALUE attr, VALUE attr_data_type)
{
    Conn_t *conn = To_Conn(self);
    uint32_t htype = rboradb_to_OciHandleType(handle_type);
    OciAttrDataType type = rboradb_to_OciAttrDataType(attr_data_type);
    dpiDataBuffer val;
    uint32_t len;

    if (dpiConn_getOciAttr(conn->dconn->handle, htype, NUM2UINT(attr), &val, &len) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    switch (type) {
    case RBORADB_OCI_ATTR_DATA_TYPE_BOOLEAN:
        return val.asBoolean ? Qtrue : Qfalse;
    case RBORADB_OCI_ATTR_DATA_TYPE_TEXT:
        return rb_enc_str_new(val.asString, len, rb_utf8_encoding());
    case RBORADB_OCI_ATTR_DATA_TYPE_UB1:
        return INT2FIX(val.asUint8);
    case RBORADB_OCI_ATTR_DATA_TYPE_UB2:
        return INT2FIX(val.asUint16);
    case RBORADB_OCI_ATTR_DATA_TYPE_UB4:
        return UINT2NUM(val.asUint32);
    case RBORADB_OCI_ATTR_DATA_TYPE_UB8:
        return ULL2NUM(val.asUint64);
    }
    return Qnil;
}

#pingObject



296
297
298
299
300
301
302
303
304
# File 'ext/oracledb/rboradb_conn.c', line 296

static VALUE conn_ping(VALUE self)
{
    Conn_t *conn = To_Conn(self);

    if (rbOraDBConn_ping(conn->dconn->handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#prepare_distrib_transObject



306
307
308
309
310
311
312
313
314
315
# File 'ext/oracledb/rboradb_conn.c', line 306

static VALUE conn_prepare_distrib_trans(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    int commit_needed;

    if (rbOraDBConn_prepareDistribTrans(conn->dconn->handle, &commit_needed) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return commit_needed ? Qtrue : Qfalse;
}

#prepare_stmt(sql, fetch_array_size: 100, scrollable: false, tag: nil) ⇒ Object



8
9
10
# File 'lib/oracledb.rb', line 8

def prepare_stmt(sql, fetch_array_size: 100, scrollable: false, tag: nil)
  __prepare_stmt(sql, fetch_array_size, scrollable, tag)
end

#rollbackObject



334
335
336
337
338
339
340
341
342
# File 'ext/oracledb/rboradb_conn.c', line 334

static VALUE conn_rollback(VALUE self)
{
    Conn_t *conn = To_Conn(self);

    if (rbOraDBConn_rollback(conn->dconn->handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#server_versionObject



274
275
276
277
278
279
280
281
282
283
# File 'ext/oracledb/rboradb_conn.c', line 274

static VALUE conn_server_version(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    dpiVersionInfo ver;

    if (dpiConn_getServerVersion(conn->dconn->handle, NULL, NULL, &ver) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return rboradb_from_dpiVersionInfo(&ver);
}

#set_oci_attr(handle_type, attr, attr_data_type, value) ⇒ Object



424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
# File 'ext/oracledb/rboradb_conn.c', line 424

static VALUE conn_set_oci_attr(VALUE self, VALUE handle_type, VALUE attr, VALUE attr_data_type, VALUE value)
{
    Conn_t *conn = To_Conn(self);
    uint32_t htype = rboradb_to_OciHandleType(handle_type);
    OciAttrDataType type = rboradb_to_OciAttrDataType(attr_data_type);
    union {
        int boolval;
        char *textval;
        uint8_t ub1val;
        uint16_t ub2val;
        uint32_t ub4val;
        uint64_t ub8val;
    } val;
    uint32_t len = 0;

    switch (type) {
    case RBORADB_OCI_ATTR_DATA_TYPE_BOOLEAN:
        val.boolval = RTEST(value) ? 1 : 0;
        break;
    case RBORADB_OCI_ATTR_DATA_TYPE_TEXT:
        ExportString(value);
        val.textval = RSTRING_PTR(value);
        len = RSTRING_LEN(value);
        break;
    case RBORADB_OCI_ATTR_DATA_TYPE_UB1:
        val.ub1val = NUM2UINT(value);
        break;
    case RBORADB_OCI_ATTR_DATA_TYPE_UB2:
        val.ub2val = NUM2UINT(value);
        break;
    case RBORADB_OCI_ATTR_DATA_TYPE_UB4:
        val.ub4val = NUM2UINT(value);
        break;
    case RBORADB_OCI_ATTR_DATA_TYPE_UB8:
        val.ub8val = NUM2ULL(value);
        break;
    }
    if (dpiConn_setOciAttr(conn->dconn->handle, htype, NUM2UINT(attr), &val, len) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#shutdown_database(mode) ⇒ Object



477
478
479
480
481
482
483
484
485
# File 'ext/oracledb/rboradb_conn.c', line 477

static VALUE conn_shutdown_database(VALUE self, VALUE mode)
{
    Conn_t *conn = To_Conn(self);

    if (rbOraDBConn_shutdownDatabase(conn->dconn->handle, rboradb_to_dpiShutdownMode(mode)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#soda_dbObject



413
414
415
416
417
418
419
420
421
422
# File 'ext/oracledb/rboradb_conn.c', line 413

static VALUE conn_soda_db(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    dpiSodaDb *db;

    if (dpiConn_getSodaDb(conn->dconn->handle, &db) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return rboradb_soda_db_new(db, conn->dconn);
}

#startup_database(*args) ⇒ Object



487
488
489
490
491
492
493
494
495
496
497
498
499
# File 'ext/oracledb/rboradb_conn.c', line 487

static VALUE conn_startup_database(int argc, VALUE *argv, VALUE self)
{
    Conn_t *conn = To_Conn(self);
    VALUE mode, pfile;

    rb_scan_args(argc, argv, "11", &mode, &pfile);
    OptExportString(pfile);
    if (rbOraDBConn_startupDatabaseWithPfile(conn->dconn->handle, OPT_RSTRING_PTR(pfile), OPT_RSTRING_LEN(pfile), rboradb_to_dpiShutdownMode(mode)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    RB_GC_GUARD(pfile);
    return Qnil;
}

#stmt_cache_sizeObject



285
286
287
288
289
290
291
292
293
294
# File 'ext/oracledb/rboradb_conn.c', line 285

static VALUE conn_stmt_cache_size(VALUE self)
{
    Conn_t *conn = To_Conn(self);
    uint32_t size;

    if (dpiConn_getStmtCacheSize(conn->dconn->handle, &size) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return UINT2NUM(size);
}

#stmt_cache_size=(size) ⇒ Object



467
468
469
470
471
472
473
474
475
# File 'ext/oracledb/rboradb_conn.c', line 467

static VALUE conn_set_stmt_cache_size(VALUE self, VALUE size)
{
    Conn_t *conn = To_Conn(self);

    if (dpiConn_setStmtCacheSize(conn->dconn->handle, NUM2UINT(size)) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(conn);
    }
    return Qnil;
}

#subscribe(params) ⇒ Object



36
37
38
# File 'lib/oracledb.rb', line 36

def subscribe(params)
  Subscr.new(self, params)
end