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.



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

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.



144
145
146
# File 'lib/plsql/jdbc_connection.rb', line 144

def result_set
  @result_set
end

#statementObject

Returns the value of attribute statement.



145
146
147
# File 'lib/plsql/jdbc_connection.rb', line 145

def statement
  @statement
end

Class Method Details

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



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/plsql/jdbc_connection.rb', line 158

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



188
189
190
191
# File 'lib/plsql/jdbc_connection.rb', line 188

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

#fetchObject



172
173
174
175
176
177
178
179
180
# File 'lib/plsql/jdbc_connection.rb', line 172

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



182
183
184
185
186
# File 'lib/plsql/jdbc_connection.rb', line 182

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