[ruby-oci8-commit] [523] trunk/ruby-oci8: add OCI8's class variables: @@ environment_handle and @@process_handle.
nobody at rubyforge.org
nobody at rubyforge.org
Sun May 20 07:44:51 UTC 2012
Revision: 523
Author: kubo
Date: 2012-05-20 07:44:50 +0000 (Sun, 20 May 2012)
Log Message:
-----------
add OCI8's class variables: @@environment_handle and @@process_handle.
Modified Paths:
--------------
trunk/ruby-oci8/ChangeLog
trunk/ruby-oci8/ext/oci8/oci8.c
trunk/ruby-oci8/test/test_oci8.rb
Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog 2012-05-20 06:51:31 UTC (rev 522)
+++ trunk/ruby-oci8/ChangeLog 2012-05-20 07:44:50 UTC (rev 523)
@@ -1,4 +1,8 @@
2012-05-20 KUBO Takehiro <kubo at jiubao.org>
+ * ext/oci8/oci8.c, test/test_oci8.rb: add OCI8's class variables:
+ @@environment_handle and @@process_handle.
+
+2012-05-20 KUBO Takehiro <kubo at jiubao.org>
* ext/oci8/ocihandle.c, lib/oci8/metadata.rb, test/test_metadata.rb:
fix methods of OCI8::Metadata::Sequence and add testcases for them.
Modified: trunk/ruby-oci8/ext/oci8/oci8.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.c 2012-05-20 06:51:31 UTC (rev 522)
+++ trunk/ruby-oci8/ext/oci8/oci8.c 2012-05-20 07:44:50 UTC (rev 523)
@@ -41,6 +41,26 @@
static ID id_at_session_handle;
static ID id_at_server_handle;
+static VALUE dummy_env_method_missing(int argc, VALUE *argv, VALUE self)
+{
+ VALUE obj = rb_cv_get(cOCI8, "@@environment_handle");
+ VALUE method_id, args;
+
+ if (self == obj) {
+ oci8_base_t *base;
+ obj = rb_obj_alloc(oci8_cOCIHandle);
+ base = DATA_PTR(obj);
+ base->type = OCI_HTYPE_ENV;
+ base->hp.ptr = oci8_envhp;
+ base->self = Qnil;
+ rb_cv_set(cOCI8, "@@environment_handle", obj);
+ }
+
+ rb_scan_args(argc, argv, "1*", &method_id, &args);
+ Check_Type(method_id, T_SYMBOL);
+ return rb_apply(obj, SYM2ID(method_id), args);
+}
+
typedef struct oci8_svcctx_associate {
oci8_base_t base;
oci8_svcctx_t *svcctx;
@@ -1054,6 +1074,8 @@
VALUE Init_oci8(void)
{
+ VALUE obj;
+ oci8_base_t *base;
#if 0
oci8_cOCIHandle = rb_define_class("OCIHandle", rb_cObject);
cOCI8 = rb_define_class("OCI8", oci8_cOCIHandle);
@@ -1064,6 +1086,18 @@
id_at_session_handle = rb_intern("@session_handle");
id_at_server_handle = rb_intern("@server_handle");
+ /* setup a dummy environment handle to lazily initialize the environment handle */
+ obj = rb_obj_alloc(rb_cObject);
+ rb_define_singleton_method(obj, "method_missing", dummy_env_method_missing, -1);
+ rb_cv_set(cOCI8, "@@environment_handle", obj);
+
+ /* setup the process handle */
+ obj = rb_obj_alloc(oci8_cOCIHandle);
+ base = DATA_PTR(obj);
+ base->type = OCI_HTYPE_PROC;
+ base->self = Qnil;
+ rb_cv_set(cOCI8, "@@process_handle", obj);
+
oracle_client_vernum = INT2FIX(oracle_client_version);
if (have_OCIClientVersion) {
sword major, minor, update, patch, port_update;
Modified: trunk/ruby-oci8/test/test_oci8.rb
===================================================================
--- trunk/ruby-oci8/test/test_oci8.rb 2012-05-20 06:51:31 UTC (rev 522)
+++ trunk/ruby-oci8/test/test_oci8.rb 2012-05-20 07:44:50 UTC (rev 523)
@@ -456,4 +456,20 @@
assert_kind_of(OCISuccessWithInfo, @conn.last_error)
assert_equal(24347, @conn.last_error.code)
end
+
+ def test_environment_handle
+ # OCI_ATTR_HEAPALLOC
+ assert_operator(OCI8.class_variable_get(:@@environment_handle).send(:attr_get_ub4, 30), :>, 0)
+ # OCI_ATTR_OBJECT
+ assert(OCI8.class_variable_get(:@@environment_handle).send(:attr_get_boolean, 2))
+ # OCI_ATTR_SHARED_HEAPALLOC
+ assert_equal(0, OCI8.class_variable_get(:@@environment_handle).send(:attr_get_ub4, 84))
+ end
+
+ def test_process_handle
+ # OCI_ATTR_MEMPOOL_APPNAME
+ assert_equal('', OCI8.class_variable_get(:@@process_handle).send(:attr_get_string, 90))
+ # OCI_ATTR_MEMPOOL_SIZE
+ assert_equal(0, OCI8.class_variable_get(:@@process_handle).send(:attr_get_ub4, 88))
+ end
end # TestOCI8
More information about the ruby-oci8-commit
mailing list