class DB::Postgres::Native::Result

Public Class Methods

new(connection, types = {}, address) click to toggle source
Calls superclass method
# File lib/db/postgres/native/result.rb, line 57
def initialize(connection, types = {}, address)
        super(address)
        
        @connection = connection
        @fields = nil
        @types = types
        @casts = nil
end

Public Instance Methods

cast!(row) click to toggle source
# File lib/db/postgres/native/result.rb, line 82
def cast!(row)
        @casts ||= self.field_types
        
        row.size.times do |index|
                if cast = @casts[index]
                        row[index] = cast.parse(row[index])
                end
        end
        
        return row
end
each() { |cast!(get_row(i))| ... } click to toggle source
# File lib/db/postgres/native/result.rb, line 94
def each
        row_count.times do |i|
                yield cast!(get_row(i))
        end
        
        Native.clear(self)
end
field_count() click to toggle source
# File lib/db/postgres/native/result.rb, line 66
def field_count
        Native.field_count(self)
end
field_names() click to toggle source
# File lib/db/postgres/native/result.rb, line 74
def field_names
        field_count.times.collect{|i| Native.field_name(self, i)}
end
field_types() click to toggle source
# File lib/db/postgres/native/result.rb, line 70
def field_types
        field_count.times.collect{|i| @types[Native.field_type(self, i)]}
end
map() { |row| ... } click to toggle source
# File lib/db/postgres/native/result.rb, line 102
def map(&block)
        results = []
        
        self.each do |row|
                results << yield(row)
        end
        
        return results
end
row_count() click to toggle source
# File lib/db/postgres/native/result.rb, line 78
def row_count
        Native.row_count(self)
end
to_a() click to toggle source
# File lib/db/postgres/native/result.rb, line 112
def to_a
        rows = []
        
        self.each do |row|
                rows << row
        end
        
        return rows
end

Protected Instance Methods

get_row(row) click to toggle source
# File lib/db/postgres/native/result.rb, line 130
def get_row(row)
        field_count.times.collect{|j| get_value(row, j)}
end
get_value(row, field) click to toggle source
# File lib/db/postgres/native/result.rb, line 124
def get_value(row, field)
        if Native.get_is_null(self, row, field) == 0
                Native.get_value(self, row, field)
        end
end