Ruby on Windows with mysql and net

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 :slight_smile:

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

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 :slight_smile:

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

>Exit code: 0

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 :slight_smile:

You code looks good. The issue also happens on other platforms, not
just Windows :wink:

Any suggetions would be very much appreciated!

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

Regards,

···

On 23 ene, 10:31, "Simon Jones" <n...@spam-required.foo> wrote:
--
Luis Lavena

"Luis Lavena" <luislavena@gmail.com> wrote in message
news:f1f18924-dc8e-46e7-9418-202c2b9e05a0@i7g2000prf.googlegroups.com...

···

On 23 ene, 10:31, "Simon Jones" <n...@spam-required.foo> wrote:

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

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.

Luis Lavena wrote:

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

>Exit code: 0

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 :slight_smile:

You code looks good. The issue also happens on other platforms, not
just Windows :wink:

Any suggetions would be very much appreciated!

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

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'.

···

--
Posted via http://www.ruby-forum.com/\.

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,

···

On 23 ene, 14:07, "Simon Jones" <n...@spam-required.foo> wrote:

"Luis Lavena" <luislav...@gmail.com> wrote in message

news:f1f18924-dc8e-46e7-9418-202c2b9e05a0@i7g2000prf.googlegroups.com...

> On 23 ene, 10:31, "Simon Jones" <n...@spam-required.foo> wrote:

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

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!

--
Luis Lavena

Luis Lavena wrote:
> 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

>> >Exit code: 0

> 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 :slight_smile:

> You code looks good. The issue also happens on other platforms, not
> just Windows :wink:

>> Any suggetions would be very much appreciated!

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

> 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.

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 :wink:

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

Regards,

···

On 23 ene, 16:46, Kevin Williams <kev...@gmail.com> wrote:
--
Luis Lavena

"Luis Lavena" <luislavena@gmail.com> wrote in message
news:57e4b46a-11a8-4751-af43-ee185ccad588@e10g2000prf.googlegroups.com...

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 :slight_smile:

Simon.