Class: PLSQL::OCIConnection::Cursor

Inherits:
Object
  • Object
show all
Includes:
Connection::CursorCommon
Defined in:
lib/plsql/oci_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, raw_cursor) ⇒ Cursor

Returns a new instance of Cursor.



77
78
79
80
81
# File 'lib/plsql/oci_connection.rb', line 77

def initialize(conn, raw_cursor)
  @connection = conn
  @raw_cursor = raw_cursor
  self.class.open_cursors.push self
end

Instance Attribute Details

#raw_cursorObject (readonly)

Returns the value of attribute raw_cursor.



70
71
72
# File 'lib/plsql/oci_connection.rb', line 70

def raw_cursor
  @raw_cursor
end

Class Method Details

.new_from_parse(conn, sql) ⇒ Object



83
84
85
86
# File 'lib/plsql/oci_connection.rb', line 83

def self.new_from_parse(conn, sql)
  raw_cursor = conn.raw_connection.parse(sql)
  self.new(conn, raw_cursor)
end

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



88
89
90
91
92
93
94
95
# File 'lib/plsql/oci_connection.rb', line 88

def self.new_from_query(conn, sql, bindvars = [], options = {})
  cursor = new_from_parse(conn, sql)
  if prefetch_rows = options[:prefetch_rows]
    cursor.prefetch_rows = prefetch_rows
  end
  cursor.exec(*bindvars)
  cursor
end

.open_cursorsObject

stack of open cursors per thread



73
74
75
# File 'lib/plsql/oci_connection.rb', line 73

def self.open_cursors
  Thread.current[:plsql_oci_cursor_stack] ||= []
end

Instance Method Details

#[](key) ⇒ Object



111
112
113
# File 'lib/plsql/oci_connection.rb', line 111

def [](key)
  @connection.ora_value_to_ruby_value(@raw_cursor[key])
end

#bind_param(arg, value, metadata) ⇒ Object



101
102
103
104
105
# File 'lib/plsql/oci_connection.rb', line 101

def bind_param(arg, value, )
  type, length = @connection.plsql_to_ruby_data_type()
  ora_value = @connection.ruby_value_to_ora_value(value, type)
  @raw_cursor.bind_param(arg, ora_value, type, length)
end

#closeObject



128
129
130
131
132
133
134
# File 'lib/plsql/oci_connection.rb', line 128

def close
  # close all cursors that were created after this one
  while (open_cursor = self.class.open_cursors.pop) && !open_cursor.equal?(self)
    open_cursor.close_raw_cursor
  end
  close_raw_cursor
end

#close_raw_cursorObject



124
125
126
# File 'lib/plsql/oci_connection.rb', line 124

def close_raw_cursor
  @raw_cursor.close
end

#exec(*bindvars) ⇒ Object



107
108
109
# File 'lib/plsql/oci_connection.rb', line 107

def exec(*bindvars)
  @raw_cursor.exec(*bindvars)
end

#fetchObject



115
116
117
118
# File 'lib/plsql/oci_connection.rb', line 115

def fetch
  row = @raw_cursor.fetch
  row && row.map { |v| @connection.ora_value_to_ruby_value(v) }
end

#fieldsObject



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

def fields
  @fields ||= @raw_cursor.get_col_names.map { |c| c.downcase.to_sym }
end

#prefetch_rows=(value) ⇒ Object



97
98
99
# File 'lib/plsql/oci_connection.rb', line 97

def prefetch_rows=(value)
  @raw_cursor.prefetch_rows = value
end