R
Ronald Fischer
May I ask some kind soul to criticize the following piece of code?
I don't have that much experience with Ruby yet, but I feel I could
do it simpler than that.
Problem: Fetch result of a query (it happens to be a SQL query to a
database, but the essential point here is that I need to generate
the resulting lines piecewise, each iteration returning the next=20
row as an array of values). The result should be returned as a=20
matrix (i.e. array of arrays). In practice, the number of rows returned
will be well below 1000, each row containing around 10 items.
Here is my code:
def fetch_result(querystring)
result=3D[]
qres =3D dbhandle.query(qstr)
while row =3D fetch_result.fetch_row # deliver next row
result.push row # add row to the result array - is this OK?
end
result # return result array
end
I suspect there might be an overhead in appending to an array
new rows piecewise as I'm doing it here. Is there a better way
to do it?=20
Ronald
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162
I don't have that much experience with Ruby yet, but I feel I could
do it simpler than that.
Problem: Fetch result of a query (it happens to be a SQL query to a
database, but the essential point here is that I need to generate
the resulting lines piecewise, each iteration returning the next=20
row as an array of values). The result should be returned as a=20
matrix (i.e. array of arrays). In practice, the number of rows returned
will be well below 1000, each row containing around 10 items.
Here is my code:
def fetch_result(querystring)
result=3D[]
qres =3D dbhandle.query(qstr)
while row =3D fetch_result.fetch_row # deliver next row
result.push row # add row to the result array - is this OK?
end
result # return result array
end
I suspect there might be an overhead in appending to an array
new rows piecewise as I'm doing it here. Is there a better way
to do it?=20
Ronald
--=20
Ronald Fischer <[email protected]>
Phone: +49-89-452133-162