M
M
mclander2012-04-30 19:02:22
ruby
mclander, 2012-04-30 19:02:22

Loop and value by reference?

I guess that it’s impossible to do this, but I don’t understand how it’s possible - the task is to read several records from the database and give them to the presto renderer. Correct me please.
I do not want to use object access yet - the task is too simple. Forgive me if this is a dumb question - I just started learning ruby.

@entries =[]
    $dbh.select_all('select * from test order by test_id desc')  do |row| 			
      p row 
      @entries.push(row)
    end
    p @entries
    p $dbh.select_all('select * from test order by test_id desc') 
    view.render

Here is what (p) outputs for debugging (when the loop variable is displayed, everything is OK, the replacement by reference is obviously longer):
[3, "\u0420\u0430\u043C\u0443"]
[2, "\u041C\u044B\u043B\u0430"]
[1, "\u041C\u0430\u043C\u0430"]




PS. Taki went to dig active_record... Everything seems to be fine, but... Good people, who knows how to slip a table name without s at the end? For two years I weaned myself from naming tables in the plural, weaned ... and now what to do? ;)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
int03e, 2012-04-30
@mclander

stackoverflow.com/questions/8972379/ruby-dbi-select-all-vs-execute-fetch-each-finish deals with a similar issue here. But I advise you to spit on DBI and connect ORM (if AR is an overhead, then Sequel). It's worth it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question