I have the following function in ruby for retrieving certain information from a database.
#Setup
require "mysql2"
@client = Mysql2::Client.new(:host => "127.0.0.1", :username => "root", :password => "password")
query = "use project1"
@client.query(query)
def nodeslastactive
query = "SELECT nodeid FROM nodes WHERE lastactive = #{@clock-1}"
result = @client.query(query)
if result.size == 0
return nil
else
resultarray = Array.new
result.each do |row|
resultarray.push(row["nodeid"])
end
end
end
It is utilized by this code:
lastactivenodes = nodeslastactive
if lastactivenodes != nil
lastactivenodes.each do |lastactivenode|
connect(node,lastactivenode)
end
end
The issue I am getting is that when the connection is established in the 2nd code block, the function tries to connect the node with the value {"nodeid"=>xxxxx}, even though I have copied all hash values out of the hash into an array in the 1st code block for processing by the second block. Any suggestions?
In the first method you miss the
in the else branch, or it will just return the
resulthash as it is the last thing evaluated in the method