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