Method: JDBCHelper::Connection::ResultSet#each

Defined in:
lib/jdbc-helper/connection/result_set.rb

#eachObject



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