PATCH for MySQL/Ruby

e$B$J$+$@$G$9!#e(B

MySQL/Ruby 2.8pre2e$B$r$$F$$?$N$G$9$,!"$d$dLdBj$,$"$k$h$&$G$9!#e(B

= e$BJL%G%#%l%/%H%j$G%3%s%Q%$%k$G$-$J$$!#e(B
*.ce$B$r<+F0$GC5$9$N$O%=!<%9%G%#%l%/%H%j$G$9!#$3$N>l9g$O%=!<%9A4e(B
e$BBN$r%3%T!<$7$J$/$H$b!"%X%C%@$KJ,$1$k$@$1$G=<J,$@$H;W$$$^$9!#e(B

  • RUBYY_VERSION_CODEe$B$r$_$F$$$ke(B
    rb_str_set_len()e$B$r;H$&$N$Oe(BRSTRING_LEN()e$B$,$J$$$H$-$G$$$$$H;W$$e(B
    e$B$^$9!#e(B

    RUBY_VERSION_CODE < 160
    e$B$N$H$-$Ke(BTypeError()e$B$de(BRaise()e$B$r;H$C$F$$e(B
    e$B$^$9$,!"$3$N4X?t$Oe(B1.3e$B$G$O$9$G$KGQ;$5$l$F$$$^$9!#$J$N$G!"e(B1.4e$B$Ge(B
    e$B$OF0$+$J$$$O$:$G$9!#$^$?!“B>$N$H$3$m$G$OL5>r7o$Ge(Brb_raisee$B$r;H$Ce(B
    e$B$F$$$k$N$G!“e(B1.2e$B0JA0$G$b%@%a$J$O$:$G$9!#$D$^$j!”$b$&e(B1.4e$B0JA0$G$Oe(B
    e$B;H$o$l$F$$$J$$!”$H$
    $J$7$F$b$$$$$N$G$O!#e(B

Index: mysql-ruby-2.7.5/extconf.rb

— mysql-ruby-2.7.5/extconf.rb~ 2006-10-29 23:59:44.000000000 +0900
+++ mysql-ruby-2.7.5/extconf.rb 2008-06-16 12:18:51.000000000 +0900
@@ -61,11 +61,7 @@
error_syms.uniq!

-newf = File::open(‘mysql.c’, ‘w’)
-IO::foreach(‘mysql.c.in’) do |l|

  • newf.puts l
  • if l =~ //* Mysql::Error constant *// then
  • error_syms.each do |s|
  •  newf.puts "    rb_define_const(eMysql, \"#{s}\", INT2NUM(#{s}));"
    
  • end
    +File::open(‘error_const.h’, ‘w’) do |f|
  • error_syms.each do |s|
  • f.puts " rb_define_mysql_const(#{s});"
    end
    end
    Index: mysql-ruby-2.7.5/mysql.c
    ===================================================================
    — mysql-ruby-2.7.5/mysql.c.in~ 2008-03-08 01:30:47.000000000 +0900
    +++ mysql-ruby-2.7.5/mysql.c 2008-06-16 12:20:36.000000000 +0900
    @@ -4,5 +4,4 @@

#include “ruby.h”
-#include “version.h”
#ifdef HAVE_MYSQL_H
#include <mysql.h>
@@ -19,4 +18,12 @@
#define GC_STORE_RESULT_LIMIT 20

+#ifndef RSTRING_PTR
+#define RSTRING_PTR(str) RSTRING(str)->ptr
+#endif
+#ifndef RSTRING_LEN
+#define RSTRING_LEN(str) RSTRING(str)->len
+#define rb_str_set_len(str, length) (RSTRING_LEN(str) = (length))
+#endif
+
#ifndef Qtrue /* ruby 1.2.x ? */
#define Qtrue TRUE
@@ -278,6 +285,6 @@
VALUE ret;
Check_Type(str, T_STRING);

  • ret = rb_str_new(0, (RSTRING(str)->len)*2+1);
  • RSTRING(ret)->len = mysql_escape_string(RSTRING(ret)->ptr,
    RSTRING(str)->ptr, RSTRING(str)->len);
  • ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
  • rb_str_set_len(ret, mysql_escape_string(RSTRING_PTR(ret),
    RSTRING_PTR(str), RSTRING_LEN(str)));
    return ret;
    }
    @@ -412,6 +419,6 @@
    VALUE ret;
    Check_Type(str, T_STRING);
  • ret = rb_str_new(0, (RSTRING(str)->len)*2+1);
  • RSTRING(ret)->len = mysql_real_escape_string(m, RSTRING(ret)->ptr,
    RSTRING(str)->ptr, RSTRING(str)->len);
  • ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
  • rb_str_set_len(ret, mysql_real_escape_string(m, RSTRING_PTR(ret),
    RSTRING_PTR(str), RSTRING_LEN(str)));
    return ret;
    }
    @@ -723,5 +730,5 @@
    mysql_raise(m);
    #endif
  • if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0)
  • if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0)
    mysql_raise(m);
    do {
    @@ -743,5 +750,5 @@
    return obj;
    }
  • if (mysql_real_query(m, RSTRING(sql)->ptr, RSTRING(sql)->len) != 0)
  • if (mysql_real_query(m, RSTRING_PTR(sql), RSTRING_LEN(sql)) != 0)
    mysql_raise(m);
    if (GetMysqlStruct(obj)->query_with_result == Qfalse)
    @@ -895,9 +902,5 @@
    {
    if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE)
    -#if RUBY_VERSION_CODE < 160
  • TypeError(“invalid type, required true or false.”);
    -#else
    rb_raise(rb_eTypeError, “invalid type, required true or
    false.”);
    -#endif
    GetMysqlStruct(obj)->query_with_result = flag;
    return flag;
    @@ -973,9 +976,5 @@
    n = NUM2INT(nr);
    if (n >= max)
    -#if RUBY_VERSION_CODE < 160
  •    Raise(eMysql, "%d: out of range (max: %d)", n, max-1);
    

-#else
rb_raise(eMysql, “%d: out of range (max: %d)”, n, max-1);
-#endif
#if MYSQL_VERSION_ID >= 32226
return make_field_obj(mysql_fetch_field_direct(res, n));
@@ -1046,6 +1045,6 @@
else {
col = rb_tainted_str_new(fields[i].table,
strlen(fields[i].table)+strlen(fields[i].name)+1);

  •  RSTRING(col)->ptr[strlen(fields[i].table)] = '.';
    
  •  strcpy(RSTRING(col)->ptr+strlen(fields[i].table)+1, 
    

fields[i].name);

  •  RSTRING_PTR(col)[strlen(fields[i].table)] = '.';
    
  •  strcpy(RSTRING_PTR(col)+strlen(fields[i].table)+1, 
    

fields[i].name);
}
rb_hash_aset(hash, col, row[i]? rb_tainted_str_new(row[i],
lengths[i]): Qnil);
@@ -1171,6 +1170,6 @@
{
VALUE n = rb_iv_get(obj, “name”);

  • VALUE s = rb_str_new(0, RSTRING(n)->len + 16);
  • sprintf(RSTRING(s)->ptr, “#Mysql::Field:%s”, RSTRING(n)->ptr);
  • VALUE s = rb_str_new(0, RSTRING_LEN(n) + 16);
  • sprintf(RSTRING_PTR(s), “#Mysql::Field:%s”, RSTRING_PTR(n));
    return s;
    }
    @@ -1297,5 +1296,5 @@
    s->result.bind[i].buffer_type = MYSQL_TYPE_DATETIME;
    else
  •  rb_raise(rb_eTypeError, "unrecognized class: %s", 
    

RSTRING(rb_inspect(argv[i]))->ptr);

  •  rb_raise(rb_eTypeError, "unrecognized class: %s", 
    

RSTRING_PTR(rb_inspect(argv[i])));
if (mysql_stmt_bind_result(s->stmt, s->result.bind))
mysql_stmt_raise(s->stmt);
@@ -1620,5 +1619,5 @@
check_stmt_closed(obj);
Check_Type(query, T_STRING);

  • if (mysql_stmt_prepare(s->stmt, RSTRING(query)->ptr,
    RSTRING(query)->len))
  • if (mysql_stmt_prepare(s->stmt, RSTRING_PTR(query),
    RSTRING_LEN(query)))
    mysql_stmt_raise(s->stmt);

@@ -1717,5 +1716,5 @@
mysql_stmt_raise(s->stmt);
}

  • if (mysql_stmt_send_long_data(s->stmt, c, RSTRING(data)->ptr,
    RSTRING(data)->len))
  • if (mysql_stmt_send_long_data(s->stmt, c, RSTRING_PTR(data),
    RSTRING_LEN(data)))
    mysql_stmt_raise(s->stmt);
    return obj;
    @@ -2233,3 +2232,5 @@

    /* Mysql::Error constant */
    +#define rb_define_mysql_const(s) rb_define_const(eMysql, #s,
    INT2NUM(s))
    +#include “error_const.h”
    }
    Index: mysql-ruby-2.8pre2/extconf.rb
    ===================================================================
    — mysql-ruby-2.8pre2/extconf.rb~ 2007-12-18 08:46:30.000000000 +0900
    +++ mysql-ruby-2.8pre2/extconf.rb 2008-06-16 12:17:28.000000000 +0900
    @@ -61,11 +61,7 @@
    error_syms.uniq!

-newf = File::open(‘mysql.c’, ‘w’)
-IO::foreach(‘mysql.c.in’) do |l|

  • newf.puts l.gsub(/%RUBY_VERSION%/, RUBY_VERSION.gsub(/\D/, ‘’))
  • if l =~ //* Mysql::Error constant *// then
  • error_syms.each do |s|
  •  newf.puts "    rb_define_const(eMysql, \"#{s}\", INT2NUM(#{s}));"
    
  • end
    +File::open(‘error_const.h’, ‘w’) do |f|
  • error_syms.each do |s|
  • f.puts " rb_define_mysql_const(#{s});"
    end
    end
    Index: mysql-ruby-2.8pre2/mysql.c
    ===================================================================
    — mysql-ruby-2.8pre2/mysql.c.in 2008-03-08 01:16:28.000000000 +0900
    +++ mysql-ruby-2.8pre2/mysql.c 2008-06-16 12:15:14.000000000 +0900
    @@ -4,5 +4,4 @@

#include “ruby.h”
-#define RUBY_VERSION_CODE %RUBY_VERSION%
#ifdef HAVE_MYSQL_H
#include <mysql.h>
@@ -19,4 +18,12 @@
#define GC_STORE_RESULT_LIMIT 20

+#ifndef RSTRING_PTR
+#define RSTRING_PTR(str) RSTRING(str)->ptr
+#endif
+#ifndef RSTRING_LEN
+#define RSTRING_LEN(str) RSTRING(str)->len
+#define rb_str_set_len(str, length) (RSTRING_LEN(str) = (length))
+#endif
+
#ifndef Qtrue /* ruby 1.2.x ? */
#define Qtrue TRUE
@@ -283,9 +290,5 @@
ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
len = mysql_escape_string(RSTRING_PTR(ret), RSTRING_PTR(str),
RSTRING_LEN(str));
-#if RUBY_VERSION_CODE < 190

  • RSTRING(ret)->len = len;
    -#else
    rb_str_set_len(ret, len);
    -#endif
    return ret;
    }
    @@ -423,9 +426,5 @@
    ret = rb_str_new(0, (RSTRING_LEN(str))*2+1);
    len = mysql_real_escape_string(m, RSTRING_PTR(ret),
    RSTRING_PTR(str), RSTRING_LEN(str));
    -#if RUBY_VERSION_CODE < 190
  • RSTRING(ret)->len = len;
    -#else
    rb_str_set_len(ret, len);
    -#endif
    return ret;
    }
    @@ -905,9 +904,5 @@
    {
    if (TYPE(flag) != T_TRUE && TYPE(flag) != T_FALSE)
    -#if RUBY_VERSION_CODE < 160
  • TypeError(“invalid type, required true or false.”);
    -#else
    rb_raise(rb_eTypeError, “invalid type, required true or
    false.”);
    -#endif
    GetMysqlStruct(obj)->query_with_result = flag;
    return flag;
    @@ -983,9 +978,5 @@
    n = NUM2INT(nr);
    if (n >= max)
    -#if RUBY_VERSION_CODE < 160
  •    Raise(eMysql, "%d: out of range (max: %d)", n, max-1);
    

-#else
rb_raise(eMysql, “%d: out of range (max: %d)”, n, max-1);
-#endif
#if MYSQL_VERSION_ID >= 32226
return make_field_obj(mysql_fetch_field_direct(res, n));
@@ -2264,3 +2255,5 @@

 /* Mysql::Error constant */

+#define rb_define_mysql_const(s) rb_define_const(eMysql, #s,
INT2NUM(s))
+#include “error_const.h”
}

e$B$H$_$?!w$D$/$Pe(B e$B$G$9!#e(B

On Wed, 18 Jun 2008 15:15:01 +0900
Nobuyoshi N. [email protected] wrote:

RUBY_VERSION_CODE < 160 e$B$N$H$-$Ke(BTypeError()e$B$de(BRaise()e$B$r;H$C$F$$e(B
e$B$^$9$,!"$3$N4X?t$Oe(B1.3e$B$G$O$9$G$KGQ;$5$l$F$$$^$9!#$J$N$G!"e(B1.4e$B$Ge(B
e$B$OF0$+$J$$$O$:$G$9!#$^$?!“B>$N$H$3$m$G$OL5>r7o$Ge(Brb_raisee$B$r;H$Ce(B
e$B$F$$$k$N$G!“e(B1.2e$B0JA0$G$b%@%a$J$O$:$G$9!#$D$^$j!”$b$&e(B1.4e$B0JA0$G$Oe(B
e$B;H$o$l$F$$$J$$!”$H$
$J$7$F$b$$$$$N$G$O!#e(B

e$B0JA0$N%P!<%8%g%s$Ne(B Ruby
e$B$GF0$/$+$I$&$+$OA4A33NG’$7$F$J$+$C$?$N$G$9$,!“e(B
e$B$”$($F0U?^E*$KF0$+$J$/$9$k$h$&$JJQ99$O$7$J$/$F$b$$$$$+$J$!!De(B
e$B$/$i$$$N46e(B
e$B$8$G$=$N$^$^$K$7$F$^$7$?!#e(B

e$B$I$&$;F0:n$7$F$J$$$N$J$i!"e(BMySQL/Ruby 2.8 e$B$K$D$$$F$O!“e(B1.8.x
e$B0J>e$G$7$+F0e(B
e$B$+$J$$$H$$$&A0Ds$K$7$F!”%=!<%9$r@0M}$7$F$b$$$$$G$9$M!#e(B

e$B%Q%C%A$NCf$G!"e(BRSTRING(str)->ptr, RSTRING(str)->len e$B$re(B
RSTRING_PTR(str), RSTRING_LEN(str) e$B$KJQ$($F$$$k$N$O!"e(BRuby 1.9
e$B$@$H%^%:e(B
e$B$$$C$F$3$H$G$9$+$M!#$J$s$+%^%:$=$&$G$9$M!D!#e(B

e$B$[$$3$N$^$^%Q%C%A$r<h$j9~$^$;$F$$$?$@$/$H;W$$$^$9!#$"$j$,$H$&$4$6$$$^$9!#e(B

e$B$H$_$?$G$9!#e(B

On Fri, 20 Jun 2008 14:04:26 +0900
e$B$H$_$?$^$5$R$me(B [email protected] wrote:

e$B%Q%C%A$NCf$G!"e(BRSTRING(str)->ptr, RSTRING(str)->len e$B$re(B
RSTRING_PTR(str), RSTRING_LEN(str) e$B$KJQ$($F$$$k$N$O!"e(BRuby 1.9 e$B$@$H%^%:e(B
e$B$$$C$F$3$H$G$9$+$M!#$J$s$+%^%:$=$&$G$9$M!D!#e(B

e$B$“$l!)e(B MySQL/Ruby 2.8 e$B$G$O!”$A$c$s$He(B RSTRING_PTR,
RSTRING_LEN e$B$K$J$C$F$^$9$M!D!#e(B
[ruby-dev:35152] e$B$N%Q%C%A$Oe(B MySQL/Ruby 2.7.5
e$B$KBP$9$k$b$N$_$?$$$G$9!#e(B

e$B$^$“!”$=$l$O$=$l$H$7$F!"<h$j9~$a$k$H$3$m$O<h$j9~$_$?$$$H;W$$$^$9!#e(B

e$B$J$+$@$G$9!#e(B

At Fri, 20 Jun 2008 14:36:52 +0900,
e$B$H$_$?$^$5$R$me(B wrote in [ruby-dev:35186]:

e$B$"$l!)e(B MySQL/Ruby 2.8 e$B$G$O!"$A$c$s$He(B RSTRING_PTR, RSTRING_LEN e$B$K$J$C$F$^$9$M!D!#e(B
[ruby-dev:35152] e$B$N%Q%C%A$Oe(B MySQL/Ruby 2.7.5 e$B$KBP$9$k$b$N$_$?$$$G$9!#e(B

2.8e$B$N$D$b$j$G$7$?$,!“e(B2.7.5e$B$N$b0l=o$KAw$C$F$7$^$$$^$7$?!#e(B2.8e$BMQ$Ne(B
e$B%Q%C%A$Oe(B2.7.5e$BMQ$N%Q%C%A$N8e$K$”$j$^$9!#e(B

e$B$H$_$?$G$9!#e(B

On Fri, 20 Jun 2008 15:19:53 +0900
Nobuyoshi N. [email protected] wrote:

2.8e$B$N$D$b$j$G$7$?$,!“e(B2.7.5e$B$N$b0l=o$KAw$C$F$7$^$$$^$7$?!#e(B2.8e$BMQ$Ne(B
e$B%Q%C%A$Oe(B2.7.5e$BMQ$N%Q%C%A$N8e$K$”$j$^$9!#e(B

e$B$“!”$"$j$^$7$?!#$9$$$^$;$s!#e(B

e$B%Q%C%A$=$N$^$^$@$He(B rb_str_set_len() e$B$,$J$$4X78$G!"e(B1.8.6
e$B$GF0$+$J$+$C$?e(B
e$B$N$G!"D4@0$7$F<h$j9~$_$^$7$?!#e(B