Class: DBI::DBD::ADO::Statement

Inherits:
BaseStatement show all
Includes:
SQL::BasicBind, SQL::BasicQuote
Defined in:
lib/dbd/ADO.rb

Instance Method Summary collapse

Methods included from SQL::BasicQuote

#quote

Methods included from SQL::BasicBind

#bind, #tokens

Methods inherited from BaseStatement

#[], #[]=, #bind_params, #cancel, #fetch_all, #fetch_many

Constructor Details

#initialize(handle, statement, db) ⇒ Statement

Returns a new instance of Statement.



109
110
111
112
113
114
# File 'lib/dbd/ADO.rb', line 109

def initialize(handle, statement, db)
  @handle = handle
  @statement = statement
  @params = []
  @db = db
end

Instance Method Details

#bind_param(param, value, attribs) ⇒ Object

Raises:



116
117
118
119
120
# File 'lib/dbd/ADO.rb', line 116

def bind_param(param, value, attribs)
  raise InterfaceError, "only ? parameters supported" unless param.is_a? Fixnum

  @params[param-1] = value 
end

#column_infoObject



187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/dbd/ADO.rb', line 187

def column_info
  num_cols = @res_handle.Fields().Count()
  retval = Array.new(num_cols)

  for i in 0...num_cols do
    retval[i] = {'name' => @res_handle.Fields(i).Name()}
  end

  retval
rescue RuntimeError => err
  raise DBI::DatabaseError.new(err.message)
end

#executeObject



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/dbd/ADO.rb', line 122

def execute
  # TODO: use Command and Parameter
  # TODO: substitute all ? by the parametes
  sql = bind(self, @statement, @params)
  @res_handle = @handle.Execute(sql) 

  # TODO: SELECT and AutoCommit finishes the result-set
  #       what to do?
  if @db['AutoCommit'] == true and not SQL.query?(@statement) then
    @db.commit
  end

rescue RuntimeError => err
  raise DBI::DatabaseError.new(err.message)
end

#fetchObject



148
149
150
151
152
153
154
# File 'lib/dbd/ADO.rb', line 148

def fetch        
  retval = fetch_currentrow
  @res_handle.MoveNext() unless retval.nil?
  retval
rescue RuntimeError => err
  raise DBI::DatabaseError.new(err.message)
end

#fetch_scroll(direction, offset) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/dbd/ADO.rb', line 158

def fetch_scroll(direction, offset)
  case direction
  when DBI::SQL_FETCH_NEXT
    return fetch
  when DBI::SQL_FETCH_PRIOR
    # TODO: check if already the first?
    #return nil if @res_handle.AbsolutePosition()
    @res_handle.MovePrevious()
    return fetch_currentrow
  when DBI::SQL_FETCH_FIRST
    @res_handle.MoveFirst()
    return fetch_currentrow
  when DBI::SQL_FETCH_LAST
    @res_handle.MoveLast()
    return fetch_currentrow
  when DBI::SQL_FETCH_RELATIVE
    @res_handle.Move(offset)
    return fetch_currentrow
  when DBI::SQL_FETCH_ABSOLUTE
    ap = @res_handle.AbsolutePositon()      
    @res_handle.Move(offset-ap)
    return fetch_currentrow      
  else
    raise DBI::InterfaceError
  end    
rescue RuntimeError => err
  raise DBI::DatabaseError.new(err.message)
end

#finishObject



138
139
140
141
142
143
144
145
146
# File 'lib/dbd/ADO.rb', line 138

def finish
  # if DCL, DDL or INSERT UPDATE and DELETE, this gives an Error
  # because no Result-Set is available
  if @res_handle.Fields.Count() != 0 then
    @res_handle.Close()
  end
rescue RuntimeError => err
  raise DBI::DatabaseError.new(err.message)
end

#rowsObject



200
201
202
203
# File 'lib/dbd/ADO.rb', line 200

def rows
  # TODO: how to get the RPC in ADO? 
  nil
end