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; }
void Init_oci8_lob(VALUE cOCI8) { id_plus = rb_intern("+"); id_dir_alias = rb_intern("@dir_alias"); id_filename = rb_intern("@filename"); seek_set = rb_eval_string("::IO::SEEK_SET"); seek_cur = rb_eval_string("::IO::SEEK_CUR"); seek_end = rb_eval_string("::IO::SEEK_END"); cOCI8LOB = oci8_define_class_under(cOCI8, "LOB", &oci8_lob_class); cOCI8CLOB = rb_define_class_under(cOCI8, "CLOB", cOCI8LOB); cOCI8NCLOB = rb_define_class_under(cOCI8, "NCLOB", cOCI8LOB); cOCI8BLOB = rb_define_class_under(cOCI8, "BLOB", cOCI8LOB); cOCI8BFILE = rb_define_class_under(cOCI8, "BFILE", cOCI8LOB); rb_define_method(cOCI8CLOB, "initialize", oci8_clob_initialize, -1); rb_define_method(cOCI8NCLOB, "initialize", oci8_nclob_initialize, -1); rb_define_method(cOCI8BLOB, "initialize", oci8_blob_initialize, -1); rb_define_private_method(cOCI8LOB, "__char_width=", oci8_lob_set_char_width, 1); rb_define_method(cOCI8LOB, "available?", oci8_lob_available_p, 0); rb_define_method(cOCI8LOB, "size", oci8_lob_get_size, 0); rb_define_method(cOCI8LOB, "pos", oci8_lob_get_pos, 0); rb_define_alias(cOCI8LOB, "tell", "pos"); rb_define_method(cOCI8LOB, "eof?", oci8_lob_eof_p, 0); rb_define_method(cOCI8LOB, "seek", oci8_lob_seek, -1); rb_define_method(cOCI8LOB, "rewind", oci8_lob_rewind, 0); rb_define_method(cOCI8LOB, "truncate", oci8_lob_truncate, 1); rb_define_method(cOCI8LOB, "size=", oci8_lob_set_size, 1); rb_define_method(cOCI8LOB, "read", oci8_lob_read, -1); rb_define_method(cOCI8LOB, "write", oci8_lob_write, 1); rb_define_method(cOCI8LOB, "close", oci8_lob_close, 0); rb_define_method(cOCI8LOB, "sync", oci8_lob_get_sync, 0); rb_define_method(cOCI8LOB, "sync=", oci8_lob_set_sync, 1); rb_define_method(cOCI8LOB, "flush", oci8_lob_flush, 0); rb_define_method(cOCI8LOB, "chunk_size", oci8_lob_get_chunk_size, 0); rb_define_method(cOCI8BFILE, "initialize", oci8_bfile_initialize, -1); rb_define_method(cOCI8BFILE, "dir_alias", oci8_bfile_get_dir_alias, 0); rb_define_method(cOCI8BFILE, "filename", oci8_bfile_get_filename, 0); rb_define_method(cOCI8BFILE, "dir_alias=", oci8_bfile_set_dir_alias, 1); rb_define_method(cOCI8BFILE, "filename=", oci8_bfile_set_filename, 1); rb_define_method(cOCI8BFILE, "exists?", oci8_bfile_exists_p, 0); rb_define_method(cOCI8BFILE, "truncate", oci8_bfile_error, 1); rb_define_method(cOCI8BFILE, "size=", oci8_bfile_error, 1); rb_define_method(cOCI8BFILE, "write", oci8_bfile_error, 1); oci8_define_bind_class("CLOB", &bind_clob_class.bind); oci8_define_bind_class("NCLOB", &bind_nclob_class.bind); oci8_define_bind_class("BLOB", &bind_blob_class.bind); oci8_define_bind_class("BFILE", &bind_bfile_class.bind); }
void Init_oci8_connection_pool(VALUE cOCI8) { #if 0 cOCIHandle = rb_define_class("OCIHandle", rb_cObject); cOCI8 = rb_define_class("OCI8", cOCIHandle); cOCIConnectionPool = rb_define_class_under(cOCI8, "ConnectionPool", cOCIHandle); #endif cOCIConnectionPool = oci8_define_class_under(cOCI8, "ConnectionPool", &oci8_cpool_class); rb_define_private_method(cOCIConnectionPool, "initialize", oci8_cpool_initialize, -1); rb_define_method(cOCIConnectionPool, "reinitialize", oci8_cpool_reinitialize, 3); rb_define_private_method(cOCIConnectionPool, "pool_name", oci8_cpool_pool_name, 0); }
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 }