Class: JDBCHelper::Connection::ResultSetEnumerator

Inherits:
Object
  • Object
show all
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

#closeObject



44
45
46
47
48
49
50
# File 'lib/jdbc-helper/connection/result_set_enumerator.rb', line 44

def close
	return if closed?

	@rset.close
	@close_callback.call if @close_callback
	@closed = true
end

#closed?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/jdbc-helper/connection/result_set_enumerator.rb', line 52

def closed?
	@closed
end

#eachObject



11
12
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
# File 'lib/jdbc-helper/connection/result_set_enumerator.rb', line 11

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|
						v = @rset.send gt, idx+=1
						@rset.was_null ? nil : v
					},
					count += 1)
		end
	ensure			
		close
	end
end