Class: Ladybug::PreparedStatement

Inherits:
Object
  • Object
show all
Extended by:
Loggability
Defined in:
lib/ladybug/prepared_statement.rb

Overview

A parameterized query which can avoid planning the same query for repeated execution

Instance Method Summary collapse

Instance Method Details

#bind(**variable_map) ⇒ Object

Bind the variables in the specified variable_map to the statement.



38
39
40
41
42
# File 'lib/ladybug/prepared_statement.rb', line 38

def	bind( **variable_map )
	variable_map.each do |name, value|
		self.bind_variable( name, value )
	end
end

#execute(**bound_variables, &block) ⇒ Object

Execute the statement against its connection and return a Ladybug::Result. If a block is supplied, the result will be passed to it instead, then finished automatically, and the return value of the block returned instead.



20
21
22
23
24
25
26
# File 'lib/ladybug/prepared_statement.rb', line 20

def execute( **bound_variables, &block )
	self.log.debug "Executing statement:\n%s\nwith variables:\n%p" %
		[ self.query, bound_variables ]
	self.bind( **bound_variables )
	result = self._execute
	return Ladybug::Result.wrap_block_result( result, &block )
end

#execute!(**bound_variables) ⇒ Object

Execute the statement against its connection and return true if it succeeded.



31
32
33
34
# File 'lib/ladybug/prepared_statement.rb', line 31

def execute!( **bound_variables )
	self.bind( **bound_variables )
	return self._execute!
end