Class: Mysql2::Statement

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

Instance Method Summary collapse

Constructor Details

#initialize(stmt, **opts) ⇒ Statement

Returns a new instance of Statement.

Parameters:

  • stmt (Mysql::Stmt)


4
5
6
7
# File 'lib/mysql2/statement.rb', line 4

def initialize(stmt, **opts)
  @stmt = stmt
  @opts = opts
end

Instance Method Details

#affected_rowsObject



29
30
31
# File 'lib/mysql2/statement.rb', line 29

def affected_rows
  @stmt.affected_rows
end

#closeObject



37
38
39
# File 'lib/mysql2/statement.rb', line 37

def close
  @stmt.close
end

#execute(*args, **opts) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/mysql2/statement.rb', line 21

def execute(*args, **opts)
  res = @stmt.execute(*args, **opts)
  opts = @opts.merge(opts)
  StatementResult.new(res, **opts)
rescue Mysql::Error => e
  raise Mysql2::Error, e.message
end

#field_countObject



13
14
15
# File 'lib/mysql2/statement.rb', line 13

def field_count
  @stmt.field_count
end

#fieldsObject



17
18
19
# File 'lib/mysql2/statement.rb', line 17

def fields
  field_count == 0 ? nil : @stmt.fields.map(&:name)
end

#last_idObject



33
34
35
# File 'lib/mysql2/statement.rb', line 33

def last_id
  @stmt.insert_id
end

#param_countObject



9
10
11
# File 'lib/mysql2/statement.rb', line 9

def param_count
  @stmt.param_count
end