I have coded a Ruby IRC bot which is on github (/ninjex/rubot) which is having some conflicting output with MySQL on a dedicated server I just purchased.
Firstly we have the connection to the database in the MySQL folder (in .gitignore) which looks similar to the following code block.
@con = Mysql.new('localhost', 'root', 'pword', 'db_name')
Then we have an actual function to query the database
def db_query
que = get_message # Grabs query from user i.e,./db_query SELECT * FROM words
results = @con.query(que) # Send query through the connection i.e, @con.query("SELECT * FROM WORDS")
results.each {|x| chan_send(x)} # For each row returned, send it to the channel via
end
On my local machine, when running the command:
./db_query SELECT amount, user from words WHERE user = 'Bob' and word = 'hello'
I receive the output in IRC in an Array like fashion: ["17", "Bob"]
Where 17 is amount and Bob is the user.
However, using this same function on my dedicated server results in an output like: 17Bob
I have attempted many changes in the code, as well as try to parse the data into it's own variable, however it seems that 17Bob
is coming out as a single variable, making it impossible to parse into something like an array, which I could then use to send the data correctly.
This seems odd to me on both my local machine and the dedicated server, as I was expecting the output to first send 17 to the IRC and then Bob like:
17
Bob
For all the functions and source you can check my github /Ninjex/rubot, however you may need to install some gems.
A few notes:
get_message
. Or you are opening yourself up to some serious security problems.Here's how I would approach debugging the issue on the dedicated machine:
gem install pry
.pry
: see abovebinding.pry
line is hit and you can interrogate almost everything in your running application.results
and see if it's an array. Just typeresults
in the console and it will print out the value. Also type outresults.class
. It's possible that query is returning some special result set object that is not an array, but that has a method to access the result array.results
is an array, then the issue is most likely inchan_send
. Perhaps it needs to be using something likeputs
vsprint
to ensure there's a new line after each message. Is it possible that you have different versions of your codebase deployed? I would also add asleep 1
within the each block to ensure that this is not related to your handling of messages arriving at the same time.