mirror of
https://gitea.invidious.io/iv-org/shard-crystal-db.git
synced 2024-08-15 00:53:32 +00:00
add ResultSet#exec
to ensure the query is performed. By default generates a move_next
.
This commit is contained in:
parent
683e6bdfa7
commit
1fb0b8a82b
4 changed files with 28 additions and 1 deletions
|
@ -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
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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 (?)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in a new issue