# Segmentation fault in interpreter doing simple MySQL

**URL:** <https://www.ruby-forum.com/t/segmentation-fault-in-interpreter-doing-simple-mysql/191680>\
**Category:** Ruby\
**Created:** [July 16, 2010, 4:12am UTC](https://www.ruby-forum.com/t/segmentation-fault-in-interpreter-doing-simple-mysql/191680 "2010-07-16T04:12:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jonraphaelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jonraphaelson](https://www.ruby-forum.com/u/jonraphaelson)\
**Post date:** [July 16, 2010, 4:12am UTC](https://www.ruby-forum.com/t/segmentation-fault-in-interpreter-doing-simple-mysql/191680/1 "2010-07-16T04:12:30Z")

</div>

I am a relative ruby-newbie (hey that rhymes!) but I am a python expert  
so this error REALLY threw me. I am doing a VERY VERY simply SQL  
program that executes two queries in a row:

require ‘mysql’  
db = Mysql.connect(‘localhost’,‘myname’,‘mypswd’,‘information\_schema’)  
q1 = db.query (“select \* from table\_constraints”)  
q1.each { |row| puts row.inspect }  
q1.free  
q2 = db.query (“select \* from key\_column\_usage”)  
q2.each { |row| puts row.inspect }  
q2.free  
db.close

This SHOULD just print the data from the two schema tables.

When I execute this with EITHER of the sets of three lines for q1 or q2  
commented out (i.e., only one query in the program), this works fine.  
Each run gives me the correct results from the appropriate query.

When I execute this as above, I get the following:

C:\ruby\>ruby sqlcompare1.rb  
[nil, “qautil”, “PRIMARY”, “qautil”, “qausers”, “PRIMARY KEY”]  
[nil, “qautil”, “PRIMARY”, “qautil”, “siteuimap”, “PRIMARY KEY”]  
[nil, “qautil”, “map\_page\_field”, “qautil”, “siteuimap”, “UNIQUE”]  
[nil, “qautil”, “PRIMARY”, “qautil”, “testusers”, “PRIMARY KEY”]  
sqlcompare1.rb:6: [BUG] Segmentation fault  
ruby 1.9.1p429 (2010-07-02 revision 28523) [i386-mingw32]

## – control frame ---------- c:0008 p:---- s:0023 b:0023 l:000022 d:000022 CFUNC :inspect c:0007 p:---- s:0021 b:0021 l:000020 d:000020 CFUNC :inspect c:0006 p:0012 s:0018 b:0017 l:001264 d:000016 BLOCK sqlcompare1.rb:6 c:0005 p:---- s:0014 b:0014 l:000013 d:000013 FINISH c:0004 p:---- s:0012 b:0012 l:000011 d:000011 CFUNC :each c:0003 p:0065 s:0009 b:0009 l:001264 d:000b58 EVAL sqlcompare1.rb:6 c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH c:0001 p:0000 s:0002 b:0002 l:001264 d:001264 TOP

– Ruby level backtrace  
information-----------------------------------------  
sqlcompare1.rb:6:in `inspect' sqlcompare1.rb:6:in `inspect’  
sqlcompare1.rb:6:in `block in <main>' sqlcompare1.rb:6:in `each’  
sqlcompare1.rb:6:in `’

[NOTE]  
You may encounter a bug of Ruby interpreter. Bug reports are welcome.  
For details: [http://www.ruby-lang.org/bugreport.html](http://www.ruby-lang.org/bugreport.html)

This application has requested the Runtime to terminate it in an  
unusual way.  
Please contact the application’s support team for more information.

C:\ruby\>

Needless to say, this looks REALLY nasty and doesn’t instill a lot of  
confidence in me about the stability of the MySQL/Ruby code. I am  
running Ruby 1.9.1 and Mysql 2.8.1 which are the latest and greatest as  
far as I know.

Also needless to say, the following python version of the same code:

import MySQLdb  
db =  
MySQLdb.connect(‘localhost’,‘myname’,‘mypswd’,‘information\_schema’)  
q = db.cursor()  
q.execute(“select \* from table\_constraints”)  
for row in q.fetchall():  
print row  
q.execute(“select \* from key\_column\_usage”)  
for row in q.fetchall():  
print row

WORKS PERFECTLY! 🙂

Anybody got any ideas or could you point me to a place where I can  
report a nasty bug like this?

I can’t even imagine that with something this simple blowing up that  
there are thousands of Ruby/MySQL applications out there running on  
websites flawlessly. There must be REALLY something weird going on  
here.

Thanks,

Jon “bleurose” Rosen

---

<div class="post-metadata">

**Author:** ![jonraphaelson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/53a042/32.png) [@jonraphaelson](https://www.ruby-forum.com/u/jonraphaelson)\
**Post date:** [July 16, 2010, 12:18pm UTC](https://www.ruby-forum.com/t/segmentation-fault-in-interpreter-doing-simple-mysql/191680/2 "2010-07-16T12:18:53Z")

</div>

On Jul 16, 4:12 am, Jon R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am  
> running Ruby 1.9.1 and Mysql 2.8.1 which are the latest and greatest as  
> far as I know.

Just a small comment: Your script works for my local environment  
without problems:

ruby 1.8.7 (2010-01-10 patchlevel 249) [i686-darwin10]  
mysql5 Ver 14.14 Distrib 5.1.47, for apple-darwin10.3.0 (i386) using  
readline 6.1

Patrick
