Class: JDBC::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/jdbc/result.rb

Instance Method Summary collapse

Constructor Details

#initialize(resultSet, statement) ⇒ Result

Returns a new instance of Result.



3
4
5
6
7
# File 'lib/jdbc/result.rb', line 3

def initialize(resultSet, statement)
  @rs = resultSet
  @stmt = statement
  @columns = 
end

Instance Method Details

#closeObject



53
54
55
56
# File 'lib/jdbc/result.rb', line 53

def close
  @rs.close unless @rs.nil?
  @stmt.close unless @stmt.nil?
end

#eachObject



41
42
43
44
45
# File 'lib/jdbc/result.rb', line 41

def each
  while(result = fetch)
    yield(result)
  end
end

#each_hashObject



47
48
49
50
51
# File 'lib/jdbc/result.rb', line 47

def each_hash
  while(result = fetch_hash)
    yield(result)
  end
end

#fetchObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/jdbc/result.rb', line 9

def fetch
  if @rs.next
    result = []
  
    @columns.each do |column| 
      result << fetch_and_cast(@rs, column)
    end
    
    return result
  end
  
  close
  
  return nil
end

#fetch_hashObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/jdbc/result.rb', line 25

def fetch_hash
  if @rs.next
    result = {}
  
    @columns.each do |column| 
      result[column[:name]] = fetch_and_cast(@rs, column)
    end
    
    return result
  end
  
  close
  
  return nil
end