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-29 19:13:01 +00:00
|
|
|
abstract def move_next : Bool
|
2016-01-28 23:31:35 +00:00
|
|
|
|
2016-01-30 00:57:00 +00:00
|
|
|
abstract def column_count : Int32
|
|
|
|
abstract def column_name(index : Int32) : String
|
|
|
|
|
|
|
|
# abstract def column_type(index : Int32)
|
|
|
|
|
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
|