Hi,
Just yesterday I successfully installed ruby in my pc, means I am
new in this technology.
Today I am trying to fetch the data in my ruby application and
successfully done this. Now I want to speed up the performance of the
fetching data by making use of prepare and execute method.In case of
select query also I am using this like

require 'mysql'
mysql = Mysql.init()
mysql.connect('localhost','root','','ruby')
selection = mysql.prepare("select * from test where id=?")
result = selection.execute(2)
while row = result.fetch_hash do
puts "The name is: #{row['name']}"
end
mysql.close();

So when I run this small part of the application I am getting the
following error:
in `<top (required)>': undefined method `fetch_hash' for
#<Mysql::Stmt:0xf9d128> (NoMethodError)
from -e:1:in `load'
from -e:1:in `<main>'

But if we write code like:
require 'mysql'
mysql = Mysql.init()
mysql.connect('localhost','root','','ruby')
result = mysql.query("select * from test where id=2")
while row = result.fetch_hash do
puts "The name is: #{row['name']}"
end
mysql.close();

then my application is running without error.

Now my question is, if we try to fetch the data by making use of prepare
and execute method then what will be the available methods for showing
the records?

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Srimanta Chakraborty at Feb 2, 2012 at 11:18 am

    Srimanta Chakraborty wrote in post #1043667:
    Hi,
    Just yesterday I successfully installed ruby in my pc, means I am
    new in this technology.
    Today I am trying to fetch the data in my ruby application and
    successfully done this. Now I want to speed up the performance of the
    fetching data by making use of prepare and execute method.In case of
    select query also I am using this like

    require 'mysql'
    mysql = Mysql.init()
    mysql.connect('localhost','root','','ruby')
    selection = mysql.prepare("select * from test where id=?")
    result = selection.execute(2)
    while row = result.fetch_hash do
    puts "The name is: #{row['name']}"
    end
    mysql.close();

    So when I run this small part of the application I am getting the
    following error:
    in `<top (required)>': undefined method `fetch_hash' for
    #<Mysql::Stmt:0xf9d128> (NoMethodError)
    from -e:1:in `load'
    from -e:1:in `<main>'

    But if we write code like:
    require 'mysql'
    mysql = Mysql.init()
    mysql.connect('localhost','root','','ruby')
    result = mysql.query("select * from test where id=2")
    while row = result.fetch_hash do
    puts "The name is: #{row['name']}"
    end
    mysql.close();

    then my application is running without error.

    Now my question is, if we try to fetch the data by making use of prepare
    and execute method then what will be the available methods for showing
    the records?



    If I use the first option and use fetch method instead of fetch_hash
    method then I am getting the records but by using only index, the array
    is fetching not by column name. So how to get that?

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Colin Law at Feb 2, 2012 at 12:14 pm

    On 2 February 2012 10:42, Srimanta Chakraborty wrote:
    Hi,
    Just yesterday I successfully installed ruby in my pc, means I am
    new in this technology.
    Today I am trying to fetch the data in my ruby application and
    successfully done this. Now I want to speed up the performance of the
    fetching data by making use of prepare and execute method.In case of
    select query also I am using this like

    require 'mysql'
    mysql = Mysql.init()
    mysql.connect('localhost','root','','ruby')
    selection = mysql.prepare("select * from test where id=?")
    result = selection.execute(2)
    while row = result.fetch_hash do
    puts "The name is: #{row['name']}"
    end
    mysql.close();

    So when I run this small part of the application I am getting the
    following error:
    in `<top (required)>': undefined method `fetch_hash' for
    #<Mysql::Stmt:0xf9d128> (NoMethodError)
    from -e:1:in `load'
    from -e:1:in `<main>'

    But if we write code like:
    require 'mysql'
    mysql = Mysql.init()
    mysql.connect('localhost','root','','ruby')
    result = mysql.query("select * from test where id=2")
    while row = result.fetch_hash do
    puts "The name is: #{row['name']}"
    end
    mysql.close();

    then my application is running without error.

    Now my question is, if we try to fetch the data by making use of prepare
    and execute method then what will be the available methods for showing
    the records?
    I don't know the answer to your question, but I see you are not using
    Rails, just Ruby. Are you intending to use Rails or is this to be a
    native Ruby application? This is principally an RoR list, someone
    here may well know the answer but there may be better places to ask
    for straight Ruby questions.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Srimanta Chakraborty at Feb 2, 2012 at 1:14 pm

    Colin Law wrote in post #1043686:
    On 2 February 2012 10:42, Srimanta Chakraborty wrote:
    mysql.connect('localhost','root','','ruby')
    #<Mysql::Stmt:0xf9d128> (NoMethodError)
    end
    mysql.close();

    then my application is running without error.

    Now my question is, if we try to fetch the data by making use of prepare
    and execute method then what will be the available methods for showing
    the records?
    I don't know the answer to your question, but I see you are not using
    Rails, just Ruby. Are you intending to use Rails or is this to be a
    native Ruby application? This is principally an RoR list, someone
    here may well know the answer but there may be better places to ask
    for straight Ruby questions.

    Colin


    Sorry for choose this forum as a "Ruby on Rails". Anyway, I am posting
    this as "Ruby" again.

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 2, '12 at 10:42a
activeFeb 2, '12 at 1:14p
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Srimanta Chakraborty: 3 posts Colin Law: 1 post

People

Translate

site design / logo © 2022 Grokbase