skip to main
|
skip to sidebar
iCesaralonso's Ruby
Friday, September 5, 2008
Postgres' NULL and Ruby's nil
There is a problem when you work with nil, because it can't be converted to NULL in Postgres
But I found a way to do it! instead of
nil
I use
"NULL"
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
Home
Subscribe to:
Posts (Atom)
Blog Archive
▼
2008
(2)
▼
September
(2)
Postgres' NULL and Ruby's nil
Converting from PGResult to Hash Array
About Me
iCesaralonso
View my complete profile