[ruby-oci8-commit] [461] trunk/ruby-oci8: reset OCI8#last_error when OCI8#parse or OCI8#exec is called.

nobody at rubyforge.org nobody at rubyforge.org
Sat Oct 29 08:37:06 EDT 2011


Revision: 461
Author:   kubo
Date:     2011-10-29 08:37:04 -0400 (Sat, 29 Oct 2011)

Log Message:
-----------
reset OCI8#last_error when OCI8#parse or OCI8#exec is called. fix bugs added by the last commit but one.

Modified Paths:
--------------
    trunk/ruby-oci8/ChangeLog
    trunk/ruby-oci8/ext/oci8/error.c
    trunk/ruby-oci8/ext/oci8/oci8.c
    trunk/ruby-oci8/lib/oci8/object.rb
    trunk/ruby-oci8/lib/oci8/oci8.rb

Modified: trunk/ruby-oci8/ChangeLog
===================================================================
--- trunk/ruby-oci8/ChangeLog	2011-10-29 11:57:00 UTC (rev 460)
+++ trunk/ruby-oci8/ChangeLog	2011-10-29 12:37:04 UTC (rev 461)
@@ -1,4 +1,9 @@
 2011-10-29  KUBO Takehiro  <kubo at jiubao.org>
+	* ext/oci8/error.c, ext/oci8/oci8.c, lib/oci8/object.rb, lib/oci8/oci8.rb:
+	    reset OCI8#last_error when OCI8#parse or OCI8#exec is called.
+	    fix bugs added by the last commit but one.
+
+2011-10-29  KUBO Takehiro  <kubo at jiubao.org>
 	* ext/oci8/oraconf.rb: use RbConfig::CONFIG instead of obsolete
 	    Config::CONFIG.
 

Modified: trunk/ruby-oci8/ext/oci8/error.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/error.c	2011-10-29 11:57:00 UTC (rev 460)
+++ trunk/ruby-oci8/ext/oci8/error.c	2011-10-29 12:37:04 UTC (rev 461)
@@ -276,7 +276,7 @@
         VALUE exc = oci8_make_exc(oci8_errhp, status, OCI_HTYPE_ERROR, stmthp, file, line);
         while (base != NULL) {
             if (base->type == OCI_HTYPE_SVCCTX) {
-                rb_ivar_set(exc, oci8_id_at_last_error, exc);
+                rb_ivar_set(base->self, oci8_id_at_last_error, exc);
                 break;
             }
             base = base->parent;

Modified: trunk/ruby-oci8/ext/oci8/oci8.c
===================================================================
--- trunk/ruby-oci8/ext/oci8/oci8.c	2011-10-29 11:57:00 UTC (rev 460)
+++ trunk/ruby-oci8/ext/oci8/oci8.c	2011-10-29 12:37:04 UTC (rev 461)
@@ -96,6 +96,7 @@
 #endif
         }
     }
+    svcctx->base.type = 0;
 }
 
 static void oci8_svcctx_init(oci8_base_t *base)
@@ -358,13 +359,13 @@
     }
 
     /* logon */
+    svcctx->base.type = OCI_HTYPE_SVCCTX;
     chker2(OCILogon_nb(svcctx, oci8_envhp, oci8_errhp, &svcctx->base.hp.svc,
                        RSTRING_ORATEXT(username), RSTRING_LEN(username),
                        RSTRING_ORATEXT(password), RSTRING_LEN(password),
                        NIL_P(dbname) ? NULL : RSTRING_ORATEXT(dbname),
                        NIL_P(dbname) ? 0 : RSTRING_LEN(dbname)),
            &svcctx->base);
-    svcctx->base.type = OCI_HTYPE_SVCCTX;
     svcctx->logoff_strategy = &simple_logoff;
 
     /* setup the session handle */
@@ -547,22 +548,6 @@
 
 /*
  * call-seq:
- *   parse(sql_text) -> an instance of OCI8::Cursor
- *
- * Prepares the SQL statement and returns a new OCI8::Cursor.
- */
-static VALUE oci8_svcctx_parse(VALUE self, VALUE sql)
-{
-    VALUE obj = rb_funcall(cOCIStmt, oci8_id_new, 2, self, sql);
-    VALUE prefetch_rows = rb_ivar_get(self, id_at_prefetch_rows);
-    if (!NIL_P(prefetch_rows)) {
-        rb_funcall(obj, id_set_prefetch_rows, 1, prefetch_rows);
-    }
-    return obj;
-}
-
-/*
- * call-seq:
  *   commit
  *
  * Commits the transaction.
@@ -1125,7 +1110,6 @@
     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);

Modified: trunk/ruby-oci8/lib/oci8/object.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/object.rb	2011-10-29 11:57:00 UTC (rev 460)
+++ trunk/ruby-oci8/lib/oci8/object.rb	2011-10-29 12:37:04 UTC (rev 461)
@@ -147,7 +147,7 @@
   :self := #{tdo.typename}(#{bind_arg_helper.arg_str});
 END;
 EOS
-        csr = @con.parse(sql)
+        csr = @con.parse_internal(sql)
         begin
           csr.bind_param(:self, nil, :named_type_internal, tdo)
           bind_arg_helper.exec(@con, csr)
@@ -174,7 +174,7 @@
   #{tdo.typename}.#{method_id}(#{bind_arg_helper.arg_str});
 END;
 EOS
-          csr = con.parse(sql)
+          csr = con.parse_internal(sql)
           begin
             bind_arg_helper.exec(con, csr)
           ensure
@@ -190,7 +190,7 @@
   :rv := #{tdo.typename}.#{method_id}(#{bind_arg_helper.arg_str});
 END;
 EOS
-          csr = con.parse(sql)
+          csr = con.parse_internal(sql)
           begin
             csr.bind_param(:rv, nil, return_type)
             bind_arg_helper.exec(con, csr)
@@ -243,7 +243,7 @@
   :self := val;
 END;
 EOS
-          csr = @con.parse(sql)
+          csr = @con.parse_internal(sql)
           begin
             csr.bind_param(:self, nil, :named_type_internal, tdo)
             csr[:self].attributes = self
@@ -264,7 +264,7 @@
   :self := val;
 END;
 EOS
-          csr = @con.parse(sql)
+          csr = @con.parse_internal(sql)
           begin
             csr.bind_param(:self, nil, :named_type_internal, tdo)
             csr.bind_param(:rv, nil, return_type)
@@ -376,7 +376,7 @@
         result_type = nil
         if type_method.has_result?
           # function
-          con.exec("select result_type_owner, result_type_name from all_method_results where OWNER = :1 and TYPE_NAME = :2 and METHOD_NO = :3", metadata.schema_name, metadata.name, i + 1) do |r|
+          con.exec_internal("select result_type_owner, result_type_name from all_method_results where OWNER = :1 and TYPE_NAME = :2 and METHOD_NO = :3", metadata.schema_name, metadata.name, i + 1) do |r|
             if r[0].nil?
               result_type = @@result_type_to_bindtype[r[1]]
             else

Modified: trunk/ruby-oci8/lib/oci8/oci8.rb
===================================================================
--- trunk/ruby-oci8/lib/oci8/oci8.rb	2011-10-29 11:57:00 UTC (rev 460)
+++ trunk/ruby-oci8/lib/oci8/oci8.rb	2011-10-29 12:37:04 UTC (rev 461)
@@ -137,6 +137,22 @@
     @username = nil
   end
 
+  # call-seq:
+  #   parse(sql_text) -> an OCI8::Cursor
+  #
+  # Returns a prepared SQL handle.
+  def parse(sql)
+    @last_error = nil
+    parse_internal(sql)
+  end
+
+  # same with OCI8#parse except that this doesn't reset OCI8#last_error.
+  def parse_internal(sql)
+    cursor = OCI8::Cursor.new(self, sql)
+    cursor.prefetch_rows = @prefetch_rows if @prefetch_rows
+    cursor
+  end
+
   # Executes the sql statement. The type of return value depends on
   # the type of sql statement: select; insert, update and delete;
   # create, alter and drop; and PL/SQL.
@@ -222,7 +238,13 @@
   #   conn.exec('CREATE TABLE test (col1 CHAR(6))') # => 0
   #   conn.logoff
   #
-  def exec(sql, *bindvars)
+  def exec(sql, *bindvars, &block)
+    @last_error = nil
+    exec_internal(sql, *bindvars, &block)
+  end
+
+  # same with OCI8#exec except that this doesn't reset OCI8#last_error.
+  def exec_internal(sql, *bindvars)
     begin
       cursor = parse(sql)
       ret = cursor.exec(*bindvars)




More information about the ruby-oci8-commit mailing list