2016-01-28 23:31:35 +00:00
|
|
|
module DB
|
|
|
|
abstract class ResultSet
|
|
|
|
getter statement
|
|
|
|
|
|
|
|
def initialize(@statement : Statement)
|
|
|
|
end
|
|
|
|
|
2016-01-28 23:51:03 +00:00
|
|
|
def each
|
2016-01-29 19:13:01 +00:00
|
|
|
while move_next
|
2016-01-28 23:51:03 +00:00
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-01-30 00:57:00 +00:00
|
|
|
def close
|
|
|
|
@statement.close
|
|
|
|
end
|
|
|
|
|
2016-01-31 00:03:02 +00:00
|
|
|
# :nodoc:
|
|
|
|
# Ensures it executes the query
|
|
|
|
def exec
|
|
|
|
move_next
|
|
|
|
end
|
|
|
|
|
2016-01-29 19:13:01 +00:00
|
|
|
abstract def move_next : Bool
|
2016-01-28 23:31:35 +00:00
|
|
|
|
2016-01-30 22:46:43 +00:00
|
|
|
# TODO def empty? : Bool, handle internally with move_next (?)
|
|
|
|
|
2016-01-30 00:57:00 +00:00
|
|
|
abstract def column_count : Int32
|
|
|
|
abstract def column_name(index : Int32) : String
|
2016-01-30 22:46:43 +00:00
|
|
|
abstract def column_type(index : Int32)
|
2016-01-30 00:57:00 +00:00
|
|
|
|
2016-01-28 23:31:35 +00:00
|
|
|
# list datatypes that must be supported form the driver
|
2016-01-29 19:13:01 +00:00
|
|
|
# users will call read(String) or read?(String) for nillables
|
|
|
|
{% for t in DB::TYPES %}
|
|
|
|
abstract def read?(t : {{t}}.class) : {{t}}?
|
|
|
|
|
2016-01-28 23:31:35 +00:00
|
|
|
def read(t : {{t}}.class) : {{t}}
|
2016-01-29 19:13:01 +00:00
|
|
|
read?({{t}}).not_nil!
|
2016-01-28 23:31:35 +00:00
|
|
|
end
|
|
|
|
{% end %}
|
|
|
|
end
|
|
|
|
end
|