/* * call-seq: * oracle_server_vernum -> an integer * * <b>(new in 2.0.1)</b> * * Returns a numerical format of the Oracle server version. * * See also: #oracle_server_version */ static VALUE oci8_oracle_server_vernum(VALUE self) { oci8_svcctx_t *svcctx = DATA_PTR(self); char buf[100]; ub4 version; char *p; if (have_OCIServerRelease) { /* Oracle 9i or later */ oci_lc(OCIServerRelease(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type, &version)); return UINT2NUM(version); } else { /* Oracle 8.x */ oci_lc(OCIServerVersion(svcctx->base.hp.ptr, oci8_errhp, (text*)buf, sizeof(buf), (ub1)svcctx->base.type)); if ((p = strchr(buf, '.')) != NULL) { unsigned int major, minor, update, patch, port_update; while (p >= buf && *p != ' ') { p--; } if (sscanf(p + 1, "%u.%u.%u.%u.%u", &major, &minor, &update, &patch, &port_update) == 5) { return INT2FIX(ORAVERNUM(major, minor, update, patch, port_update)); } } return Qnil; } }
OCIInterval *oci8_set_ociinterval_ym(OCIInterval *intvl, VALUE val) { sb4 year; sb4 month; Check_Type(val, T_ARRAY); if (RARRAY_LEN(val) != 2) { rb_raise(rb_eRuntimeError, "invalid array size %ld", RARRAY_LEN(val)); } year = NUM2INT(RARRAY_PTR(val)[0]); month = NUM2INT(RARRAY_PTR(val)[1]); if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) { chkerr(OCIIntervalSetYearMonth(oci8_envhp, oci8_errhp, year, month, intvl)); } else { /* Workaround for Bug 2227982 */ char buf[64]; const char *sign = ""; if (year < 0 && month != 0) { year += 1; month -= 12; } if (year < 0 || month < 0) { sign = "-"; year = -year; month = -month; } sprintf(buf, "%s%d-%d", sign, year, month); chkerr(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl)); } return intvl; }
VALUE Init_oci8(void) { #if 0 oci8_cOCIHandle = rb_define_class("OCIHandle", rb_cObject); cOCI8 = rb_define_class("OCI8", oci8_cOCIHandle); #endif cOCI8 = oci8_define_class("OCI8", &oci8_svcctx_class); cSession = oci8_define_class_under(cOCI8, "Session", &oci8_svcctx_associate_class); cServer = oci8_define_class_under(cOCI8, "Server", &oci8_svcctx_associate_class); id_at_session_handle = rb_intern("@session_handle"); id_at_server_handle = rb_intern("@server_handle"); oracle_client_vernum = INT2FIX(oracle_client_version); if (have_OCIClientVersion) { sword major, minor, update, patch, port_update; OCIClientVersion(&major, &minor, &update, &patch, &port_update); oracle_client_vernum = INT2FIX(ORAVERNUM(major, minor, update, patch, port_update)); } sym_SYSDBA = ID2SYM(rb_intern("SYSDBA")); sym_SYSOPER = ID2SYM(rb_intern("SYSOPER")); id_at_prefetch_rows = rb_intern("@prefetch_rows"); id_set_prefetch_rows = rb_intern("prefetch_rows="); rb_define_const(cOCI8, "VERSION", rb_obj_freeze(rb_usascii_str_new_cstr(OCI8LIB_VERSION))); rb_define_singleton_method_nodoc(cOCI8, "oracle_client_vernum", oci8_s_oracle_client_vernum, 0); rb_define_singleton_method_nodoc(cOCI8, "__set_property", oci8_s_set_property, 2); if (have_OCIMessageOpen && have_OCIMessageGet) { rb_define_singleton_method(cOCI8, "error_message", oci8_s_error_message, 1); } rb_define_private_method(cOCI8, "parse_connect_string", oci8_parse_connect_string, 1); rb_define_private_method(cOCI8, "logon", oci8_logon, 3); rb_define_private_method(cOCI8, "allocate_handles", oci8_allocate_handles, 0); rb_define_private_method(cOCI8, "session_handle", oci8_get_session_handle, 0); rb_define_private_method(cOCI8, "server_handle", oci8_get_server_handle, 0); rb_define_private_method(cOCI8, "server_attach", oci8_server_attach, 2); rb_define_private_method(cOCI8, "session_begin", oci8_session_begin, 2); rb_define_method(cOCI8, "logoff", oci8_svcctx_logoff, 0); rb_define_method(cOCI8, "parse", oci8_svcctx_parse, 1); rb_define_method(cOCI8, "commit", oci8_commit, 0); rb_define_method(cOCI8, "rollback", oci8_rollback, 0); rb_define_method(cOCI8, "non_blocking?", oci8_non_blocking_p, 0); rb_define_method(cOCI8, "non_blocking=", oci8_set_non_blocking, 1); rb_define_method(cOCI8, "autocommit?", oci8_autocommit_p, 0); rb_define_method(cOCI8, "autocommit=", oci8_set_autocommit, 1); rb_define_method(cOCI8, "long_read_len", oci8_long_read_len, 0); rb_define_method(cOCI8, "long_read_len=", oci8_set_long_read_len, 1); rb_define_method(cOCI8, "break", oci8_break, 0); rb_define_method(cOCI8, "prefetch_rows=", oci8_set_prefetch_rows, 1); rb_define_private_method(cOCI8, "oracle_server_vernum", oci8_oracle_server_vernum, 0); rb_define_method(cOCI8, "ping", oci8_ping, 0); rb_define_method(cOCI8, "client_identifier=", oci8_set_client_identifier, 1); rb_define_method(cOCI8, "module=", oci8_set_module, 1); rb_define_method(cOCI8, "action=", oci8_set_action, 1); rb_define_method(cOCI8, "client_info=", oci8_set_client_info, 1); return cOCI8; }
VALUE Init_oci8(void) { #if 0 /* * OCIHandle is the abstract base class for all OCI handles and * descriptors which are opaque data types of Oracle Call Interface. */ oci8_cOCIHandle = rb_define_class("OCIHandle", rb_cObject); cOCI8 = rb_define_class("OCI8", oci8_cOCIHandle); #endif cOCI8 = oci8_define_class("OCI8", &oci8_svcctx_class); oracle_client_vernum = INT2FIX(oracle_client_version); if (have_OCIClientVersion) { sword major, minor, update, patch, port_update; OCIClientVersion(&major, &minor, &update, &patch, &port_update); oracle_client_vernum = INT2FIX(ORAVERNUM(major, minor, update, patch, port_update)); } sym_SYSDBA = ID2SYM(rb_intern("SYSDBA")); sym_SYSOPER = ID2SYM(rb_intern("SYSOPER")); id_at_prefetch_rows = rb_intern("@prefetch_rows"); id_at_username = rb_intern("@username"); id_set_prefetch_rows = rb_intern("prefetch_rows="); rb_define_singleton_method_nodoc(cOCI8, "oracle_client_vernum", oci8_s_oracle_client_vernum, 0); if (have_OCIMessageOpen && have_OCIMessageGet) { rb_define_singleton_method(cOCI8, "error_message", oci8_s_error_message, 1); } rb_define_private_method(cOCI8, "parse_connect_string", oci8_parse_connect_string, 1); rb_define_method(cOCI8, "initialize", oci8_svcctx_initialize, -1); rb_define_method(cOCI8, "logoff", oci8_svcctx_logoff, 0); rb_define_method(cOCI8, "parse", oci8_svcctx_parse, 1); rb_define_method(cOCI8, "commit", oci8_commit, 0); rb_define_method(cOCI8, "rollback", oci8_rollback, 0); rb_define_method(cOCI8, "non_blocking?", oci8_non_blocking_p, 0); rb_define_method(cOCI8, "non_blocking=", oci8_set_non_blocking, 1); rb_define_method(cOCI8, "autocommit?", oci8_autocommit_p, 0); rb_define_method(cOCI8, "autocommit=", oci8_set_autocommit, 1); rb_define_method(cOCI8, "long_read_len", oci8_long_read_len, 0); rb_define_method(cOCI8, "long_read_len=", oci8_set_long_read_len, 1); rb_define_method(cOCI8, "break", oci8_break, 0); rb_define_method(cOCI8, "prefetch_rows=", oci8_set_prefetch_rows, 1); rb_define_private_method(cOCI8, "oracle_server_vernum", oci8_oracle_server_vernum, 0); rb_define_method(cOCI8, "ping", oci8_ping, 0); rb_define_method(cOCI8, "client_identifier=", oci8_set_client_identifier, 1); rb_define_method(cOCI8, "module=", oci8_set_module, 1); rb_define_method(cOCI8, "action=", oci8_set_action, 1); rb_define_method(cOCI8, "client_info=", oci8_set_client_info, 1); return cOCI8; }
/* * call-seq: * client_identifier = string or nil * * <b>(new in 2.0.3)</b> * * Sets the client ID. This information is stored in the V$SESSION * view. * * === Oracle 9i client or upper * * This doesn't perform network round trips. The change is reflected * to the server by the next round trip such as OCI8#exec, OCI8#ping, * etc. * * === Oracle 8i client or lower * * This executes the following PL/SQL block internally. * The change is reflected immediately by a network round trip. * * BEGIN * DBMS_SESSION.SET_IDENTIFIER(:client_id); * END; * * See {Oracle Manual: Oracle Database PL/SQL Packages and Types Reference}[http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_sessio.htm#i996935] * */ static VALUE oci8_set_client_identifier(VALUE self, VALUE val) { char *ptr; ub4 size; int use_attr_set = 1; if (!NIL_P(val)) { OCI8SafeStringValue(val); ptr = RSTRING_PTR(val); size = RSTRING_LEN(val); } else { ptr = ""; size = 0; } if (oracle_client_version < ORAVER_9_0) { use_attr_set = 0; } else if (oracle_client_version < ORAVERNUM(9, 2, 0, 3, 0) && size == 0) { /* Workaround for Bug 2449486 */ use_attr_set = 0; } if (use_attr_set) { if (size > 0 && ptr[0] == ':') { rb_raise(rb_eArgError, "client identifier should not start with ':'."); } oci_lc(OCIAttrSet(oci8_get_oci_session(self), OCI_HTYPE_SESSION, ptr, size, OCI_ATTR_CLIENT_IDENTIFIER, oci8_errhp)); } else { oci8_exec_sql_var_t bind_vars[1]; /* :client_id */ bind_vars[0].valuep = ptr; bind_vars[0].value_sz = size; bind_vars[0].dty = SQLT_CHR; bind_vars[0].indp = NULL; bind_vars[0].alenp = NULL; oci8_exec_sql(oci8_get_svcctx(self), "BEGIN\n" " DBMS_SESSION.SET_IDENTIFIER(:client_id);\n" "END;\n", 0, NULL, 1, bind_vars, 1); } return val; }
OCIInterval *oci8_set_ociinterval_ds(OCIInterval *intvl, VALUE val) { sb4 day; sb4 hour; sb4 minute; sb4 sec; sb4 fsec; Check_Type(val, T_ARRAY); if (RARRAY_LEN(val) != 5) { rb_raise(rb_eRuntimeError, "invalid array size %ld", RARRAY_LEN(val)); } day = NUM2INT(RARRAY_PTR(val)[0]); hour = NUM2INT(RARRAY_PTR(val)[1]); minute = NUM2INT(RARRAY_PTR(val)[2]); sec = NUM2INT(RARRAY_PTR(val)[3]); fsec = NUM2INT(RARRAY_PTR(val)[4]); if (oracle_client_version >= ORAVERNUM(9, 2, 0, 3, 0)) { chkerr(OCIIntervalSetDaySecond(oci8_envhp, oci8_errhp, day, hour, minute, sec, fsec, intvl)); } else { /* Workaround for Bug 2227982 */ char buf[64]; const char *sign = ""; if (day == 0) { if (hour < 0) { sign = "-"; hour = -hour; } else if (minute < 0) { sign = "-"; minute = -minute; } else if (sec < 0) { sign = "-"; sec = -sec; } else if (fsec < 0) { sign = "-"; fsec = -fsec; } } sprintf(buf, "%s%d %02d:%02d:%02d.%09d", sign, day, hour, minute, sec, fsec); chkerr(OCIIntervalFromText(oci8_envhp, oci8_errhp, (text*)buf, strlen(buf), intvl)); } return intvl; }
void Init_oci8lib() { VALUE cOCI8; OCIEnv *envhp; OCIError *errhp; sword rv; #ifdef RUNTIME_API_CHECK Init_oci8_apiwrap(); if (oracle_client_version < ORAVER_9_0) { rb_raise(rb_eLoadError, "Oracle 8 (8.0) and Oracle 8i (8.1) is not supported anymore!"); } if (have_OCIClientVersion) { sword major, minor, update, patch, port_update; OCIClientVersion(&major, &minor, &update, &patch, &port_update); oracle_client_version = ORAVERNUM(major, minor, update, patch, port_update); } #endif oci8_id_at_last_error = rb_intern("@last_error"); oci8_id_new = rb_intern("new"); oci8_id_get = rb_intern("get"); oci8_id_set = rb_intern("set"); oci8_id_oci8_vtable = rb_intern("__oci8_vtable__"); #ifdef CHAR_IS_NOT_A_SHORTCUT_TO_ID oci8_id_add_op = rb_intern("+"); oci8_id_sub_op = rb_intern("-"); oci8_id_mul_op = rb_intern("*"); oci8_id_div_op = rb_intern("/"); #endif #ifdef HAVE_RB_SET_END_PROC rb_set_end_proc(at_exit_func, Qnil); #endif Init_oci8_thread_util(); Init_oci8_error(); Init_oci8_env(); /* OCIHandle class */ Init_oci8_handle(); /* OCI8 class */ Init_oci8(&cOCI8); /* OCI8::ConnectionPool class */ Init_oci8_connection_pool(cOCI8); /* OCI8::BindType module */ mOCI8BindType = rb_define_module_under(cOCI8, "BindType"); /* OCI8::BindType::Base class */ cOCI8BindTypeBase = rb_define_class_under(mOCI8BindType, "Base", oci8_cOCIHandle); /* Handle */ Init_oci8_bind(cOCI8BindTypeBase); Init_oci8_stmt(cOCI8); /* Encoding */ Init_oci8_encoding(cOCI8); /* register allocators */ Init_oci8_metadata(cOCI8); Init_oci8_lob(cOCI8); /* allocate a temporary errhp to pass Init_oci_number() */ rv = OCIEnvCreate(&envhp, oci8_env_mode, NULL, NULL, NULL, NULL, 0, NULL); if (rv != OCI_SUCCESS) { oci8_raise_init_error(); } rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL); if (rv != OCI_SUCCESS) oci8_env_raise(envhp, rv); Init_oci_number(cOCI8, errhp); OCIHandleFree(errhp, OCI_HTYPE_ERROR); OCIHandleFree(envhp, OCI_HTYPE_ENV); Init_ora_date(); Init_oci_datetime(); Init_oci_object(cOCI8); #ifdef USE_WIN32_C Init_oci8_win32(cOCI8); #endif }
void Init_oci8lib() { VALUE cOCI8; OCIEnv *envhp; OCIError *errhp; sword rv; #ifdef RUNTIME_API_CHECK Init_oci8_apiwrap(); if (oracle_client_version < ORAVER_10_1) { const char *oraver; const char *ruby_oci8_ver; if (oracle_client_version >= ORAVER_9_2) { oraver = "9iR2"; ruby_oci8_ver = "2.1.x"; } else if (oracle_client_version >= ORAVER_9_0) { oraver = "9iR1"; ruby_oci8_ver = "2.1.x"; } else if (oracle_client_version >= ORAVER_8_2) { oraver = "8i"; ruby_oci8_ver = "2.0.x"; } else { oraver = "8"; ruby_oci8_ver = "2.0.x"; } rb_raise(rb_eLoadError, "Ruby-oci8 %s doesn't support Oracle %s. Use ruby-oci8 %s instead.", OCI8LIB_VERSION, oraver, ruby_oci8_ver); } if (have_OCIClientVersion) { sword major, minor, update, patch, port_update; OCIClientVersion(&major, &minor, &update, &patch, &port_update); oracle_client_version = ORAVERNUM(major, minor, update, patch, port_update); } #endif oci8_id_at_last_error = rb_intern("@last_error"); oci8_id_get = rb_intern("get"); oci8_id_set = rb_intern("set"); #ifdef CHAR_IS_NOT_A_SHORTCUT_TO_ID oci8_id_add_op = rb_intern("+"); oci8_id_sub_op = rb_intern("-"); oci8_id_mul_op = rb_intern("*"); oci8_id_div_op = rb_intern("/"); #endif #ifdef HAVE_RB_SET_END_PROC rb_set_end_proc(at_exit_func, Qnil); #endif Init_oci8_thread_util(); Init_oci8_error(); Init_oci8_env(); /* OCIHandle class */ Init_oci8_handle(); /* OCI8 class */ Init_oci8(&cOCI8); /* OCI8::ConnectionPool class */ Init_oci8_connection_pool(cOCI8); /* OCI8::BindType module */ mOCI8BindType = rb_define_module_under(cOCI8, "BindType"); /* OCI8::BindType::Base class */ cOCI8BindTypeBase = oci8_define_class_under(mOCI8BindType, "Base", &oci8_bind_data_type, bind_base_alloc); /* Handle */ Init_oci8_bind(cOCI8BindTypeBase); Init_oci8_stmt(cOCI8); /* Encoding */ Init_oci8_encoding(cOCI8); /* register allocators */ Init_oci8_metadata(cOCI8); Init_oci8_lob(cOCI8); /* allocate a temporary errhp to pass Init_oci_number() */ rv = OCIEnvCreate(&envhp, oci8_env_mode, NULL, NULL, NULL, NULL, 0, NULL); if (rv != OCI_SUCCESS) { oci8_raise_init_error(); } rv = OCIHandleAlloc(envhp, (dvoid *)&errhp, OCI_HTYPE_ERROR, 0, NULL); if (rv != OCI_SUCCESS) oci8_env_raise(envhp, rv); Init_oci_number(cOCI8, errhp); OCIHandleFree(errhp, OCI_HTYPE_ERROR); OCIHandleFree(envhp, OCI_HTYPE_ENV); Init_ora_date(); Init_oci_datetime(); Init_oci_object(cOCI8); #ifdef USE_WIN32_C Init_oci8_win32(cOCI8); #endif }