Skip to content

Commit

Permalink
added some missing methods for PGconn and PGresult
Browse files Browse the repository at this point in the history
  • Loading branch information
mneumann committed Dec 6, 2004
1 parent 1228cea commit fa126cc
Showing 1 changed file with 51 additions and 6 deletions.
57 changes: 51 additions & 6 deletions lib/postgres-pr/postgres-compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,69 @@ def query(sql)
end

alias exec query

def self.escape(str)
# TODO: correct?
str.gsub(/\\/){ '\\\\' }.gsub(/'/){ '\\\'' }
end

end

class PGresult
attr_reader :fields, :result
include Enumerable

def each(&block)
@result.each(&block)
end

def [](index)
@result[index]
end

def initialize(res)
@res = res
@fields = @res.fields.map {|f| f.name}
@result = @res.rows
end

include Enumerable
# TODO: status, getlength, cmdstatus

def each(&block)
@result.each(&block)
attr_reader :result, :fields

def num_tuples
@result.size
end

def [](index)
@result[index]
def num_fields
@fields.size
end

def fieldname(index)
@fields[index]
end

def fieldnum(name)
@fields.index(name)
end

def type(index)
raise
# TODO: correct?
@res.fields[index].type_oid
end

def size(index)
raise
# TODO: correct?
@res.fields[index].typlen
end

def getvalue(tup_num, field_num)
@result[tup_num][field_num]
end

# free the result set
def clear
@res = @fields = @result = nil
end
end

0 comments on commit fa126cc

Please sign in to comment.