add ResultSet#exec to ensure the query is performed. By default generates a move_next.

This commit is contained in:
Brian J. Cardiff 2016-01-30 21:03:02 -03:00
parent 683e6bdfa7
commit 1fb0b8a82b
4 changed files with 28 additions and 1 deletions

View file

@ -50,4 +50,12 @@ describe DB do
db.connection.last_statement.closed?.should be_true db.connection.last_statement.closed?.should be_true
end end
end end
it "exec should perform statement" do
with_dummy do |db|
db.exec ""
DummyDriver::DummyResultSet.last_result_set.executed?.should be_true
db.connection.last_statement.closed?.should be_true
end
end
end end

View file

@ -43,9 +43,20 @@ class DummyDriver < DB::Driver
class DummyResultSet < DB::ResultSet class DummyResultSet < DB::ResultSet
def initialize(statement, @iterator) def initialize(statement, @iterator)
super(statement) super(statement)
@executed = false
@@last_result_set = self
end
def self.last_result_set
@@last_result_set.not_nil!
end
def executed?
@executed
end end
def move_next def move_next
@executed = true
@iterator.next.tap do |n| @iterator.next.tap do |n|
return false if n.is_a?(Iterator::Stop) return false if n.is_a?(Iterator::Stop)
@values = n.each @values = n.each

View file

@ -15,6 +15,12 @@ module DB
@statement.close @statement.close
end end
# :nodoc:
# Ensures it executes the query
def exec
move_next
end
abstract def move_next : Bool abstract def move_next : Bool
# TODO def empty? : Bool, handle internally with move_next (?) # TODO def empty? : Bool, handle internally with move_next (?)

View file

@ -7,7 +7,9 @@ module DB
end end
def exec(*args) def exec(*args)
execute(*args).close query(*args) do |rs|
rs.exec
end
end end
def scalar(*args) def scalar(*args)