Class: ODPI::Dpi::Conn

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

Instance Method Summary collapse

Constructor Details

#initialize(username, password, database, auth_mode, params) ⇒ Object


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/odpi_ext/rbdpi-conn.c', line 72

static VALUE conn_initialize(VALUE self, VALUE username, VALUE password, VALUE database, VALUE auth_mode, VALUE params)
{
    conn_t *conn = (conn_t *)rb_check_typeddata(self, &conn_data_type);
    dpiCommonCreateParams common_params;
    dpiConnCreateParams create_params;
    VALUE gc_guard1;
    VALUE gc_guard2;

    if (conn->handle != NULL) {
        rb_raise(rb_eRuntimeError, "Try to initialize an initialized connection");
    }
    conn->enc = rbdpi_get_encodings(params);
    CHK_NSTR_ENC(username, conn->enc.enc);
    CHK_NSTR_ENC(password, conn->enc.enc);
    CHK_NSTR_ENC(database, conn->enc.enc);
    gc_guard1 = rbdpi_fill_dpiCommonCreateParams(&common_params, params, conn->enc.enc);
    gc_guard2 = rbdpi_fill_dpiConnCreateParams(&create_params, params, auth_mode, conn->enc.enc);
    if (NIL_P(username) && NIL_P(password)) {
        create_params.externalAuth = 1;
    }
    CHK(dpiConn_create_without_gvl(rbdpi_g_context,
                                   NSTR_PTR(username), NSTR_LEN(username),
                                   NSTR_PTR(password), NSTR_LEN(password),
                                   NSTR_PTR(database), NSTR_LEN(database),
                                   &common_params, &create_params, &conn->handle));
    RB_GC_GUARD(username);
    RB_GC_GUARD(password);
    RB_GC_GUARD(database);
    RB_GC_GUARD(gc_guard1);
    RB_GC_GUARD(gc_guard2);
    return self;
}

Instance Method Details

#action=(val) ⇒ Object


410
411
412
413
414
415
416
417
# File 'ext/odpi_ext/rbdpi-conn.c', line 410

static VALUE conn_set_action(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setAction(conn->handle, NSTR_PTR(val), NSTR_LEN(val)));
    return val;
}

#begin_distrib_trans(format_id, transaction_id, branch_id) ⇒ Object


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'ext/odpi_ext/rbdpi-conn.c', line 116

static VALUE conn_begin_distrib_trans(VALUE self, VALUE format_id, VALUE transaction_id, VALUE branch_id)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_STR_ENC(transaction_id, conn->enc.enc);
    CHK_STR_ENC(branch_id, conn->enc.enc);
    CHK(dpiConn_beginDistribTrans_without_gvl(conn->handle, NUM2LONG(format_id),
                                              RSTRING_PTR(transaction_id),
                                              RSTRING_LEN(transaction_id),
                                              RSTRING_PTR(branch_id),
                                              RSTRING_LEN(branch_id)));
    RB_GC_GUARD(transaction_id);
    RB_GC_GUARD(branch_id);
    return self;
}

#breakObject


132
133
134
135
136
137
138
# File 'ext/odpi_ext/rbdpi-conn.c', line 132

static VALUE conn_break(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK(dpiConn_breakExecution_without_gvl(conn->handle));
    return self;
}

#change_password(user_name, old_password, new_password) ⇒ Object


140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'ext/odpi_ext/rbdpi-conn.c', line 140

static VALUE conn_change_password(VALUE self, VALUE user_name, VALUE old_password, VALUE new_password)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_STR_ENC(user_name, conn->enc.enc);
    CHK_STR_ENC(old_password, conn->enc.enc);
    CHK_STR_ENC(new_password, conn->enc.enc);

    CHK(dpiConn_changePassword_without_gvl(conn->handle,
                                           RSTRING_PTR(user_name),
                                           RSTRING_LEN(user_name),
                                           RSTRING_PTR(old_password),
                                           RSTRING_LEN(old_password),
                                           RSTRING_PTR(new_password),
                                           RSTRING_LEN(new_password)));
    RB_GC_GUARD(user_name);
    RB_GC_GUARD(old_password);
    RB_GC_GUARD(new_password);
    return self;
}

#client_identifier=(val) ⇒ Object


419
420
421
422
423
424
425
426
# File 'ext/odpi_ext/rbdpi-conn.c', line 419

static VALUE conn_set_client_identifier(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setClientIdentifier(conn->handle, NSTR_PTR(val), NSTR_LEN(val)));
    return val;
}

#client_info=(val) ⇒ Object


428
429
430
431
432
433
434
435
# File 'ext/odpi_ext/rbdpi-conn.c', line 428

static VALUE conn_set_client_info(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setClientInfo(conn->handle, NSTR_PTR(val), NSTR_LEN(val)));
    return val;
}

#close(mode, tag) ⇒ Object


161
162
163
164
165
166
167
168
169
170
171
# File 'ext/odpi_ext/rbdpi-conn.c', line 161

static VALUE conn_close(VALUE self, VALUE mode, VALUE tag)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR(tag);
    CHK(dpiConn_close_without_gvl(conn->handle,
                                  rbdpi_to_dpiConnCloseMode(mode),
                                  NSTR_PTR(tag), NSTR_LEN(tag)));
    RB_GC_GUARD(tag);
    return self;
}

#commitObject


173
174
175
176
177
# File 'ext/odpi_ext/rbdpi-conn.c', line 173

static VALUE conn_commit(VALUE self)
{
    CHK(dpiConn_commit_without_gvl(rbdpi_to_conn(self)->handle));
    return self;
}

#current_schemaObject


213
214
215
216
217
218
219
220
221
# File 'ext/odpi_ext/rbdpi-conn.c', line 213

static VALUE conn_get_current_schema(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *val;
    uint32_t len;

    CHK(dpiConn_getCurrentSchema(conn->handle, &val, &len));
    return NSTR_NEW_ENC(val, len, conn->enc.enc);
}

#current_schema=(val) ⇒ Object


437
438
439
440
441
442
443
444
# File 'ext/odpi_ext/rbdpi-conn.c', line 437

static VALUE conn_set_current_schema(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_STR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setCurrentSchema(conn->handle, RSTRING_PTR(val), RSTRING_LEN(val)));
    return val;
}

#dbop=(val) ⇒ Object


446
447
448
449
450
451
452
453
# File 'ext/odpi_ext/rbdpi-conn.c', line 446

static VALUE conn_set_dbop(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setDbOp(conn->handle, NSTR_PTR(val), NSTR_LEN(val)));
    return val;
}

#deq_object(queue_name, options, props, payload) ⇒ Object


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

static VALUE conn_deq_object(VALUE self, VALUE queue_name, VALUE options, VALUE props, VALUE payload)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *msgId;
    uint32_t msgIdLength;

    CHK_STR_ENC(queue_name, conn->enc.enc);
    CHK(dpiConn_deqObject_without_gvl(conn->handle, RSTRING_PTR(queue_name),
                                      RSTRING_LEN(queue_name),
                                      rbdpi_to_deq_options(options)->handle,
                                      rbdpi_to_msg_props(props)->handle,
                                      rbdpi_to_object(payload)->handle,
                                      &msgId, &msgIdLength));
    RB_GC_GUARD(queue_name);
    return STR_NEW_ENC(msgId, msgIdLength, conn->enc.enc);
}

#editionObject


223
224
225
226
227
228
229
230
231
# File 'ext/odpi_ext/rbdpi-conn.c', line 223

static VALUE conn_get_edition(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *val;
    uint32_t len;

    CHK(dpiConn_getEdition(conn->handle, &val, &len));
    return NSTR_NEW_ENC(val, len, conn->enc.enc);
}

#encoding_infoObject


233
234
235
236
237
238
239
240
# File 'ext/odpi_ext/rbdpi-conn.c', line 233

static VALUE conn_get_encoding_info(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiEncodingInfo info;

    CHK(dpiConn_getEncodingInfo(conn->handle, &info));
    return rbdpi_from_dpiEncodingInfo(&info);
}

#enq_object(queue_name, options, props, payload) ⇒ Object


196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'ext/odpi_ext/rbdpi-conn.c', line 196

static VALUE conn_enq_object(VALUE self, VALUE queue_name, VALUE options, VALUE props, VALUE payload)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *msgId;
    uint32_t msgIdLength;

    CHK_STR_ENC(queue_name, conn->enc.enc);
    CHK(dpiConn_enqObject_without_gvl(conn->handle, RSTRING_PTR(queue_name),
                                      RSTRING_LEN(queue_name),
                                      rbdpi_to_enq_options(options)->handle,
                                      rbdpi_to_msg_props(props)->handle,
                                      rbdpi_to_object(payload)->handle,
                                      &msgId, &msgIdLength));
    RB_GC_GUARD(queue_name);
    return STR_NEW_ENC(msgId, msgIdLength, conn->enc.enc);
}

#external_nameObject


242
243
244
245
246
247
248
249
250
# File 'ext/odpi_ext/rbdpi-conn.c', line 242

static VALUE conn_get_external_name(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *val;
    uint32_t len;

    CHK(dpiConn_getExternalName(conn->handle, &val, &len));
    return NSTR_NEW_ENC(val, len, conn->enc.enc);
}

#external_name=(val) ⇒ Object


455
456
457
458
459
460
461
462
# File 'ext/odpi_ext/rbdpi-conn.c', line 455

static VALUE conn_set_external_name(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setExternalName(conn->handle, NSTR_PTR(val), NSTR_LEN(val)));
    return val;
}

#initialize_copy(other) ⇒ Object


105
106
107
108
109
110
111
112
113
114
# File 'ext/odpi_ext/rbdpi-conn.c', line 105

static VALUE conn_initialize_copy(VALUE self, VALUE other)
{
    conn_t *conn = rbdpi_to_conn(self);

    *conn = *rbdpi_to_conn(other);
    if (conn->handle != NULL) {
        CHK(dpiConn_addRef(conn->handle));
    }
    return self;
}

#internal_nameObject


252
253
254
255
256
257
258
259
260
# File 'ext/odpi_ext/rbdpi-conn.c', line 252

static VALUE conn_get_internal_name(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *val;
    uint32_t len;

    CHK(dpiConn_getInternalName(conn->handle, &val, &len));
    return NSTR_NEW_ENC(val, len, conn->enc.enc);
}

#internal_name=(val) ⇒ Object


464
465
466
467
468
469
470
471
# File 'ext/odpi_ext/rbdpi-conn.c', line 464

static VALUE conn_set_internal_name(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setInternalName(conn->handle, NSTR_PTR(val), NSTR_LEN(val)));
    return val;
}

#ltxidObject


262
263
264
265
266
267
268
269
270
# File 'ext/odpi_ext/rbdpi-conn.c', line 262

static VALUE conn_get_ltxid(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *val;
    uint32_t len;

    CHK(dpiConn_getLTXID(conn->handle, &val, &len));
    return NSTR_NEW_ENC(val, len, conn->enc.enc);
}

#module=(val) ⇒ Object


473
474
475
476
477
478
479
480
# File 'ext/odpi_ext/rbdpi-conn.c', line 473

static VALUE conn_set_module(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK_NSTR_ENC(val, conn->enc.enc);
    CHK(dpiConn_setModule(conn->handle, NSTR_PTR(val), NSTR_LEN(val)));
    return val;
}

#new_deq_optionsObject


314
315
316
317
318
319
320
321
# File 'ext/odpi_ext/rbdpi-conn.c', line 314

static VALUE conn_new_deq_options(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiDeqOptions *options;

    CHK(dpiConn_newDeqOptions(conn->handle, &options));
    return rbdpi_from_deq_options(options, conn->enc.enc);
}

#new_enq_optionsObject


323
324
325
326
327
328
329
330
# File 'ext/odpi_ext/rbdpi-conn.c', line 323

static VALUE conn_new_enq_options(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiEnqOptions *options;

    CHK(dpiConn_newEnqOptions(conn->handle, &options));
    return rbdpi_from_enq_options(options, conn->enc.enc);
}

#new_msg_propsObject


332
333
334
335
336
337
338
339
# File 'ext/odpi_ext/rbdpi-conn.c', line 332

static VALUE conn_new_msg_props(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiMsgProps *props;

    CHK(dpiConn_newMsgProps(conn->handle, &props));
    return rbdpi_from_msg_props(props, conn->enc.enc);
}

#new_subscription(params) ⇒ Object


341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'ext/odpi_ext/rbdpi-conn.c', line 341

static VALUE conn_new_subscription(VALUE self, VALUE params)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiSubscrCreateParams create_params;
    dpiSubscr *handle;
    subscr_t *subscr;
    VALUE obj;
    VALUE gc_guard;

    gc_guard = rbdpi_fill_dpiSubscrCreateParams(&create_params, params, conn->enc.enc);
    obj = rbdpi_subscr_prepare(&subscr, &create_params, &conn->enc);
    CHK(dpiConn_newSubscription(conn->handle, &create_params, &handle, NULL));
    RB_GC_GUARD(gc_guard);
    subscr->handle = handle;
    rbdpi_subscr_start(subscr);
    return obj;
}

#new_temp_lob(lobtype) ⇒ Object


359
360
361
362
363
364
365
366
367
# File 'ext/odpi_ext/rbdpi-conn.c', line 359

static VALUE conn_new_temp_lob(VALUE self, VALUE lobtype)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiOracleTypeNum lobtype_num = rbdpi_to_dpiOracleTypeNum(lobtype);
    dpiLob *lob;

    CHK(dpiConn_newTempLob(conn->handle, lobtype_num, &lob));
    return rbdpi_from_lob(lob, &conn->enc, lobtype_num);
}

#object_type(name) ⇒ Object


272
273
274
275
276
277
278
279
280
281
# File 'ext/odpi_ext/rbdpi-conn.c', line 272

static VALUE conn_get_object_type(VALUE self, VALUE name)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiObjectType *handle;

    CHK_STR_ENC(name, conn->enc.enc);
    CHK(dpiConn_getObjectType_without_gvl(conn->handle, RSTRING_PTR(name), RSTRING_LEN(name), &handle));
    RB_GC_GUARD(name);
    return rbdpi_from_object_type(handle, &conn->enc);
}

#pingObject


369
370
371
372
373
374
375
# File 'ext/odpi_ext/rbdpi-conn.c', line 369

static VALUE conn_ping(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK(dpiConn_ping(conn->handle));
    return self;
}

#prepare_distrib_transObject


377
378
379
380
381
382
383
384
# File 'ext/odpi_ext/rbdpi-conn.c', line 377

static VALUE conn_prepare_distrib_trans(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    int commit_needed;

    CHK(dpiConn_prepareDistribTrans(conn->handle, &commit_needed));
    return commit_needed ? Qtrue : Qfalse;
}

#prepare_stmt(scrollable, sql, tag) ⇒ Object


386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
# File 'ext/odpi_ext/rbdpi-conn.c', line 386

static VALUE conn_prepare_stmt(VALUE self, VALUE scrollable, VALUE sql, VALUE tag)
{
    conn_t *conn = rbdpi_to_conn(self);
    dpiStmt *stmt;

    CHK_STR_ENC(sql, conn->enc.enc);
    CHK_NSTR_ENC(tag, conn->enc.enc);
    CHK(dpiConn_prepareStmt(conn->handle, RTEST(scrollable),
                            RSTRING_PTR(sql), RSTRING_LEN(sql),
                            NSTR_PTR(tag), NSTR_LEN(tag),
                            &stmt));
    RB_GC_GUARD(sql);
    RB_GC_GUARD(tag);
    return rbdpi_from_stmt(stmt, &conn->enc);
}

#rollbackObject


402
403
404
405
406
407
408
# File 'ext/odpi_ext/rbdpi-conn.c', line 402

static VALUE conn_rollback(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK(dpiConn_rollback(conn->handle));
    return self;
}

#server_releaseObject


283
284
285
286
287
288
289
290
291
292
# File 'ext/odpi_ext/rbdpi-conn.c', line 283

static VALUE conn_get_server_release(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *str;
    uint32_t len;
    dpiVersionInfo ver;

    CHK(dpiConn_getServerVersion(conn->handle, &str, &len, &ver));
    return rb_usascii_str_new(str, len);
}

#server_versionObject


294
295
296
297
298
299
300
301
302
303
# File 'ext/odpi_ext/rbdpi-conn.c', line 294

static VALUE conn_get_server_version(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    const char *str;
    uint32_t len;
    dpiVersionInfo ver;

    CHK(dpiConn_getServerVersion(conn->handle, &str, &len, &ver));
    return rbdpi_from_dpiVersionInfo(&ver);
}

#shutdown_database(mode) ⇒ Object


490
491
492
493
494
495
496
# File 'ext/odpi_ext/rbdpi-conn.c', line 490

static VALUE conn_shutdown_database(VALUE self, VALUE mode)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK(dpiConn_shutdownDatabase(conn->handle, rbdpi_to_dpiShutdownMode(mode)));
    return self;
}

#startup_database(mode) ⇒ Object


498
499
500
501
502
503
504
# File 'ext/odpi_ext/rbdpi-conn.c', line 498

static VALUE conn_startup_database(VALUE self, VALUE mode)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK(dpiConn_startupDatabase(conn->handle, rbdpi_to_dpiStartupMode(mode)));
    return self;
}

#stmt_cache_sizeObject


305
306
307
308
309
310
311
312
# File 'ext/odpi_ext/rbdpi-conn.c', line 305

static VALUE conn_get_stmt_cache_size(VALUE self)
{
    conn_t *conn = rbdpi_to_conn(self);
    uint32_t size;

    CHK(dpiConn_getStmtCacheSize(conn->handle, &size));
    return ULONG2NUM(size);
}

#stmt_cache_size=(val) ⇒ Object


482
483
484
485
486
487
488
# File 'ext/odpi_ext/rbdpi-conn.c', line 482

static VALUE conn_set_stmt_cache_size(VALUE self, VALUE val)
{
    conn_t *conn = rbdpi_to_conn(self);

    CHK(dpiConn_setStmtCacheSize(conn->handle, NUM2UINT(val)));
    return val;
}