Friday, September 5, 2008

Converting from PGResult to Hash Array

It receives a pgresult table as a result from a SQL query and returns a "table" which really is a Hash-Array.

The new table has the same format than the PGResult table. Something like: "table [0]["fieldname"]"

def fxPGResultToHash (pgresult)

tabla = Array.new(pgresult.num_tuples()) {Hash.new}
tuplas = 0
column = 0
while tuplas < style="font-weight: bold;">
column = 0

while column < style="font-weight: bold;">
tabla[tuplas]["#{pgresult.fieldname(column)}"] = pgresult.result[tuplas][column]

column += 1
end
tuplas += 1
end

No comments: