Class: JDBC::PreparedStatement

Inherits:
Object
  • Object
show all
Defined in:
lib/jdbc/prepared_statement.rb

Instance Method Summary collapse

Constructor Details

#initialize(stmt) ⇒ PreparedStatement

Returns a new instance of PreparedStatement.



3
4
5
6
# File 'lib/jdbc/prepared_statement.rb', line 3

def initialize(stmt)
  @stmt = stmt
  @meta_data = stmt.
end

Instance Method Details

#closeObject



27
28
29
# File 'lib/jdbc/prepared_statement.rb', line 27

def close
  @stmt.close
end

#execute(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jdbc/prepared_statement.rb', line 8

def execute(*args)
  if args.length != @meta_data.getParameterCount
    raise RuntimeError.new("Got #{args.length} params, " + 
                  "expected #{@meta_data.getParameterCount}.")
  end
  
  @stmt.clearParameters
  
  args.each_with_index do |arg, i|
    @stmt.setObject(i+1, arg, @meta_data.getParameterType(i+1))
  end
  
  if @stmt.execute
    return Result.new(@stmt.getResultSet, @stmt)
  end
  
  return @stmt.getUpdateCount
end