require 'mysql2' module Mysql class TableMeta MANDATORY_OPTS = [ :mysql_url, :database, :tables ] OPTIONAL_OPTS = [ ] GET_TABLE_META_SQL = < ruby # # mysql # http://dev.mysql.com/doc/refman/5.6/en/charset-charsets.html # mysql(supported CJK character sets) # http://dev.mysql.com/doc/refman/5.6/en/faqs-cjk.html#qandaitem-A-11-1-1 # For ruby, you can see encoding list with "Encoding.list" CHARSET_ENCODE_RULE = { 'ascii' => nil, # 'ASCII-8BIT', (not need to be encoded) 'utf8' => nil, # 'UTF-8', (not need to be encoded) 'utf8mb4' => nil, # 'UTF-8', (not need to be encoded) 'utf16' => 'UTF-16', 'utf32' => 'UTF-32', 'latin1' => 'ISO-8859-1', 'latin2' => 'ISO-8859-2', 'big5' => 'Big5', 'cp932' => 'CP932', 'eucjpms' => 'eucJP-ms', 'euckr' => 'EUC-KR', 'gb18030' => 'GB18030', 'gb2312' => 'GB2312', 'gbk' => 'GBK', 'sjis' => 'Shift_JIS', 'ujis' => 'EUC-JP', } def get_ruby_charset_name(mysql_charset) return nil if mysql_charset.to_s.empty? raise "Unsupported charset:#{mysql_charset}." unless CHARSET_ENCODE_RULE.has_key?(mysql_charset) charset = CHARSET_ENCODE_RULE[mysql_charset] return charset end # Return table meta # :character_set_name def [](table_name) @table_meta[table_name.to_sym] end end end