Class: ODPI::Statement

Inherits:
Object
  • Object
show all
Defined in:
lib/odpi/statement.rb

Instance Method Summary collapse

Constructor Details

#initialize(conn, stmt) ⇒ Statement

Returns a new instance of Statement.


35
36
37
38
39
40
41
42
# File 'lib/odpi/statement.rb', line 35

def initialize(conn, stmt)
  @conn = conn
  @stmt = stmt
  @column_vars = []
  @column_info = nil
  @bind_vars = {}
  @executed = false
end

Instance Method Details

#[](key) ⇒ Object


92
93
94
# File 'lib/odpi/statement.rb', line 92

def [](key)
  @bind_vars[key].get
end

#[]=(key, val) ⇒ Object


96
97
98
# File 'lib/odpi/statement.rb', line 96

def []=(key, val)
  @bind_vars[key].set(val)
end

#bind(key, value, type = nil, params = {}) ⇒ Object


80
81
82
83
84
85
86
87
88
89
90
# File 'lib/odpi/statement.rb', line 80

def bind(key, value, type = nil, params = {})
  var = make_var(value, type, params, nil)
  if key.is_a? Integer
    @stmt.bind_by_pos(key, var.raw_var)
  else
    @stmt.bind_by_name(key, var.raw_var)
  end
  var.set(value)
  @bind_vars[key] = var
  self
end

#bind_namesObject


68
69
70
# File 'lib/odpi/statement.rb', line 68

def bind_names
  @stmt.bind_names
end

#closeObject


139
140
141
# File 'lib/odpi/statement.rb', line 139

def close
  @stmt.close(nil)
end

#ddl?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/odpi/statement.rb', line 52

def ddl?
  @stmt.ddl?
end

#define(pos, type, params = {}) ⇒ Object


100
101
102
103
104
105
# File 'lib/odpi/statement.rb', line 100

def define(pos, type, params = {})
  var = make_var(nil, type, params)
  @stmt.define(pos, var) if @executed
  @column_vars[pos - 1] = var
  self
end

#dml?Boolean

Returns:

  • (Boolean)

56
57
58
# File 'lib/odpi/statement.rb', line 56

def dml?
  @stmt.dml?
end

#execute(binds = nil, defines = nil, params = nil) ⇒ Object


111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/odpi/statement.rb', line 111

def execute(binds = nil, defines = nil, params = nil)
  @stmt.execute(:default)
  if @stmt.query?
    @stmt.query_columns.each_with_index do |col, idx|
      unless @column_vars[idx]
        type = col.type_info
        @column_vars[idx] = make_var(nil, type.oracle_type, type, @stmt.fetch_array_size)
      end
    end
    unless @executed
      @column_vars.each_with_index do |var, idx|
        @stmt.define(idx + 1, var.raw_var)
      end
    end
  end
  @executed = true
  self
end

#fetchObject


130
131
132
133
134
135
136
137
# File 'lib/odpi/statement.rb', line 130

def fetch
  idx = @stmt.fetch
  if idx
    @column_vars.collect do |var|
      var[idx]
    end
  end
end

#fetch_array_sizeObject


72
73
74
# File 'lib/odpi/statement.rb', line 72

def fetch_array_size
  @stmt.fetch_array_size
end

#fetch_array_size=(size) ⇒ Object


76
77
78
# File 'lib/odpi/statement.rb', line 76

def fetch_array_size=(size)
  @stmt.fetch_array_size = size
end

#plsql?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/odpi/statement.rb', line 48

def plsql?
  @stmt.plsql?
end

#query?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/odpi/statement.rb', line 44

def query?
  @stmt.query?
end

#query_columnsObject


107
108
109
# File 'lib/odpi/statement.rb', line 107

def query_columns
  @stmt.query_columns
end

#returning?Boolean

Returns:

  • (Boolean)

64
65
66
# File 'lib/odpi/statement.rb', line 64

def returning?
  @stmt.returning?
end

#typeObject


60
61
62
# File 'lib/odpi/statement.rb', line 60

def type
  @stmt.statement_type
end