Ruby ãã MySQL ã使ãããã® pure Ruby ã©ã¤ãã©ãª Ruby/MySQL 2.9 ãå ¬éãã¾ãããã¾ã ãã¼ã¿çã§ãã http://github.com/tmtm/ruby-mysql/tree/2.9
åã® Ruby/MySQL 㯠0.2.6 ã ã£ãã®ã§ãããä»å 2.9 ã¨ããçç±ã¯:
â¦ã¨ããæå³ãããã¾ãã
gem 㯠gemcutter ã«ããã¾ããhttp://gemcutter.org/gems/ruby-mysql/versions/2.9.0
gemcutter ãè¨å®ããã¦å
¥ãã°æ¬¡ã®ã³ãã³ãã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
# gem install ruby-mysql -v 2.9
対å¿ãã Ruby ãã¼ã¸ã§ã³ã¯ 1.8.7 / 1.9.1 / 1.9.2ãMySQL ãã¼ã¸ã§ã³ã¯ 5.1.x ã§ãã
MySQL/Ruby 2.8.x ã¨ã®äºæ
以åã®ãã¼ã¸ã§ã³ã¨ç°ãªããMySQL/Ruby 2.8.x ã¨ã»ã¼äºæãããã¾ãããã ã以ä¸ã®éäºæãããã¾ãã
Ruby 1.8.x ã§ä½¿ç¨ããå ´åãMysql#escape_string ã¯ããã«ããã¤ãæåã®ä¸é¨ã¨ãã¦ç¹æ®è¨å·ãå«ããã«ããã¤ãæåã»ããã«å¯¾ãã¦å®å ¨ã§ã¯ããã¾ãããã·ããJIS(sjis, cp932)çã¯2ãã¤ãç®ã«ã\ããå«ããããã®å¶éã«ãã¦ã¯ã¾ãã¾ããããã°ã©ã å´ã§ç¬èªã«ã¨ã¹ã±ã¼ãå¦çãè¡ãããã¹ãã¢ãããã·ã¸ã£ã使ç¨ãã¦ãã ãããããã§ãªã㨠SQL ã¤ã³ã¸ã§ã¯ã·ã§ã³ã®å±éºæ§ãããã¾ããEUC-JP ã UTF-8 ã¯åé¡ããã¾ããã
ããã¤ãã®ã¡ã½ãããããã¾ãã: Mysql#debug, Mysql#change_user, Mysql#create_db, Mysql#drop_db, Mysql#dump_debug_info, Mysql#ssl_set, Mysql#reconnect
Mysql#options ã§ãµãã¼ããã¦ãããªãã·ã§ã³ã¯æ¬¡ã®ãã®ã ãã§ã: Mysql::INIT_COMMAND, Mysql::OPT_CONNECT_TIMEOUT, Mysql::OPT_LOCAL_INFILE, Mysql::OPT_READ_TIMEOUT, Mysql::OPT_WRITE_TIMEOUT, Mysql::SET_CHARSET_NAME. ããã以å¤ãæå®ãã㨠"option not implementted" ã¨ãã warning ãæ¨æºã¨ã©ã¼åºåã«åºåããã¾ãã
Mysql#use_result 㯠Mysql#store_result ã¨åãã§ããã¤ã¾ããµã¼ãã¼ããä¸æ°ã«çµæã»ãããèªã¿è¾¼ã¿ã¾ãã
MySQL/Ruby 2.8.x ããã®æ¹è¯ç¹
Ruby 1.9.x ã® M17N ã«å¯¾å¿ãã¦ãã¾ããmysqld ã¸ã®ã¯ã¨ãªæååãããªãã¢ãã¹ãã¼ãã¡ã³ãã§ä¸ããå¤ã¯ mysqld ã¨ã®æ¥ç¶ã®æåã³ã¼ãã«èªåçã«å¤æããã¾ããmysqld ããã®çµææååã¯æ¥ç¶æåã³ã¼ãã¨ãã¦åãåºããã¾ãã
Mysql::Result, Mysql::Stmt ã Enumerable ã include ãã¦ãã¾ãã
ãããã¯ãªãã® Mysql::Result#each, each_hash Mysql::Stmt#each, each_hash ã Enumerator ãè¿ãã¾ãã
Mysql#charset= ã§æ¥ç¶ charset ãæå®ã§ãã¾ãã
Mysql::Error ã ãã§ãªããã¨ã©ã¼ç¨®å¥ãã¨ã«ã¨ã©ã¼ã¯ã©ã¹ãç¨æããã¦ã¾ãããã¨ãã°ãæ§æã¨ã©ã¼ã®å ´å㯠Mysql::ParseError ãªã©ããããã®ã¨ã©ã¼ã¯ Mysql::Error ã®ç¶æ¿ã¯ã©ã¹ã§ãã
ä»ã« pure Ruby çã§ãããã¨ã®ã¡ãªããã¨ãã¦ãRuby ã®ãã«ãã¹ã¬ãããåæã«åãã¨ããã®ãããã¾ããããã¹ã¬ããã§æéã®ãããã¯ã¨ãªãå®è¡ä¸ã«ä»ã®ã¹ã¬ãããåããã¨ãã§ãã¾ãã
æ©è½çãªæ¹è¯ç¹ã§ã¯ããã¾ããããã©ã¤ã»ã³ã¹ã¯ Ruby ã©ã¤ã»ã³ã¹ã§ããCã©ã¤ãã©ãªçã® MySQL/Ruby 㯠libmysqlclient ããªã³ã¯ãããããããã使ç¨ãã Ruby ã¹ã¯ãªããã GPL ã«ãããããããå«ãªã MySQL ã®åç¨ã©ã¤ã»ã³ã¹ãè³¼å ¥ããå¿ è¦ãããã¾ãããRuby/MySQL 㯠libmysqlclient ããªã³ã¯ããªãããããã®å¶éã¯ããã¾ããã
Ruby 1.9.x M17N 対å¿
MySQL ã¯ãã¼ã¿ãã¼ã¹ããã¼ãã«ãã«ã©ã æ¯ã«ããããæåã»ãããæã£ã¦ãã¾ããã¾ãããµã¼ãã¼ã¨ã¯ã©ã¤ã¢ã³ãã®éã®æ¥ç¶ã«æåã»ãããæã£ã¦ãã¾ããæ¥ç¶ã¨ã«ã©ã ã¨ã®éã®æåã»ãã㯠MySQL ã®ãµã¼ãã¼å´ã§èªåçã«å¤æããã¾ãã
Ruby/MySQL ã§ã¯ MySQL æ¥ç¶ã®æåã»ããã Mysql#charset= ã§æå®ã§ãã¾ããã¾ãã¯ãMysql#connect åã« Mysql#options(Mysql::SET_CHARSET_NAME) ã§è¨å®ãã¾ãã
Ruby 1.9.x ã§ã¯æååã¯ããããã¨ã³ã³ã¼ãã£ã³ã°(æåã»ãã)ãæã£ã¦ãã¾ããRuby/MySQL 㧠Ruby ããã°ã©ã ãã MySQL ãµã¼ãã¼ã«æ¸¡ãæååï¼ã¯ã¨ãªæååããããªãã¢ãã¹ãã¼ãã¡ã³ãã®ãã©ã¡ã¼ã¿ï¼ã¯èªåçã«æ¥ç¶ã«å¿ããæåã»ããã«å¤æããã¾ãã
MySQL ãµã¼ãã¼ããè¿ãããæååã® Ruby ã®ã¨ã³ã³ã¼ãã£ã³ã°ã¯æ¥ç¶ã®æåã»ããã«å¯¾å¿ãããã®ã«ãªãã¾ãããã ããããªãã¢ãã¹ãã¼ãã¡ã³ãã§ã¯ãBINARYåã¨BITåã®ãã¼ã¿ã¯ ASCII-8BIT ã¨ã³ã³ã¼ãã£ã³ã°ã§è¿ãã¾ãã
ä¾:
# -*- coding:utf-8 -*- require 'mysql' my = Mysql.connect(nil, 'username', 'password') my.charset = 'cp932' # æ¥ç¶ã®æåã»ãã㯠CP932 query = 'select "ããã"' # UTF-8 ã®ã¯ã¨ãªæåå query.encoding # => #<Encoding:UTF-8> col, = my.query(query).fetch # åãåºããå¤ã¯æ¥ç¶ã¨åãã CP932 col.encoding # => #<Encoding:Windows-31J> col # => CP932 㧠"ããã"