Class: PLSQL::JDBCConnection::Cursor

Inherits:
Object
  • Object
show all
Includes:
Connection::CursorCommon
Defined in:
lib/plsql/jdbc_connection.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Connection::CursorCommon

#fetch_all, #fetch_hash, #fetch_hash_all

Constructor Details

#initialize(conn, result_set) ⇒ Cursor

Returns a new instance of Cursor.



123
124
125
126
127
128
129
130
131
132
# File 'lib/plsql/jdbc_connection.rb', line 123

def initialize(conn, result_set)
  @connection = conn
  @result_set = result_set
  @metadata = @result_set.
  @column_count = @metadata.getColumnCount
  @column_type_names = [nil] # column numbering starts at 1
  (1..@column_count).each do |i|
    @column_type_names << {:type_name => @metadata.getColumnTypeName(i), :sql_type => @metadata.getColumnType(i)}
  end
end

Instance Attribute Details

#result_setObject (readonly)

Returns the value of attribute result_set.



120
121
122
# File 'lib/plsql/jdbc_connection.rb', line 120

def result_set
  @result_set
end

#statementObject

Returns the value of attribute statement.



121
122
123
# File 'lib/plsql/jdbc_connection.rb', line 121

def statement
  @statement
end

Class Method Details

.new_from_query(conn, sql, bindvars = [], options = {}) ⇒ Object



134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/plsql/jdbc_connection.rb', line 134

def self.new_from_query(conn, sql, bindvars=[], options={})
  stmt = conn.prepare_statement(sql, *bindvars)
  if prefetch_rows = options[:prefetch_rows]
    stmt.setRowPrefetch(prefetch_rows)
  end
  cursor = Cursor.new(conn, stmt.executeQuery)
  cursor.statement = stmt
  cursor
rescue
  # in case of any error close statement
  stmt.close rescue nil
  raise
end

Instance Method Details

#closeObject



164
165
166
167
# File 'lib/plsql/jdbc_connection.rb', line 164

def close
  @result_set.close
  @statement.close if @statement
end

#fetchObject



148
149
150
151
152
153
154
155
156
# File 'lib/plsql/jdbc_connection.rb', line 148

def fetch
  if @result_set.next
    (1..@column_count).map do |i|
      @connection.get_ruby_value_from_result_set(@result_set, i, @column_type_names[i])
    end
  else
    nil
  end
end

#fieldsObject



158
159
160
161
162
# File 'lib/plsql/jdbc_connection.rb', line 158

def fields
  @fields ||= (1..@column_count).map do |i|
    @metadata.getColumnName(i).downcase.to_sym
  end
end