Ruby on Windows with mysql and net

S

Simon Jones

Hello all,

I'm a new Ruby user, so pardon me if this is a silly question, but I've done
some googling and not found any answers so far. Apologies in advance if this
post is a little long, but I thought it might help to list what I've done so
far.

I've downloaded Ruby 1.8.6 One-Click Installer, and got Ruby up and running
on my Win XP box. Then I used RubyGems to obtain v 2.7.3 of the MySQL API.

The idea is to connect to MySQL running on Ubuntu Server on another box on
my LAN - that part of the equation seems to work ok, in that I can connect
to MySQL from the Windows box using MySQL Administrator etc. The data to be
retrieved is login details (server, username, password) for several POP3
mail boxes - I eventually want Ruby to get details for each box from the
database, connect to the mailbox, download mail and process it etc..

However, when I tried to query the database via Ruby I got a Segmentation
Fault. After much googling I found I needed libmySQL.dll in my path, and
tried various versions of the file (including the one that came with MySQL
Administrator, and the one in MySQL 5.1.22), before getting things to work
with the version from MySQL 5.0.45.

Great, Ruby can now retrieve a result set from the database containing login
details for the two POP3 boxes currently stored there. Also, by using the
demo code in the docs for net/pop and hard coding the login details for any
given mailbox, I can connect to the mail server.

But, when I merge the code together, things go slightly wrong. Ruby
retrieves the details from the database and connects to the mail servers
correctly, but, when the program ends, I get:

Error in my_thread_global_end(): 1 threads didn't exit
Exit code: 0

The code I'm using is below. It's messy and long winded, but it IS my first
attempt ever at writing Ruby code - I like what I see so far, and I WILL get
better at it :)

To keep things shorter than they woud otherwise be, I've removed the code
between pop.start and pop.finish, since the error happens whether it's
present or not.

Any suggetions would be very much appreciated!

TIA

Simon.

#!/usr/bin/ruby -w

require 'net/pop'

require "mysql"

begin
# connect to the MySQL server
dbh = Mysql.real_connect("xxx.xxx.xxx.xxx", "username", "password",
"database")
# get get email account details
res = dbh.query("SELECT name, server, user_name, password FROM
pop_boxes")
if res.nil? then
puts "Statement has no result set"
else
puts "Statement has a result set"
while row = res.fetch_hash do
printf "%s\n", row["name"]
pop = Net::pOP3.new(row["server"])
pop.start(row["user_name"], row["password"])

pop.finish
printf "%s, %s,%s, %s\n", row["name"], row["server"],
row["user_name"], row["password"]
end
end
puts "Number of rows returned: #{res.num_rows}"
res.free
rescue Mysql::Error => e
puts "Error code: #{e.errno}"
puts "Error message: #{e.error}"
puts "Error SQLSTATE: #{e.sqlstate}" if e.respond_to?("sqlstate")
ensure
# disconnect from server
dbh.close if dbh
end
 
L

Luis Lavena

Hello all,

I'm a new Ruby user, so pardon me if this is a silly question, but I've done
some googling and not found any answers so far. Apologies in advance if this
post is a little long, but I thought it might help to list what I've done so
far.

No problem, I'm used to write long posts :)
I've downloaded Ruby 1.8.6 One-Click Installer, and got Ruby up and running
on my Win XP box. Then I used RubyGems to obtain v 2.7.3 of the MySQL API.

The idea is to connect to MySQL running on Ubuntu Server on another box on
my LAN - that part of the equation seems to work ok, in that I can connect
to MySQL from the Windows box using MySQL Administrator etc. The data to be
retrieved is login details (server, username, password) for several POP3
mail boxes - I eventually want Ruby to get details for each box from the
database, connect to the mailbox, download mail and process it etc..

However, when I tried to query the database via Ruby I got a Segmentation
Fault. After much googling I found I needed libmySQL.dll in my path, and
tried various versions of the file (including the one that came with MySQL
Administrator, and the one in MySQL 5.1.22), before getting things to work
with the version from MySQL 5.0.45.

The pre-build gem of mysql 2.7.3 is build for 5.0.x version of MySQL,
anything above that will generate a segfault due changes in the API/
exported symbols of libmySQL.dll
Great, Ruby can now retrieve a result set from the database containing login
details for the two POP3 boxes currently stored there. Also, by using the
demo code in the docs for net/pop and hard coding the login details for any
given mailbox, I can connect to the mail server.

But, when I merge the code together, things go slightly wrong. Ruby
retrieves the details from the database and connects to the mail servers
correctly, but, when the program ends, I get:

Error in my_thread_global_end(): 1 threads didn't exit

That is correct, nothing wrong with your code.

Is a known problem of MySQL 5.0.x, and still wasn't solved in latest
version of it:

http://bugs.mysql.com/bug.php?id=25621

The problem is the lack of a newer version of the installers (official
ones) for 5.0.x and the issue I mention above about pre-build gem.
The code I'm using is below. It's messy and long winded, but it IS my first
attempt ever at writing Ruby code - I like what I see so far, and I WILL get
better at it :)

You code looks good. The issue also happens on other platforms, not
just Windows ;-)
Any suggetions would be very much appreciated!

Just ignore the error for the time being? :)
I'm doing that on a daily basis, so maybe you can too ;-)

Regards,
 
S

Simon Jones

Luis Lavena said:
Just ignore the error for the time being? :)
I'm doing that on a daily basis, so maybe you can too ;-)

Thanks for that, Luis! I'm happy to ignore it now that I know there's
nothing I can do about it:)

Have you noticed any unfortunate side effects from the issue? Any memory
leaks or anything, either with the client code or at the MySQL end? Just
curious to know if ignoring is going to catch up with me eventually!

Simon.
 
K

Kevin Williams

Luis said:
The pre-build gem of mysql 2.7.3 is build for 5.0.x version of MySQL,
anything above that will generate a segfault due changes in the API/
exported symbols of libmySQL.dll


That is correct, nothing wrong with your code.

Is a known problem of MySQL 5.0.x, and still wasn't solved in latest
version of it:

http://bugs.mysql.com/bug.php?id=25621

The problem is the lack of a newer version of the installers (official
ones) for 5.0.x and the issue I mention above about pre-build gem.


You code looks good. The issue also happens on other platforms, not
just Windows ;-)


Just ignore the error for the time being? :)
I'm doing that on a daily basis, so maybe you can too ;-)

Regards,


Is there anything I can do with the pre-built gem that would help? I
stopped using MySQL personally over a year ago, but I have heard very
few complaints about the pre-built gem since then. If I need to make a
fresh build in one form or another, I can try.

Since I don't use MySQL anymore, anyone who wishes to take over the gem
project could do so. Ping me off-list, my gmail account is 'kevwil'.
 
L

Luis Lavena

Thanks for that, Luis! I'm happy to ignore it now that I know there's
nothing I can do about it:)

Have you noticed any unfortunate side effects from the issue? Any memory
leaks or anything, either with the client code or at the MySQL end? Just
curious to know if ignoring is going to catch up with me eventually!

In case you're using mongrel_service (for serving Rails applications)
you will find that sometimes the service fails at stopping process,
mostly due this.

libmysql.dll takes 2 or 3 seconds to release the locking on some
threads until it kill them. That isn't good, but so far, no data
corruption or any other issue server or client side besides the one I
mention from mongrel_service.

Regards,
 
L

Luis Lavena

Is there anything I can do with the pre-built gem that would help? I
stopped using MySQL personally over a year ago, but I have heard very
few complaints about the pre-built gem since then. If I need to make a
fresh build in one form or another, I can try.

Thank you Kevin for answering.

I've tried rebuild the gem with MySQL 5.1.x, but then it stops working
with MySQL 5.0.x, doing segfaults (the inverse scenario previously
described).
Since I don't use MySQL anymore, anyone who wishes to take over the gem
project could do so. Ping me off-list, my gmail account is 'kevwil'.

The thing is 5.1.x is "Release Candidate", and maintain compatibility
with boths gems seems overkill, mostly that you aren't around
anymore ;-)

I'll try to catch you later this weekend and maybe we can both come to
a good solution for it.

Regards,
 
S

Simon Jones

libmysql.dll takes 2 or 3 seconds to release the locking on some
threads until it kill them. That isn't good, but so far, no data
corruption or any other issue server or client side besides the one I
mention from mongrel_service.

Thanks again, Luis. I'm not using Rails, so ignoring the problem sounds good
to me :)

Simon.
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top