A Place for my head

On Ruby, Rails, Concurrency and fiction

Posted in : Uncategorized, ruby | 7 comments

Update: Mysql official bindings has been ported to 1.9, look into comments for details
For those who want to stay on the edge, here is modified set of mysql C bindings for Ruby 1.9. Works perfectly well in my small tests.

To compile it:

$ ruby2 extconf.rb
$ make
$ sudo make install

Mysql C bindings for Ruby 1.9

7 Responses to 'Mysql C bindings for Ruby 1.9'

Subscribe to comments with RSS or TrackBack to 'Mysql C bindings for Ruby 1.9'.

  1. Hemant, I get these errors when I try to compile against the 1.9.0 code I just installed:

    gcc -I. -I/usr/local/include/ruby-1.9.0/i686-darwin9.1.0 -I/usr/local/include/ruby-1.9.0 -I. -DHAVE_MYSQL_SSL_SET -DHAVE_MYSQL_H -I/usr/local/mysql/include -Os -arch i386 -fno-common -fno-common -g -O2 -pipe -fno-common -o mysql.o -c mysql.c
    mysql.c:6:21: error: version.h: No such file or directory
    mysql.c: In function ‘escape_string’:
    mysql.c:280: error: ‘struct RString’ has no member named ‘len’
    mysql.c:281: error: ‘struct RString’ has no member named ‘len’
    mysql.c:281: error: ‘struct RString’ has no member named ‘ptr’
    mysql.c:281: error: ‘struct RString’ has no member named ‘ptr’
    mysql.c:281: error: ‘struct RString’ has no member named ‘len’
    mysql.c: In function ‘real_escape_string’:

    Any ideas?

    Mike Perham

    1 Feb 08 at 4:31 pm

  2. The latest code from here compiles for me.

    http://tmtm.org/downloads/mysql/ruby/

    Mike Perham

    1 Feb 08 at 4:35 pm

  3. Awesome, so they fixed mysql binding code to support 1.9.

    Hemant

    2 Feb 08 at 1:08 am

  4. What helps me was editing “/usr/include/ruby-1.9.0/ruby/ruby.h” (in your case the file is in “/usr/local/include/ruby-1.9.0″ dir) file and replacing the RString struct with this code:

    struct RString {
    struct RBasic basic;
    union {
    union {
    struct {
    long len;
    char *ptr;
    union {
    long capa;
    VALUE shared;
    } aux;
    } heap;
    char ary[RSTRING_EMBED_LEN_MAX];
    } as;

    struct {
    long len;
    char *ptr;
    union {
    long capa;
    VALUE shared;
    } aux;
    };
    };
    };

    I’ve created empty file “version.h” in the “/usr/include/ruby-1.9.0″ dir.

    Then I’ve just run “sudo gem1.9 install dbd-mysql” and everything compiled smooth.

    Cheers,
    Dawid

    Dawid Marcin Grzesiak

    25 Aug 08 at 10:52 am

  5. you can download the official mysql-ruby-1.8.0 that supports ruby 1.9.0.5

    http://rubyforge.org/frs/?group_id=4550

    Fred

    29 Nov 08 at 4:50 pm

  6. Under 1.9.1 preview 2, I encountered an error with both RString (as above) and RArray. Following instructions regarding RArray here http://www.rubyinside.com/ruby-1-9-1-preview-released-why-its-a-big-deal-1280.html , I modified mysql.c starting on line 1375 as follows:

    t.second = FIX2INT(RARRAY_PTR(a)[0]);
    t.minute = FIX2INT(RARRAY_PTR(a)[1]);
    t.hour = FIX2INT(RARRAY_PTR(a)[2]);
    t.day = FIX2INT(RARRAY_PTR(a)[3]);
    t.month = FIX2INT(RARRAY_PTR(a)[4]);
    t.year = FIX2INT(RARRAY_PTR(a)[5]);

    It then compiled and installed correctly.

    Barry Ezell

    8 Dec 08 at 12:04 pm

  7. Downloaded the gzip of 2.8.1 from the site fred linked, worked for the 1.9.1 release, Ubuntu jaunty.

    Aaron

    6 Aug 09 at 9:33 pm

Leave a Reply