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.



139
140
141
142
143
144
145
146
147
148
# File 'lib/plsql/jdbc_connection.rb', line 139

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

Instance Attribute Details

#result_setObject (readonly)

Returns the value of attribute result_set.



136
137
138
# File 'lib/plsql/jdbc_connection.rb', line 136

def result_set
  @result_set
end

#statementObject

Returns the value of attribute statement.



137
138
139
# File 'lib/plsql/jdbc_connection.rb', line 137

def statement
  @statement
end

Class Method Details

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



150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/plsql/jdbc_connection.rb', line 150

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



180
181
182
183
# File 'lib/plsql/jdbc_connection.rb', line 180

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

#fetchObject



164
165
166
167
168
169
170
171
172
# File 'lib/plsql/jdbc_connection.rb', line 164

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



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

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