Class: JDBCHelper::Connection::ResultSet
- Inherits:
-
Object
- Object
- JDBCHelper::Connection::ResultSet
- Includes:
- Enumerable
- Defined in:
- lib/jdbc-helper/connection/result_set.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
53 54 55 56 57 58 59 |
# File 'lib/jdbc-helper/connection/result_set.rb', line 53 def close return if closed? @rset.close @close_callback.call if @close_callback @closed = true end |
#closed? ⇒ Boolean
61 62 63 |
# File 'lib/jdbc-helper/connection/result_set.rb', line 61 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 |
# File 'lib/jdbc-helper/connection/result_set.rb', line 13 def each return enum_for(:each) unless block_given? return if closed? while @nrow 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 row = 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 }, @rownum += 1) close unless @nrow = @rset.next yield row end close end |