Class: JDBCHelper::Connection::ResultSetEnumerator
- Inherits:
-
Object
- Object
- JDBCHelper::Connection::ResultSetEnumerator
- Includes:
- Enumerable
- Defined in:
- lib/jdbc-helper/connection/result_set_enumerator.rb
Overview
Automatically closed after used. When not used, you must close it explicitly by calling “close”.
Instance Method Summary collapse
Instance Method Details
#close ⇒ Object
54 55 56 57 58 59 60 |
# File 'lib/jdbc-helper/connection/result_set_enumerator.rb', line 54 def close return if closed? @rset.close @close_callback.call if @close_callback @closed = true end |
#closed? ⇒ Boolean
62 63 64 |
# File 'lib/jdbc-helper/connection/result_set_enumerator.rb', line 62 def closed? @closed end |
#each ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/jdbc-helper/connection/result_set_enumerator.rb', line 13 def each return if closed? count = -1 begin while @rset.next idx = 0 # Oracle returns numbers in NUMERIC type, which can be of any precision. # So, we retrieve the numbers in String type not to lose their precision. # This can be quite annoying when you're just working with integers, # so I tried the following code to automatically convert integer string into integer # when it's obvious. However, the performance drop is untolerable. # Thus, commented out. # # if v && @cols_meta[i-1] == java.sql.Types::NUMERIC && v !~ /[\.e]/i # v.to_i # else # v # end yield Connection::Row.new( @col_labels, @col_labels_d, @getters.map { |gt| case gt when :getBigNum v = @rset.getBigDecimal idx+=1 @rset.was_null ? nil : v.toPlainString.to_i when :getBigDecimal v = @rset.getBigDecimal idx+=1 @rset.was_null ? nil : BigDecimal.new(v.toPlainString) else v = @rset.send gt, idx+=1 @rset.was_null ? nil : v end }, count += 1) end ensure close end end |