Syntax error, want to use multiple variables in one line, copy mysqldata

K

K. V.

I'm completely new to Ruby and trying to do something pretty simple --
run through the lines of a database and copy them using ruby. The data's
going from mysql to flockdb. The meat of the argument looks like this:

res = mysql.query("SELECT source, target FROM old_data")
while row = res.fetch_row do
flock.add(row[0], :follows, row[1])
end

Now, I don't know what I'm doing wrong, though I'm sure it's easy, but
this never works. If I use only one of the variables (either row[0] or
row[1]) and make the other some constant (ie flock.add(1, :follows,
row[1]) it works fine. But if I use two, it never works. Even if I want
to check that they're integers,

while row = res.fetch_row do
Integer(row[0]), Integer(row[1])
end

it fails. I have checked separately and they are, so that's not the
problem. These are the error messages that come back:

NoMethodError: undefined method `<' for [0]:Array
from
/var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/protocol/binary_protocol.rb:95:in
`write_i64'
from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/client.rb:35:in
`write'
from /var/lib/gems/1.8/gems/thrift-0.2.0.4/lib/thrift/client.rb:35:in
`send_message'
from
/var/lib/gems/1.8/gems/flockdb-0.5.1/lib/flock/gen-rb/flock_d_b.rb:102:in
`send_execute'
from
/var/lib/gems/1.8/gems/flockdb-0.5.1/lib/flock/gen-rb/flock_d_b.rb:97:in
`execute'
from
/var/lib/gems/1.8/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:115:in
`send'
from
/var/lib/gems/1.8/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:115:in
`handled_proxy'
from
/var/lib/gems/1.8/gems/thrift_client-0.5.0/lib/thrift_client/abstract_thrift_client.rb:57:in
`execute'
from
/var/lib/gems/1.8/gems/flockdb-0.5.1/lib/flock/operations/execute_operations.rb:13:in
`apply'
from /var/lib/gems/1.8/gems/flockdb-0.5.1/lib/flock/client.rb:77:in
`update'
from /var/lib/gems/1.8/gems/flockdb-0.5.1/lib/flock/client.rb:82:in
`add'
from (irb):41
from /usr/lib/ruby/1.8/rubygems.rb:123

What I don't get is why it will add them separately, but won't add both
at the same time! Any help? All the tutorials seem to say this should
work just fine, that multiple variables is not a problem. :(
 
K

K. V.

Thanks for all your help! Turns out the problem was even simpler than I
thought -- one of my outputs was an array not an integer, which flockdb
can't handle, so doing

while row = res.fetch_row do
flock.add(Integer(row[0]), :follows, Integer(row[1]))
end

worked fine, though your comments explain why I couldn't check that they
were both integers at the same time! Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top