kubo / ruby-oci8

Ruby-oci8 - Oracle interface for ruby
Other
169 stars 75 forks source link

Do not call __paramGet(i) when @define_handles[i - 1] is already defined #171

Closed doloopwhile closed 6 years ago

doloopwhile commented 6 years ago

Hello.

It looks needless to me that __paramGet(i) is called for every call of exec (via define_columns).

BTW, I am using ruby-oci8 with activerecord-oracle_enhanced-adapter. When one query is executed repeatedly with different bind parameters, activerecord-oracle_enhanced-adapter keeps one cursor for the query and call exec (and __paramsGet) of the cursor. I encoutered a problem that __paramsGet becomes very slow as it is called. I hope that this pull request fixes the problem.

kubo commented 6 years ago

Thank you! I have not noticed it.

Your patch won't work in the following case.

cursor = conn.parse('select empno, ename from emp')
cursor.define(1, Integer)
cursor.exec
cursor.get_col_names # => NoMethodError: undefined method `name' for nil:NilClass

It will be fixed with the following patch. I'll check this patch tomorrow.

--- a/lib/oci8/cursor.rb
+++ b/lib/oci8/cursor.rb
@@ -125,7 +125,8 @@ class OCI8
       case type
       when :select_stmt
         __execute(0)
-        define_columns()
+        define_columns() if @column_metadata.size == 0
+        @column_metadata.size
       else
         __execute(1)
         row_count
kubo commented 6 years ago

@doloopwhile Thank you! I fixed it by 7dd7642.